Skip to content

Commit 0041ad3

Browse files
authored
Merge pull request #1011 from Cysharp/copilot/migrate-tests-to-tunit
2 parents be784b8 + 376f98d commit 0041ad3

File tree

7 files changed

+64
-64
lines changed

7 files changed

+64
-64
lines changed

.nuget/nuget.exe

7.88 MB
Binary file not shown.

Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
4646
<PackageVersion Include="NSubstitute" Version="5.0.0" />
4747
<PackageVersion Include="Testcontainers" Version="2.3.0" />
48+
<PackageVersion Include="TUnit" Version="0.4.105" />
4849
<PackageVersion Include="xunit.v3" Version="1.0.0" />
4950
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.0" />
5051
</ItemGroup>

tests/MagicOnion.Client.NativeAot.Tests/MSTestSettings.cs

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/MagicOnion.Client.NativeAot.Tests/MagicOnion.Client.NativeAot.Tests.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="MSTest.Sdk/3.6.1">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net9.0</TargetFramework>
@@ -19,16 +19,16 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="coverlet.collector" />
22+
<PackageReference Include="TUnit" />
23+
<PackageReference Include="coverlet.collector">
24+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
25+
<PrivateAssets>all</PrivateAssets>
26+
</PackageReference>
2327
</ItemGroup>
2428

2529
<ItemGroup>
2630
<ProjectReference Include="..\..\src\MagicOnion.Client\MagicOnion.Client.csproj" />
2731
<ProjectReference Include="..\..\src\MagicOnion.Client.SourceGenerator\MagicOnion.Client.SourceGenerator.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
2832
</ItemGroup>
2933

30-
<ItemGroup>
31-
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
32-
</ItemGroup>
33-
3434
</Project>

tests/MagicOnion.Client.NativeAot.Tests/ResolverTest.cs

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
namespace MagicOnion.Client.NativeAot.Tests;
55

66
// NOTE: This test uses a Resolver that contains code corresponding to the arguments and return values of IUnaryTestService.
7-
[TestClass]
87
public sealed class ResolverTest
98
{
109
static ResolverTest()
@@ -13,8 +12,8 @@ static ResolverTest()
1312
_ = typeof(MessagePack.GeneratedMessagePackResolver).GetFields();
1413
}
1514

16-
[TestMethod]
17-
public void MyObject()
15+
[Test]
16+
public async Task MyObject()
1817
{
1918
// Arrange
2019
var options = MessagePackSerializerOptions.Standard.WithResolver(CompositeResolver.Create(MagicOnionClientGeneratedInitializer.Resolver, StandardResolver.Instance));
@@ -27,12 +26,12 @@ public void MyObject()
2726
writer.Flush();
2827

2928
// Assert
30-
Assert.IsNotNull(formatter);
31-
Assert.AreEqual("0x91, 0xcd, 0x30, 0x39", string.Join(", ", arrayBufferWriter.WrittenMemory.ToArray().Select(x => $"0x{x:x2}")));
29+
await Assert.That(formatter).IsNotNull();
30+
await Assert.That(string.Join(", ", arrayBufferWriter.WrittenMemory.ToArray().Select(x => $"0x{x:x2}"))).IsEqualTo("0x91, 0xcd, 0x30, 0x39");
3231
}
3332

34-
[TestMethod]
35-
public void DynamicArgumentTuple()
33+
[Test]
34+
public async Task DynamicArgumentTuple()
3635
{
3736
// Arrange
3837
var options = MessagePackSerializerOptions.Standard.WithResolver(CompositeResolver.Create(MagicOnionClientGeneratedInitializer.Resolver, StandardResolver.Instance));
@@ -45,12 +44,12 @@ public void DynamicArgumentTuple()
4544
writer.Flush();
4645

4746
// Assert
48-
Assert.IsNotNull(formatter);
49-
Assert.AreEqual("0x92, 0xcd, 0x30, 0x39, 0xac, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21", string.Join(", ", arrayBufferWriter.WrittenMemory.ToArray().Select(x => $"0x{x:x2}")));
47+
await Assert.That(formatter).IsNotNull();
48+
await Assert.That(string.Join(", ", arrayBufferWriter.WrittenMemory.ToArray().Select(x => $"0x{x:x2}"))).IsEqualTo("0x92, 0xcd, 0x30, 0x39, 0xac, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x21");
5049
}
5150

52-
//[TestMethod]
53-
//public void DynamicArgumentTuple_Unknown()
51+
//[Test]
52+
//public async Task DynamicArgumentTuple_Unknown()
5453
//{
5554
// // Arrange
5655
// var options = MessagePackSerializerOptions.Standard.WithResolver(CompositeResolver.Create(MagicOnionClientGeneratedInitializer.Resolver, StandardResolver.Instance));
@@ -59,11 +58,11 @@ public void DynamicArgumentTuple()
5958
// var formatter = options.Resolver.GetFormatter<DynamicArgumentTuple<int, string, object, bool, Uri, Guid, MyEnumValue>>();
6059

6160
// // Assert
62-
// Assert.IsNull(formatter);
61+
// await Assert.That(formatter).IsNull();
6362
//}
6463

65-
[TestMethod]
66-
public void Enum()
64+
[Test]
65+
public async Task Enum()
6766
{
6867
// Arrange
6968
var options = MessagePackSerializerOptions.Standard.WithResolver(CompositeResolver.Create(MagicOnionClientGeneratedInitializer.Resolver, StandardResolver.Instance));
@@ -76,12 +75,12 @@ public void Enum()
7675
writer.Flush();
7776

7877
// Assert
79-
Assert.IsNotNull(formatter);
80-
Assert.AreEqual("0x02", string.Join(", ", arrayBufferWriter.WrittenMemory.ToArray().Select(x => $"0x{x:x2}")));
78+
await Assert.That(formatter).IsNotNull();
79+
await Assert.That(string.Join(", ", arrayBufferWriter.WrittenMemory.ToArray().Select(x => $"0x{x:x2}"))).IsEqualTo("0x02");
8180
}
8281

83-
//[TestMethod]
84-
//public void Enum_Unknown()
82+
//[Test]
83+
//public async Task Enum_Unknown()
8584
//{
8685
// // Arrange
8786
// var options = MessagePackSerializerOptions.Standard.WithResolver(CompositeResolver.Create(MagicOnionClientGeneratedInitializer.Resolver, StandardResolver.Instance));
@@ -90,11 +89,11 @@ public void Enum()
9089
// var formatter = options.Resolver.GetFormatter<UnknownEnumValue>();
9190

9291
// // Assert
93-
// Assert.IsNull(formatter);
92+
// await Assert.That(formatter).IsNull();
9493
//}
9594

96-
[TestMethod]
97-
public void BuiltInGenerics_List()
95+
[Test]
96+
public async Task BuiltInGenerics_List()
9897
{
9998
// Arrange
10099
var options = MessagePackSerializerOptions.Standard.WithResolver(CompositeResolver.Create(MagicOnionClientGeneratedInitializer.Resolver, StandardResolver.Instance));
@@ -107,12 +106,12 @@ public void BuiltInGenerics_List()
107106
writer.Flush();
108107

109108
// Assert
110-
Assert.IsNotNull(formatter);
111-
Assert.AreEqual("0x93, 0x91, 0x01, 0x91, 0x64, 0x91, 0xcd, 0x03, 0xe8", string.Join(", ", arrayBufferWriter.WrittenMemory.ToArray().Select(x => $"0x{x:x2}")));
109+
await Assert.That(formatter).IsNotNull();
110+
await Assert.That(string.Join(", ", arrayBufferWriter.WrittenMemory.ToArray().Select(x => $"0x{x:x2}"))).IsEqualTo("0x93, 0x91, 0x01, 0x91, 0x64, 0x91, 0xcd, 0x03, 0xe8");
112111
}
113112

114-
[TestMethod]
115-
public void BuiltInGenerics_Dictionary()
113+
[Test]
114+
public async Task BuiltInGenerics_Dictionary()
116115
{
117116
// Arrange
118117
var options = MessagePackSerializerOptions.Standard.WithResolver(CompositeResolver.Create(MagicOnionClientGeneratedInitializer.Resolver, StandardResolver.Instance));
@@ -129,12 +128,12 @@ [new MyObject(67890)] = "World",
129128
writer.Flush();
130129

131130
// Assert
132-
Assert.IsNotNull(formatter);
133-
Assert.AreEqual("0x82, 0x91, 0xcd, 0x30, 0x39, 0xa5, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x91, 0xce, 0x00, 0x01, 0x09, 0x32, 0xa5, 0x57, 0x6f, 0x72, 0x6c, 0x64", string.Join(", ", arrayBufferWriter.WrittenMemory.ToArray().Select(x => $"0x{x:x2}")));
131+
await Assert.That(formatter).IsNotNull();
132+
await Assert.That(string.Join(", ", arrayBufferWriter.WrittenMemory.ToArray().Select(x => $"0x{x:x2}"))).IsEqualTo("0x82, 0x91, 0xcd, 0x30, 0x39, 0xa5, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x91, 0xce, 0x00, 0x01, 0x09, 0x32, 0xa5, 0x57, 0x6f, 0x72, 0x6c, 0x64");
134133
}
135134

136-
//[TestMethod]
137-
//public void BuiltInGenerics_Unknown()
135+
//[Test]
136+
//public async Task BuiltInGenerics_Unknown()
138137
//{
139138
// // Arrange
140139
// var options = MessagePackSerializerOptions.Standard.WithResolver(CompositeResolver.Create(MagicOnionClientGeneratedInitializer.Resolver, StandardResolver.Instance));
@@ -144,8 +143,8 @@ [new MyObject(67890)] = "World",
144143
// var formatter2 = options.Resolver.GetFormatter<Dictionary<UnknownObject, string>>();
145144

146145
// // Assert
147-
// Assert.IsNull(formatter1);
148-
// Assert.IsNull(formatter2);
146+
// await Assert.That(formatter1).IsNull();
147+
// await Assert.That(formatter2).IsNull();
149148
//}
150149

151150
class UnknownObject;

tests/MagicOnion.Client.NativeAot.Tests/UnaryTest.cs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,10 @@
33

44
namespace MagicOnion.Client.NativeAot.Tests;
55

6-
[TestClass]
76
public sealed class UnaryTest
87
{
9-
[TestMethod]
10-
public void Create()
8+
[Test]
9+
public async Task Create()
1110
{
1211
// Arrange
1312
var resolvers = CompositeResolver.Create(MagicOnionClientGeneratedInitializer.Resolver, StandardResolver.Instance);
@@ -18,10 +17,10 @@ public void Create()
1817
var client = MagicOnionClient.Create<IUnaryTestService>(callInvokerMock, serializerOptions);
1918

2019
// Assert
21-
Assert.IsNotNull(client);
20+
await Assert.That(client).IsNotNull();
2221
}
2322

24-
[TestMethod]
23+
[Test]
2524
public async Task Invoke_With_Arguments()
2625
{
2726
// Arrange
@@ -36,12 +35,12 @@ public async Task Invoke_With_Arguments()
3635
var result = await resultTask.ResponseAsync.WaitAsync(TimeSpan.FromSeconds(5));
3736

3837
// Assert
39-
Assert.AreEqual(67890, result);
40-
Assert.AreEqual(1, callInvokerMock.RequestPayloads.Count);
41-
Assert.AreEqual("0x92, 0xcd, 0x30, 0x39, 0xa5, 0x48, 0x65, 0x6c, 0x6c, 0x6f", string.Join(", ", callInvokerMock.RequestPayloads[0].Select(x => $"0x{x:x2}")));
38+
await Assert.That(result).IsEqualTo(67890);
39+
await Assert.That(callInvokerMock.RequestPayloads.Count).IsEqualTo(1);
40+
await Assert.That(string.Join(", ", callInvokerMock.RequestPayloads[0].Select(x => $"0x{x:x2}"))).IsEqualTo("0x92, 0xcd, 0x30, 0x39, 0xa5, 0x48, 0x65, 0x6c, 0x6c, 0x6f");
4241
}
4342

44-
[TestMethod]
43+
[Test]
4544
public async Task Invoke_Enum()
4645
{
4746
// Arrange
@@ -56,11 +55,11 @@ public async Task Invoke_Enum()
5655
await resultTask.ResponseAsync.WaitAsync(TimeSpan.FromSeconds(5));
5756

5857
// Assert
59-
Assert.AreEqual(1, callInvokerMock.RequestPayloads.Count);
60-
Assert.AreEqual("0x02", string.Join(", ", callInvokerMock.RequestPayloads[0].Select(x => $"0x{x:x2}")));
58+
await Assert.That(callInvokerMock.RequestPayloads.Count).IsEqualTo(1);
59+
await Assert.That(string.Join(", ", callInvokerMock.RequestPayloads[0].Select(x => $"0x{x:x2}"))).IsEqualTo("0x02");
6160
}
6261

63-
[TestMethod]
62+
[Test]
6463
public async Task Invoke_Enum_Return()
6564
{
6665
// Arrange
@@ -75,12 +74,12 @@ public async Task Invoke_Enum_Return()
7574
var result = await resultTask.ResponseAsync.WaitAsync(TimeSpan.FromSeconds(5));
7675

7776
// Assert
78-
Assert.AreEqual(1, callInvokerMock.RequestPayloads.Count);
79-
Assert.AreEqual(MyEnumValue.C, result);
77+
await Assert.That(callInvokerMock.RequestPayloads.Count).IsEqualTo(1);
78+
await Assert.That(result).IsEqualTo(MyEnumValue.C);
8079
}
8180

8281

83-
[TestMethod]
82+
[Test]
8483
public async Task Invoke_BuiltInGeneric()
8584
{
8685
// Arrange
@@ -95,11 +94,11 @@ public async Task Invoke_BuiltInGeneric()
9594
await resultTask.ResponseAsync.WaitAsync(TimeSpan.FromSeconds(5));
9695

9796
// Assert
98-
Assert.AreEqual(1, callInvokerMock.RequestPayloads.Count);
99-
Assert.AreEqual("0x95, 0x91, 0x01, 0x91, 0x02, 0x91, 0x03, 0x91, 0x04, 0x91, 0x05", string.Join(", ", callInvokerMock.RequestPayloads[0].Select(x => $"0x{x:x2}")));
97+
await Assert.That(callInvokerMock.RequestPayloads.Count).IsEqualTo(1);
98+
await Assert.That(string.Join(", ", callInvokerMock.RequestPayloads[0].Select(x => $"0x{x:x2}"))).IsEqualTo("0x95, 0x91, 0x01, 0x91, 0x02, 0x91, 0x03, 0x91, 0x04, 0x91, 0x05");
10099
}
101100

102-
[TestMethod]
101+
[Test]
103102
public async Task Invoke_BuiltInGeneric_Return()
104103
{
105104
// Arrange
@@ -114,14 +113,14 @@ public async Task Invoke_BuiltInGeneric_Return()
114113
var result = await resultTask.ResponseAsync.WaitAsync(TimeSpan.FromSeconds(5));
115114

116115
// Assert
117-
Assert.AreEqual(1, callInvokerMock.RequestPayloads.Count);
118-
Assert.IsTrue(result.ContainsKey(new(12)));
119-
Assert.AreEqual("FooBar", result[new(12)]);
120-
Assert.IsTrue(result.ContainsKey(new(34)));
121-
Assert.AreEqual("Baz", result[new(34)]);
116+
await Assert.That(callInvokerMock.RequestPayloads.Count).IsEqualTo(1);
117+
await Assert.That(result.ContainsKey(new(12))).IsTrue();
118+
await Assert.That(result[new(12)]).IsEqualTo("FooBar");
119+
await Assert.That(result.ContainsKey(new(34))).IsTrue();
120+
await Assert.That(result[new(34)]).IsEqualTo("Baz");
122121
}
123122

124-
//[TestMethod]
123+
//[Test]
125124
//public async Task Invoke_With_Arguments_ResolverUnregistered()
126125
//{
127126
// // Arrange
@@ -143,8 +142,8 @@ public async Task Invoke_BuiltInGeneric_Return()
143142
// }
144143

145144
// // Assert
146-
// Assert.IsNotNull(ex);
147-
// Assert.IsInstanceOfType<MessagePackSerializationException>(ex);
145+
// await Assert.That(ex).IsNotNull();
146+
// await Assert.That(ex).IsTypeOf<MessagePackSerializationException>();
148147
//}
149148
}
150149

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
global using Grpc.Core;
22
global using MessagePack;
3+
global using TUnit.Assertions;
4+
global using TUnit.Core;

0 commit comments

Comments
 (0)