Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update NativeAOT runner example #2634

Merged
merged 2 commits into from
Mar 28, 2024
Merged
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
11 changes: 5 additions & 6 deletions samples/mstest-runner/NativeAotRunner/ClassLibrary1/Class1.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
namespace ClassLibrary1
namespace ClassLibrary1;

public class Class1
{
public class Class1
public int Add(int left, int right)
{
public int Add(int left, int right)
{
return left + right;
}
return left + right;
}
}
24 changes: 12 additions & 12 deletions samples/mstest-runner/NativeAotRunner/TestProject1/Program.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
using Microsoft.Testing.Extensions;
using Microsoft.Testing.Internal.Framework;
using Microsoft.Testing.Framework;
using Microsoft.Testing.Platform.Builder;
namespace TestProject1

namespace TestProject1;
internal static class Program
{
internal static class Program
public static async Task<int> Main(string[] args)
{
public static async Task<int> Main(string[] args)
{
var builder = await TestApplication.CreateBuilderAsync(args);
// Registers TestFramework, with tree of test nodes that are generated into your project by source generator.
builder.AddTestFramework(new SourceGeneratedTestNodesBuilder());
builder.AddTrxReportProvider();
var app = await builder.BuildAsync();
return await app.RunAsync();
}
var builder = await TestApplication.CreateBuilderAsync(args);
// Registers TestFramework, with tree of test nodes that are generated into your project by source generator.
builder.AddTestFramework(new SourceGeneratedTestNodesBuilder());
builder.AddTrxReportProvider();
builder.AddCodeCoverageProvider();
var app = await builder.BuildAsync();
return await app.RunAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
close sourced, licensed the same as our extensions
with Microsoft Testing Platform Tools license.
-->
<PackageReference Include="MSTest.Engine" Version="1.0.0-alpha.24151.3" />
<PackageReference Include="MSTest.SourceGeneration" Version="1.0.0-alpha.24151.3" />
<PackageReference Include="MSTest.Engine" Version="1.0.0-alpha.24163.4" />
<PackageReference Include="MSTest.SourceGeneration" Version="1.0.0-alpha.24163.4" />

<PackageReference Include="Microsoft.CodeCoverage.MSBuild" Version="17.10.4" />
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" Version="17.10.4" />

<!-- From nuget.org. -->
<PackageReference Include="Microsoft.Testing.Extensions.TrxReport" Version="1.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.2" />
<PackageReference Include="MSTest.Analyzers" Version="3.2.2" />
Expand Down
89 changes: 44 additions & 45 deletions samples/mstest-runner/NativeAotRunner/TestProject1/UnitTest1.cs
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
using ClassLibrary1;

namespace TestProject1
namespace TestProject1;

[TestClass]
public class UnitTest1
{
[TestClass]
public class UnitTest1
[TestMethod]
public void TestMethod1()
{
Assert.AreEqual(3, new Class1().Add(1, 2));
}

[TestMethod]
[DataRow(1, 2)]
public void TestMethod2(int left, int right)
{
[TestMethod]
public void TestMethod1()
{
Assert.AreEqual(3, new Class1().Add(1, 2));
}

[TestMethod]
[DataRow(1, 2)]
public void TestMethod2(int left, int right)
{
Assert.AreEqual(3, new Class1().Add(left, right));
}

[TestMethod]
[DynamicData(nameof(Data))]
public void TestMethod3(int left, int right)
{
Assert.AreEqual(3, new Class1().Add(left, right));
}

[TestMethod]
[DynamicData(nameof(Users))]
public void TestMethod4(User u)
{
Assert.AreEqual(3, new Class1().Add(u.Left, u.Right));
}

public static IEnumerable<object[]> Data { get; } =
[
[1, 2],
[-3, 6],
];

public static IEnumerable<object[]> Users { get; } =
[
[new User { Left = 1, Right = 2 }],
[new User { Left = -3, Right = 6}],
];
Assert.AreEqual(3, new Class1().Add(left, right));
}

public class User
[TestMethod]
[DynamicData(nameof(Data))]
public void TestMethod3(int left, int right)
{
public required int Left { get; init; }
public required int Right { get; init; }
Assert.AreEqual(3, new Class1().Add(left, right));
}
}

[TestMethod]
[DynamicData(nameof(Users))]
public void TestMethod4(User u)
{
Assert.AreEqual(3, new Class1().Add(u.Left, u.Right));
}

public static IEnumerable<object[]> Data { get; } =
[
[1, 2],
[-3, 6],
];

public static IEnumerable<object[]> Users { get; } =
[
[new User { Left = 1, Right = 2 }],
[new User { Left = -3, Right = 6}],
];
}

public class User
{
public required int Left { get; init; }
public required int Right { get; init; }
}
4 changes: 2 additions & 2 deletions samples/mstest-runner/NativeAotRunner/nuget.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!-- MSTest early access packages. See: https://aka.ms/mstest/preview uncomment this line -->
<!-- <add key="test-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/test-tools/nuget/v3/index.json" /> -->
<clear />
<add key="nuget" value="https://api.nuget.org/v3/index.json" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not do that, this is causing security alerts. We should instead use the dotnet-public feed. I think just dropping this nuget.config to use the one from parent folder would be enough.

</packageSources>
</configuration>
Loading