Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jsakamoto committed Dec 3, 2023
1 parent 15adb0c commit b284183
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 192 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/unit-tests-for-mstest.yml
Expand Up @@ -9,14 +9,14 @@ jobs:
runs-on: ubuntu-latest
steps:
# Checkout the code
- uses: actions/checkout@v2
- uses: actions/checkout@v3

# Install .NET Core SDK
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.*
dotnet-version: 8.0.*

# Perform unit tests
- name: Perform unit tests
run: dotnet test ChainingAssertion.MSTest.UnitTest -l "console;verbosity=normal" -v:q --nologo
run: dotnet test ChainingAssertion.MSTest.UnitTest -l "console;verbosity=normal" -v:q --nologo -f:net8.0
8 changes: 4 additions & 4 deletions .github/workflows/unit-tests-for-xunit.yml
Expand Up @@ -9,14 +9,14 @@ jobs:
runs-on: ubuntu-latest
steps:
# Checkout the code
- uses: actions/checkout@v2
- uses: actions/checkout@v3

# Install .NET Core SDK
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
uses: actions/setup-dotnet@v2
with:
dotnet-version: 6.0.*
dotnet-version: 8.0.*

# Perform unit tests
- name: Perform unit tests
run: dotnet test ChainingAssertion.xUnit.UnitTest -l "console;verbosity=normal" -v:q --nologo
run: dotnet test ChainingAssertion.xUnit.UnitTest -l "console;verbosity=normal" -v:q --nologo -f:net8.0
102 changes: 33 additions & 69 deletions ChainingAssertion.MSTest.UnitTest/AssertExTest.cs
Expand Up @@ -48,7 +48,7 @@ public void CollectionTest()
public void OthersTest()
{
// Null Assertions
Object? obj = GetNullableObject();
var obj = GetNullableObject();
obj.IsNotNull(); // Assert.NotNull(obj)
obj.ToString().Is("{ Foo = Bar }");

Expand Down Expand Up @@ -219,74 +219,46 @@ public void DynamicNullableTest()
{
var d = new PrivateMock().AsDynamic();

(d.NullableMethod((IEnumerable<int>?)null) as string).Is("enumerable");
(d.NullableMethod((List<int>?)null) as string).Is("enumerable");
AssertEx.Throws<ArgumentException>(() => { d.NullableMethod((IEnumerable<int>?)null); })
.IsNotNull()
.Message.StartsWith("\"NullableMethod\" ambiguous arguments")
.IsTrue();
AssertEx.Throws<ArgumentException>(() => { d.NullableMethod((List<int>?)null); })
.IsNotNull()
.Message.StartsWith("\"NullableMethod\" ambiguous arguments")
.IsTrue();

(d.NullableMethod(Enumerable.Range(1, 10)) as string).Is("enumerable");
(d.NullableMethod(new List<int>().AsEnumerable()) as string).Is("enumerable");
(d.NullableMethod(new List<int>()) as string).Is("enumerable");
(d.NullableMethod(new List<int>().AsEnumerable()) as string).Is("list");
(d.NullableMethod(new List<int>()) as string).Is("list");
}

public class GenericPrivateMock
{
private string PrivateGeneric<T1, T2>(T1 t1a, T2 t2a, T1 t1b)
{
return "a";
}
private string PrivateGeneric<T1, T2>(T1 t1a, T2 t2a, T1 t1b) => "a";

private string PrivateGeneric<T1, T2, T3>(T1 t1a, T2 t2a, T1 t1b)
{
return "b";
}
private string PrivateGeneric<T1, T2, T3>(T1 t1a, T2 t2a, T1 t1b) => "b";

private string PrivateGeneric<T1, T2>(T1 t1a, T2 t2a, int i)
{
return "c";
}
private string PrivateGeneric<T1, T2>(T1 t1a, T2 t2a, int i) => "c";

private string PrivateGeneric<T1, T2>(T1 t1a, T2 t2a, int i, T2 t2b)
{
return "d";
}
private string PrivateGeneric<T1, T2>(T1 t1a, T2 t2a, int i, T2 t2b) => "d";

private string PrivateGeneric(string t1a, string t2a, string t1b)
{
return "e";
}
private string PrivateGeneric(string t1a, string t2a, string t1b) => "e";

private string PrivateGeneric<T1, T2, T3>(T3 t3a, T2 t2, T1 t1, T3 t3b)
{
return "f";
}
private string PrivateGeneric<T1, T2, T3>(T3 t3a, T2 t2, T1 t1, T3 t3b) => "f";

private string PrivateGeneric<T>()
{
return "g";
}
private string PrivateGeneric<T>() => "g";

private string PrivateGeneric()
{
return "h";
}
private string PrivateGeneric() => "h";

private Type ReturnType<T>(T t1, T t2)
{
return typeof(T);
}
private Type ReturnType<T>(T t1, T t2) => typeof(T);

private Type ReturnType<T>(IEnumerable<T> t1, T t2)
{
return typeof(T);
}
private Type ReturnType<T>(IEnumerable<T> t1, T t2) => typeof(T);

private string DictGen<T1, T2, T3>(IDictionary<T1, IDictionary<T2, T3>> dict, T3 xxx)
{
return "dict";
}
private string DictGen<T1, T2, T3>(IDictionary<T1, IDictionary<T2, T3>> dict, T3 t) => "dict";
}

[TestMethod]
[Ignore("Currently, this test is broken. It would be fixed in the future.")]
public void GenericPrivateTest()
{
var d = new GenericPrivateMock().AsDynamic();
Expand All @@ -303,12 +275,18 @@ public void GenericPrivateTest()
(d.PrivateGeneric<int, string, double>(0.0, "", 0, 0.0) as string).Is("f");
(d.PrivateGeneric<int>() as string).Is("g");
(d.PrivateGeneric() as string).Is("h");
(d.ReturnType(0, 0) as Type).Is(typeof(int));

(d.PrivateGeneric(0, "", 0) as string).Is("c");
(d.PrivateGeneric<int, string>(0, "", 0) as string).Is("c");
(d.PrivateGeneric(0, 0, 0) as string).Is("c");

(d.ReturnType(0, 0) as Type).Is(typeof(int));
(d.ReturnType(Enumerable.Range(1, 10), 0) as Type).Is(typeof(int));
(d.ReturnType<int>(Enumerable.Range(1, 10), 0) as Type).Is(typeof(int));
(d.ReturnType<IEnumerable<int>>(Enumerable.Range(1, 10), new List<int>()) as Type).Is(typeof(IEnumerable<int>));

var dict = new Dictionary<int, IDictionary<string, double>>();
(d.DictGen(dict, 1.9) as string).Is("dict");
(d.DictGen<int, string, double>(dict, 1.9) as string).Is("dict");
}

[TestMethod]
Expand All @@ -326,20 +304,6 @@ public void GenericPrivateExceptionTest()
e3.Message.Is(s => s.Contains("not match arguments") && s.Contains("PrivateGeneric"));
}

[TestMethod]
[Ignore("Currently, this test is broken. It would be fixed in the future.")]
public void DynamicNotSupportedCase()
{
var d = new GenericPrivateMock().AsDynamic();

(d.ReturnType(Enumerable.Range(1, 10), 0) as Type).Is(typeof(int));
(d.ReturnType<int>(Enumerable.Range(1, 10), 0) as Type).Is(typeof(int));

var dict = new Dictionary<int, IDictionary<string, double>>();
(d.DictGen(dict, 1.9) as string).Is("dict");
(d.DictGen<int, string, double>(dict, 1.9) as string).Is("dict");
}

private class Person
{
public int Age { get; set; }
Expand Down Expand Up @@ -527,7 +491,7 @@ public void Exception()
[TestMethod]
public void IsNullMethodMessage()
{
object? o = new object();
var o = new object();
o.IsNotNull();
AssertEx.Throws<AssertFailedException>(
() => o.IsNull("msg_msg"))
Expand Down Expand Up @@ -639,7 +603,7 @@ public void StructuralEqualFailed()
object? n = null;
AssertEx.Throws<AssertFailedException>(() => n.IsStructuralEqual("a"));
AssertEx.Throws<AssertFailedException>(() => "a".IsStructuralEqual(n));
int i = 10;
var i = 10;
long l = 10;
AssertEx.Throws<AssertFailedException>(() => i.IsStructuralEqual(l));

Expand Down Expand Up @@ -768,7 +732,7 @@ public void NotStructuralEqualSuccess()
object? n = null;
n.IsNotStructuralEqual("a");
"a".IsNotStructuralEqual(n);
int i = 10;
var i = 10;
long l = 10;
i.IsNotStructuralEqual(l);

Expand Down
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>nullable</WarningsAsErrors>
<ImplicitUsings>enable</ImplicitUsings>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
<PackageReference Include="coverlet.collector" Version="3.1.2">
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.1.1" />
<PackageReference Include="MSTest.TestFramework" Version="3.1.1" />
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
67 changes: 20 additions & 47 deletions ChainingAssertion.NUnit.UnitTest/AssertExTest.cs
Expand Up @@ -95,7 +95,7 @@ public void TestCaseTest(int x, int y, int z)
}

[Test]
[TestCaseSource("toaruSource")]
[TestCaseSource(nameof(toaruSource))]
public void TestTestCaseSource(int x, int y, string z)
{
string.Concat(x, y).Is(z);
Expand Down Expand Up @@ -215,60 +215,27 @@ public void DynamicNullableTest()

public class GenericPrivateMock
{
private string PrivateGeneric<T1, T2>(T1 t1a, T2 t2a, T1 t1b)
{
return "a";
}
private string PrivateGeneric<T1, T2>(T1 t1a, T2 t2a, T1 t1b) => "a";

private string PrivateGeneric<T1, T2, T3>(T1 t1a, T2 t2a, T1 t1b)
{
return "b";
}
private string PrivateGeneric<T1, T2, T3>(T1 t1a, T2 t2a, T1 t1b) => "b";

private string PrivateGeneric<T1, T2>(T1 t1a, T2 t2a, int i)
{
return "c";
}
private string PrivateGeneric<T1, T2>(T1 t1a, T2 t2a, int i) => "c";

private string PrivateGeneric<T1, T2>(T1 t1a, T2 t2a, int i, T2 t2b)
{
return "d";
}
private string PrivateGeneric<T1, T2>(T1 t1a, T2 t2a, int i, T2 t2b) => "d";

private string PrivateGeneric(string t1a, string t2a, string t1b)
{
return "e";
}
private string PrivateGeneric(string t1a, string t2a, string t1b) => "e";

private string PrivateGeneric<T1, T2, T3>(T3 t3a, T2 t2, T1 t1, T3 t3b)
{
return "f";
}
private string PrivateGeneric<T1, T2, T3>(T3 t3a, T2 t2, T1 t1, T3 t3b) => "f";

private string PrivateGeneric<T>()
{
return "g";
}
private string PrivateGeneric<T>() => "g";

private string PrivateGeneric()
{
return "h";
}
private string PrivateGeneric() => "h";

private Type ReturnType<T>(T t1, T t2)
{
return typeof(T);
}
private Type ReturnType<T>(T t1, T t2) => typeof(T);

private Type ReturnType<T>(IEnumerable<T> t1, T t2)
{
return typeof(T);
}
private Type ReturnType<T>(IEnumerable<T> t1, T t2) => typeof(T);

private string DictGen<T1, T2, T3>(IDictionary<T1, IDictionary<T2, T3>> dict, T3 xxx)
{
return "dict";
}
private string DictGen<T1, T2, T3>(IDictionary<T1, IDictionary<T2, T3>> dict, T3 t) => "dict";
}

[Test]
Expand All @@ -288,12 +255,18 @@ public void GenericPrivateTest()
(d.PrivateGeneric<int, string, double>(0.0, "", 0, 0.0) as string).Is("f");
(d.PrivateGeneric<int>() as string).Is("g");
(d.PrivateGeneric() as string).Is("h");
(d.ReturnType(0, 0) as Type).Is(typeof(int));

(d.PrivateGeneric(0, "", 0) as string).Is("c");
(d.PrivateGeneric<int, string>(0, "", 0) as string).Is("c");
(d.PrivateGeneric(0, 0, 0) as string).Is("c");

(d.ReturnType(0, 0) as Type).Is(typeof(int));
(d.ReturnType(Enumerable.Range(1, 10), 0) as Type).Is(typeof(int));
(d.ReturnType<int>(Enumerable.Range(1, 10), 0) as Type).Is(typeof(int));
(d.ReturnType<IEnumerable<int>>(Enumerable.Range(1, 10), new List<int>()) as Type).Is(typeof(IEnumerable<int>));

var dict = new Dictionary<int, IDictionary<string, double>>();
(d.DictGen(dict, 1.9) as string).Is("dict");
(d.DictGen<int, string, double>(dict, 1.9) as string).Is("dict");
}

[Test]
Expand Down

0 comments on commit b284183

Please sign in to comment.