Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions AppInspector.CLI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("AppInspector.Tests")]
2 changes: 1 addition & 1 deletion AppInspector.CLI/Writers/JsonWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override void WriteResults(Result result, CLICommandOptions commandOption
case TagDiffResult:
case ExportTagsResult:
case VerifyRulesResult:
JsonSerializer.Serialize(StreamWriter.BaseStream, result, options);
JsonSerializer.Serialize(StreamWriter.BaseStream, result, result.GetType(), options);
break;
case PackRulesResult prr:
JsonSerializer.Serialize(StreamWriter.BaseStream, prr.Rules, options);
Expand Down
37 changes: 37 additions & 0 deletions AppInspector.Tests/Commands/TestExportTagsCmd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,41 @@ public void NoDefaultNoCustomRules()
};
Assert.Throws<OpException>(() => new ExportTagsCommand(options));
}

[Fact]
public void ExportJsonSerialization()
{
ExportTagsOptions options = new()
{
IgnoreDefaultRules = true,
CustomRulesPath = testRulesPath
};
ExportTagsCommand command = new(options, factory);
var result = command.GetResult();

// Test JSON serialization via the production JsonWriter to ensure tags are included
using var memoryStream = new MemoryStream();
using var streamWriter = new StreamWriter(memoryStream);

// Use the JsonWriter that production code uses
var jsonWriter = new Microsoft.ApplicationInspector.CLI.Writers.JsonWriter(streamWriter, factory);
var cliOptions = new Microsoft.ApplicationInspector.CLI.CLIExportTagsCmdOptions
{
IgnoreDefaultRules = true,
CustomRulesPath = testRulesPath
};

jsonWriter.WriteResults(result, cliOptions, autoClose: false);
streamWriter.Flush();

memoryStream.Position = 0;
using var reader = new StreamReader(memoryStream);
string json = reader.ReadToEnd();

// Verify tags are present in JSON output from JsonWriter
Assert.Contains("Test.Tags.Linux", json);
Assert.Contains("Test.Tags.Windows", json);
Assert.Contains("tagsList", json);
Assert.Contains("appVersion", json);
}
}
Loading