Skip to content

Commit 8a749af

Browse files
CopilotYoussef1313
andauthored
Add tests for solution filter with shared projects and platform configuration support (#51526)
Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Youssef1313 <[email protected]>
1 parent cdb835d commit 8a749af

File tree

17 files changed

+446
-0
lines changed

17 files changed

+446
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Solution>
2+
<Configurations>
3+
<BuildType Name="Debug" />
4+
<BuildType Name="Release" />
5+
<Platform Name="x64" />
6+
<Platform Name="x86" />
7+
</Configurations>
8+
<Project Path="TestProject/TestProject.csproj" />
9+
<Project Path="OtherTestProject/OtherTestProject.csproj">
10+
<Platform Solution="*|x86" Build="false" />
11+
</Project>
12+
</Solution>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />
3+
4+
<PropertyGroup>
5+
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
6+
<OutputType>Exe</OutputType>
7+
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
<Nullable>enable</Nullable>
10+
11+
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.Testing.Platform" Version="$(MicrosoftTestingPlatformVersion)" />
16+
</ItemGroup>
17+
</Project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using Microsoft.Testing.Platform.Builder;
2+
using Microsoft.Testing.Platform.Capabilities.TestFramework;
3+
using Microsoft.Testing.Platform.Extensions.Messages;
4+
using Microsoft.Testing.Platform.Extensions.TestFramework;
5+
6+
for (int i = 0; i < 3; i++)
7+
{
8+
Console.WriteLine(new string('a', 10000));
9+
Console.Error.WriteLine(new string('e', 10000));
10+
}
11+
12+
var testApplicationBuilder = await TestApplication.CreateBuilderAsync(args);
13+
14+
testApplicationBuilder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_, __) => new DummyTestAdapter());
15+
16+
using var testApplication = await testApplicationBuilder.BuildAsync();
17+
return await testApplication.RunAsync();
18+
19+
public class DummyTestAdapter : ITestFramework, IDataProducer
20+
{
21+
public string Uid => nameof(DummyTestAdapter);
22+
23+
public string Version => "2.0.0";
24+
25+
public string DisplayName => nameof(DummyTestAdapter);
26+
27+
public string Description => nameof(DummyTestAdapter);
28+
29+
public Task<bool> IsEnabledAsync() => Task.FromResult(true);
30+
31+
public Type[] DataTypesProduced => new[] {
32+
typeof(TestNodeUpdateMessage)
33+
};
34+
35+
public Task<CreateTestSessionResult> CreateTestSessionAsync(CreateTestSessionContext context)
36+
=> Task.FromResult(new CreateTestSessionResult() { IsSuccess = true });
37+
38+
public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context)
39+
=> Task.FromResult(new CloseTestSessionResult() { IsSuccess = true });
40+
41+
public async Task ExecuteRequestAsync(ExecuteRequestContext context)
42+
{
43+
await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, new TestNode()
44+
{
45+
Uid = "Test1",
46+
DisplayName = "Test1",
47+
Properties = new PropertyBag(new PassedTestNodeStateProperty("OK")),
48+
}));
49+
50+
await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, new TestNode()
51+
{
52+
Uid = "Test2",
53+
DisplayName = "Test2",
54+
Properties = new PropertyBag(new SkippedTestNodeStateProperty("skipped")),
55+
}));
56+
57+
context.Complete();
58+
}
59+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
using Microsoft.Testing.Platform.Builder;
2+
using Microsoft.Testing.Platform.Capabilities.TestFramework;
3+
using Microsoft.Testing.Platform.Extensions.Messages;
4+
using Microsoft.Testing.Platform.Extensions.TestFramework;
5+
6+
for (int i = 0; i < 3; i++)
7+
{
8+
Console.WriteLine(new string('a', 10000));
9+
Console.Error.WriteLine(new string('e', 10000));
10+
}
11+
12+
var testApplicationBuilder = await TestApplication.CreateBuilderAsync(args);
13+
14+
testApplicationBuilder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_, __) => new DummyTestAdapter());
15+
16+
using var testApplication = await testApplicationBuilder.BuildAsync();
17+
return await testApplication.RunAsync();
18+
19+
public class DummyTestAdapter : ITestFramework, IDataProducer
20+
{
21+
public string Uid => nameof(DummyTestAdapter);
22+
23+
public string Version => "2.0.0";
24+
25+
public string DisplayName => nameof(DummyTestAdapter);
26+
27+
public string Description => nameof(DummyTestAdapter);
28+
29+
public Task<bool> IsEnabledAsync() => Task.FromResult(true);
30+
31+
public Type[] DataTypesProduced => new[] {
32+
typeof(TestNodeUpdateMessage)
33+
};
34+
35+
public Task<CreateTestSessionResult> CreateTestSessionAsync(CreateTestSessionContext context)
36+
=> Task.FromResult(new CreateTestSessionResult() { IsSuccess = true });
37+
38+
public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context)
39+
=> Task.FromResult(new CloseTestSessionResult() { IsSuccess = true });
40+
41+
public async Task ExecuteRequestAsync(ExecuteRequestContext context)
42+
{
43+
await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, new TestNode()
44+
{
45+
Uid = "Test0",
46+
DisplayName = "Test0",
47+
Properties = new PropertyBag(new PassedTestNodeStateProperty("OK")),
48+
}));
49+
50+
await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, new TestNode()
51+
{
52+
Uid = "Test1",
53+
DisplayName = "Test1",
54+
Properties = new PropertyBag(new SkippedTestNodeStateProperty("OK skipped!")),
55+
}));
56+
57+
await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, new TestNode()
58+
{
59+
Uid = "Test2",
60+
DisplayName = "Test2",
61+
Properties = new PropertyBag(new FailedTestNodeStateProperty(new Exception("this is a failed test"), "not OK")),
62+
}));
63+
64+
context.Complete();
65+
}
66+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />
3+
4+
<PropertyGroup>
5+
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
6+
<OutputType>Exe</OutputType>
7+
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
<Nullable>enable</Nullable>
10+
11+
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.Testing.Platform" Version="$(MicrosoftTestingPlatformVersion)" />
16+
</ItemGroup>
17+
</Project>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"test": {
3+
"runner": "Microsoft.Testing.Platform"
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<Solution>
2+
<Project Path="TestProject/TestProject.csproj" />
3+
<Project Path="OtherTestProject/OtherTestProject.csproj" />
4+
<Project Path="SharedProject/SharedProject.shproj" />
5+
</Solution>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), testAsset.props))\testAsset.props" />
3+
4+
<PropertyGroup>
5+
<TargetFramework>$(CurrentTargetFramework)</TargetFramework>
6+
<OutputType>Exe</OutputType>
7+
8+
<ImplicitUsings>enable</ImplicitUsings>
9+
<Nullable>enable</Nullable>
10+
11+
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.Testing.Platform" Version="$(MicrosoftTestingPlatformVersion)" />
16+
</ItemGroup>
17+
</Project>
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using Microsoft.Testing.Platform.Builder;
2+
using Microsoft.Testing.Platform.Capabilities.TestFramework;
3+
using Microsoft.Testing.Platform.Extensions.Messages;
4+
using Microsoft.Testing.Platform.Extensions.TestFramework;
5+
6+
for (int i = 0; i < 3; i++)
7+
{
8+
Console.WriteLine(new string('a', 10000));
9+
Console.Error.WriteLine(new string('e', 10000));
10+
}
11+
12+
var testApplicationBuilder = await TestApplication.CreateBuilderAsync(args);
13+
14+
testApplicationBuilder.RegisterTestFramework(_ => new TestFrameworkCapabilities(), (_, __) => new DummyTestAdapter());
15+
16+
using var testApplication = await testApplicationBuilder.BuildAsync();
17+
return await testApplication.RunAsync();
18+
19+
public class DummyTestAdapter : ITestFramework, IDataProducer
20+
{
21+
public string Uid => nameof(DummyTestAdapter);
22+
23+
public string Version => "2.0.0";
24+
25+
public string DisplayName => nameof(DummyTestAdapter);
26+
27+
public string Description => nameof(DummyTestAdapter);
28+
29+
public Task<bool> IsEnabledAsync() => Task.FromResult(true);
30+
31+
public Type[] DataTypesProduced => new[] {
32+
typeof(TestNodeUpdateMessage)
33+
};
34+
35+
public Task<CreateTestSessionResult> CreateTestSessionAsync(CreateTestSessionContext context)
36+
=> Task.FromResult(new CreateTestSessionResult() { IsSuccess = true });
37+
38+
public Task<CloseTestSessionResult> CloseTestSessionAsync(CloseTestSessionContext context)
39+
=> Task.FromResult(new CloseTestSessionResult() { IsSuccess = true });
40+
41+
public async Task ExecuteRequestAsync(ExecuteRequestContext context)
42+
{
43+
await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, new TestNode()
44+
{
45+
Uid = "Test1",
46+
DisplayName = "Test1",
47+
Properties = new PropertyBag(new PassedTestNodeStateProperty("OK")),
48+
}));
49+
50+
await context.MessageBus.PublishAsync(this, new TestNodeUpdateMessage(context.Request.Session.SessionUid, new TestNode()
51+
{
52+
Uid = "Test2",
53+
DisplayName = "Test2",
54+
Properties = new PropertyBag(new SkippedTestNodeStateProperty("skipped")),
55+
}));
56+
57+
context.Complete();
58+
}
59+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace SharedProject
2+
{
3+
public class SharedClass
4+
{
5+
public static string GetMessage() => "Hello from shared project";
6+
}
7+
}

0 commit comments

Comments
 (0)