diff --git a/test/TestAssets/TestProjects/TestProjectMTPWithUseAppHostFalse/Program.cs b/test/TestAssets/TestProjects/TestProjectMTPWithUseAppHostFalse/Program.cs new file mode 100644 index 000000000000..aca68508c192 --- /dev/null +++ b/test/TestAssets/TestProjects/TestProjectMTPWithUseAppHostFalse/Program.cs @@ -0,0 +1,47 @@ +using Microsoft.Testing.Platform.Builder; +using Microsoft.Testing.Platform.Capabilities.TestFramework; +using Microsoft.Testing.Platform.Extensions.Messages; +using Microsoft.Testing.Platform.Extensions.TestFramework; + +var testApplicationBuilder = await TestApplication.CreateBuilderAsync(args); + +testApplicationBuilder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_, __) => new DummyTestAdapter()); + +using var testApplication = await testApplicationBuilder.BuildAsync(); +return await testApplication.RunAsync(); + +public class DummyTestAdapter : ITestFramework, IDataProducer +{ + public string Uid => nameof(DummyTestAdapter); + + public string Version => "2.0.0"; + + public string DisplayName => nameof(DummyTestAdapter); + + public string Description => nameof(DummyTestAdapter); + + public Task IsEnabledAsync() => Task.FromResult(true); + + public Type[] DataTypesProduced { get; } = [typeof(TestNodeUpdateMessage)]; + + public Task CreateTestSessionAsync(CreateTestSessionContext context) + => Task.FromResult(new CreateTestSessionResult() { IsSuccess = true }); + + public Task CloseTestSessionAsync(CloseTestSessionContext context) + => Task.FromResult(new CloseTestSessionResult() { IsSuccess = true }); + + public async Task ExecuteRequestAsync(ExecuteRequestContext context) + { + // Simple dummy test that always passes + await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage( + context.Request.Session.SessionUid, + new TestNode() + { + Uid = "dummy_test_1", + DisplayName = "Dummy Test 1", + Properties = new PropertyBag(PassedTestNodeStateProperty.CachedInstance) + })); + + context.Complete(); + } +} diff --git a/test/TestAssets/TestProjects/TestProjectMTPWithUseAppHostFalse/TestProjectMTPWithUseAppHostFalse.csproj b/test/TestAssets/TestProjects/TestProjectMTPWithUseAppHostFalse/TestProjectMTPWithUseAppHostFalse.csproj new file mode 100644 index 000000000000..9fd88a6e395e --- /dev/null +++ b/test/TestAssets/TestProjects/TestProjectMTPWithUseAppHostFalse/TestProjectMTPWithUseAppHostFalse.csproj @@ -0,0 +1,19 @@ + + + + + $(CurrentTargetFramework) + Exe + false + + enable + enable + + false + true + + + + + + diff --git a/test/TestAssets/TestProjects/TestProjectMTPWithUseAppHostFalse/dotnet.config b/test/TestAssets/TestProjects/TestProjectMTPWithUseAppHostFalse/dotnet.config new file mode 100644 index 000000000000..da0410e32d54 --- /dev/null +++ b/test/TestAssets/TestProjects/TestProjectMTPWithUseAppHostFalse/dotnet.config @@ -0,0 +1,2 @@ +[dotnet.test.runner] +name = "Microsoft.Testing.Platform" diff --git a/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs b/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs index 549b50e93552..853a46e8829d 100644 --- a/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs +++ b/test/dotnet.Tests/CommandTests/Test/GivenDotnetTestBuildsAndRunsTests.cs @@ -374,5 +374,20 @@ public void RunningWithGlobalPropertyShouldProperlyPropagate(string configuratio result.ExitCode.Should().Be(ExitCodes.Success); } + + [Fact] + public void RunMTPProjectWithUseAppHostFalse_ShouldWork() + { + TestAsset testInstance = _testAssetsManager.CopyTestAsset("TestProjectMTPWithUseAppHostFalse", Guid.NewGuid().ToString()) + .WithSource(); + + // Run test with UseAppHost=false + CommandResult result = new DotnetTestCommand(Log, disableNewOutput: false) + .WithWorkingDirectory(testInstance.Path) + .Execute(); + + // Verify the test runs successfully with UseAppHost=false + result.ExitCode.Should().Be(0); + } } }