Handle BizTalk artifact collection via ExplorerOM
Build und Test / build (push) Has been cancelled

This commit is contained in:
2026-07-28 11:35:10 +02:00
parent d1e10920c9
commit b9d01339b0
9 changed files with 601 additions and 117 deletions
@@ -1,4 +1,5 @@
using System;
using System.Collections;
using System.IO;
using System.IO.Compression;
using System.Linq;
@@ -24,6 +25,7 @@ namespace BizTalkSapEnvironmentInventory.Infrastructure
{
TestSanitizer();
TestBindingParser();
TestExplorerArtifactReader();
TestLoggerDiagnostics();
TestDocxPackage();
}
@@ -238,6 +240,53 @@ namespace BizTalkSapEnvironmentInventory.Infrastructure
}
}
private static void TestExplorerArtifactReader()
{
var directory = CreateTemporaryDirectory();
var logPath = Path.Combine(directory, "explorer-artifacts.log");
try
{
var document = new InventoryDocument();
var application = new ApplicationRecord
{
Name = "ExplorerOM-Test",
Status = "Gestartet"
};
using (var logger = new ConsoleFileLogger(logPath))
{
var collector = BizTalkWmiCollector.CreateForExplorerArtifactTest(
document,
logger,
5000);
collector.CollectExplorerArtifactsForTest(
new FakeApplication(new FakeAssembly(
"Test.Assembly, Version=1.0.0.0",
new FakeArtifact("Test.Schema"),
new FakeArtifact("Test.Map"),
new FakeArtifact("Test.Pipeline"))),
application);
}
Assert(application.Count("Assembly") == 1,
"ExplorerOM-Assembly wurde nicht gelesen.");
Assert(application.Count("Schema") == 1,
"ExplorerOM-Schema wurde nicht gelesen.");
Assert(application.Count("Map") == 1,
"ExplorerOM-Map wurde nicht gelesen.");
Assert(application.Count("Pipeline") == 1,
"ExplorerOM-Pipeline wurde nicht gelesen.");
Assert(
application.Artifacts.All(item =>
item.Properties.Any(property =>
property.Value == "BizTalk Explorer Object Model")),
"ExplorerOM-Quelle fehlt an einem Artefakt.");
}
finally
{
DeleteDirectory(directory);
}
}
private static void TestLoggerDiagnostics()
{
var directory = CreateTemporaryDirectory();
@@ -254,7 +303,7 @@ namespace BizTalkSapEnvironmentInventory.Infrastructure
// Die absichtlich erzeugte Testausnahme soll den Self-Test
// auf der Konsole nicht wie einen echten Laufzeitfehler aussehen lassen.
Console.SetOut(TextWriter.Null);
logger.Exception("Self-Test-Diagnose", exception);
logger.WarningException("Self-Test-Diagnose", exception);
}
finally
{
@@ -272,6 +321,10 @@ namespace BizTalkSapEnvironmentInventory.Infrastructure
Assert(
log.Contains("HRESULT=0x"),
"Logger dokumentierte den HRESULT nicht.");
Assert(
log.Contains("[WARNUNG] Self-Test-Diagnose")
&& !log.Contains("[FEHLER] Self-Test-Diagnose"),
"Optionale Ausnahme wurde nicht als Warnung protokolliert.");
}
finally
{
@@ -381,5 +434,79 @@ namespace BizTalkSapEnvironmentInventory.Infrastructure
throw new InvalidOperationException(message);
}
}
private interface IFakeApplication
{
IEnumerable Assemblies { get; }
}
private interface IFakeAssembly
{
IEnumerable Schemas { get; }
IEnumerable Transforms { get; }
IEnumerable Pipelines { get; }
}
private sealed class FakeApplication : IFakeApplication
{
private readonly IEnumerable assemblies;
public FakeApplication(params object[] assemblies)
{
this.assemblies = assemblies;
}
// ExplorerOM stellt einige Sammlungen explizit über Interfaces bereit.
IEnumerable IFakeApplication.Assemblies
{
get { return assemblies; }
}
}
private sealed class FakeAssembly : IFakeAssembly
{
private readonly IEnumerable schemas;
private readonly IEnumerable transforms;
private readonly IEnumerable pipelines;
public FakeAssembly(
string displayName,
object schema,
object transform,
object pipeline)
{
DisplayName = displayName;
schemas = new[] { schema };
transforms = new[] { transform };
pipelines = new[] { pipeline };
}
public string DisplayName { get; private set; }
IEnumerable IFakeAssembly.Schemas
{
get { return schemas; }
}
IEnumerable IFakeAssembly.Transforms
{
get { return transforms; }
}
IEnumerable IFakeAssembly.Pipelines
{
get { return pipelines; }
}
}
private sealed class FakeArtifact
{
public FakeArtifact(string fullName)
{
FullName = fullName;
}
public string FullName { get; private set; }
}
}
}