diff --git a/src/BuildCheck.UnitTests/BuildCheckManagerProviderTests.cs b/src/BuildCheck.UnitTests/BuildCheckManagerProviderTests.cs index d33261fc6d9..1cd861e4c98 100644 --- a/src/BuildCheck.UnitTests/BuildCheckManagerProviderTests.cs +++ b/src/BuildCheck.UnitTests/BuildCheckManagerProviderTests.cs @@ -28,7 +28,7 @@ public class BuildCheckManagerTests public BuildCheckManagerTests(ITestOutputHelper output) { _loggingService = LoggingService.CreateLoggingService(LoggerMode.Synchronous, 1); - _logger = new MockLogger(); + _logger = new MockLogger(output); _loggingService.RegisterLogger(_logger); _testedInstance = new BuildCheckManager(); } diff --git a/src/BuildCheck.UnitTests/TaskInvocationAnalysisDataTests.cs b/src/BuildCheck.UnitTests/TaskInvocationAnalysisDataTests.cs index 7d109f7da15..e764f20cae5 100644 --- a/src/BuildCheck.UnitTests/TaskInvocationAnalysisDataTests.cs +++ b/src/BuildCheck.UnitTests/TaskInvocationAnalysisDataTests.cs @@ -13,6 +13,7 @@ using Microsoft.Build.Utilities; using Shouldly; using Xunit; +using Xunit.Abstractions; using static Microsoft.Build.Experimental.BuildCheck.Infrastructure.BuildCheckManagerProvider; namespace Microsoft.Build.BuildCheck.UnitTests @@ -51,15 +52,19 @@ private void TaskInvocationAction(BuildCheckDataContext } } + private ITestOutputHelper _output; + private static TestCheck? s_testCheck; - public TaskInvocationCheckDataTests() + public TaskInvocationCheckDataTests(ITestOutputHelper output) { + _output = output; + BuildCheckManager.s_testFactoriesPerDataSource = [ // BuildCheckDataSource.EventArgs [ - ([TestCheck.SupportedRule.Id], true, () => (s_testCheck = new TestCheck())), + ([TestCheck.SupportedRule.Id], true, () => s_testCheck = new TestCheck()), ], // BuildCheckDataSource.Execution [], @@ -75,7 +80,7 @@ public void Dispose() private void BuildProject(string taskInvocation) { - using (var env = TestEnvironment.Create()) + using (var env = TestEnvironment.Create(_output)) { var testProject = env.CreateTestProjectWithFiles($"{taskInvocation}"); @@ -84,6 +89,7 @@ private void BuildProject(string taskInvocation) var request = new BuildRequestData(testProject.ProjectFile, new Dictionary(), MSBuildConstants.CurrentToolsVersion, [], null, BuildRequestDataFlags.None); var parameters = new BuildParameters { + Loggers = [new MockLogger(_output)], LogTaskInputs = true, IsBuildCheckEnabled = true, ShutdownInProcNodeOnBuildFinish = true, @@ -94,7 +100,7 @@ private void BuildProject(string taskInvocation) result.OverallResult.ShouldBe(BuildResultCode.Success); } - foreach (var data in s_testCheck!.CheckData) + foreach (var data in s_testCheck.ShouldNotBeNull().CheckData) { data.ProjectFilePath.ShouldBe(testProject.ProjectFile); data.TaskInvocationLocation.Line.ShouldBeGreaterThan(0);