diff --git a/.github/workflows/unit-tests-for-mstest.yml b/.github/workflows/unit-tests-for-mstest.yml index dc128e1..56d3b8d 100644 --- a/.github/workflows/unit-tests-for-mstest.yml +++ b/.github/workflows/unit-tests-for-mstest.yml @@ -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 diff --git a/.github/workflows/unit-tests-for-xunit.yml b/.github/workflows/unit-tests-for-xunit.yml index e618f34..4ab0c24 100644 --- a/.github/workflows/unit-tests-for-xunit.yml +++ b/.github/workflows/unit-tests-for-xunit.yml @@ -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 diff --git a/ChainingAssertion.MSTest.UnitTest/AssertExTest.cs b/ChainingAssertion.MSTest.UnitTest/AssertExTest.cs index 28dd261..b46e054 100644 --- a/ChainingAssertion.MSTest.UnitTest/AssertExTest.cs +++ b/ChainingAssertion.MSTest.UnitTest/AssertExTest.cs @@ -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 }"); @@ -219,74 +219,46 @@ public void DynamicNullableTest() { var d = new PrivateMock().AsDynamic(); - (d.NullableMethod((IEnumerable?)null) as string).Is("enumerable"); - (d.NullableMethod((List?)null) as string).Is("enumerable"); + AssertEx.Throws(() => { d.NullableMethod((IEnumerable?)null); }) + .IsNotNull() + .Message.StartsWith("\"NullableMethod\" ambiguous arguments") + .IsTrue(); + AssertEx.Throws(() => { d.NullableMethod((List?)null); }) + .IsNotNull() + .Message.StartsWith("\"NullableMethod\" ambiguous arguments") + .IsTrue(); (d.NullableMethod(Enumerable.Range(1, 10)) as string).Is("enumerable"); - (d.NullableMethod(new List().AsEnumerable()) as string).Is("enumerable"); - (d.NullableMethod(new List()) as string).Is("enumerable"); + (d.NullableMethod(new List().AsEnumerable()) as string).Is("list"); + (d.NullableMethod(new List()) as string).Is("list"); } public class GenericPrivateMock { - private string PrivateGeneric(T1 t1a, T2 t2a, T1 t1b) - { - return "a"; - } + private string PrivateGeneric(T1 t1a, T2 t2a, T1 t1b) => "a"; - private string PrivateGeneric(T1 t1a, T2 t2a, T1 t1b) - { - return "b"; - } + private string PrivateGeneric(T1 t1a, T2 t2a, T1 t1b) => "b"; - private string PrivateGeneric(T1 t1a, T2 t2a, int i) - { - return "c"; - } + private string PrivateGeneric(T1 t1a, T2 t2a, int i) => "c"; - private string PrivateGeneric(T1 t1a, T2 t2a, int i, T2 t2b) - { - return "d"; - } + private string PrivateGeneric(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(T3 t3a, T2 t2, T1 t1, T3 t3b) - { - return "f"; - } + private string PrivateGeneric(T3 t3a, T2 t2, T1 t1, T3 t3b) => "f"; - private string PrivateGeneric() - { - return "g"; - } + private string PrivateGeneric() => "g"; - private string PrivateGeneric() - { - return "h"; - } + private string PrivateGeneric() => "h"; - private Type ReturnType(T t1, T t2) - { - return typeof(T); - } + private Type ReturnType(T t1, T t2) => typeof(T); - private Type ReturnType(IEnumerable t1, T t2) - { - return typeof(T); - } + private Type ReturnType(IEnumerable t1, T t2) => typeof(T); - private string DictGen(IDictionary> dict, T3 xxx) - { - return "dict"; - } + private string DictGen(IDictionary> 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(); @@ -303,12 +275,18 @@ public void GenericPrivateTest() (d.PrivateGeneric(0.0, "", 0, 0.0) as string).Is("f"); (d.PrivateGeneric() 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(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(Enumerable.Range(1, 10), 0) as Type).Is(typeof(int)); (d.ReturnType>(Enumerable.Range(1, 10), new List()) as Type).Is(typeof(IEnumerable)); + + var dict = new Dictionary>(); + (d.DictGen(dict, 1.9) as string).Is("dict"); + (d.DictGen(dict, 1.9) as string).Is("dict"); } [TestMethod] @@ -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(Enumerable.Range(1, 10), 0) as Type).Is(typeof(int)); - - var dict = new Dictionary>(); - (d.DictGen(dict, 1.9) as string).Is("dict"); - (d.DictGen(dict, 1.9) as string).Is("dict"); - } - private class Person { public int Age { get; set; } @@ -527,7 +491,7 @@ public void Exception() [TestMethod] public void IsNullMethodMessage() { - object? o = new object(); + var o = new object(); o.IsNotNull(); AssertEx.Throws( () => o.IsNull("msg_msg")) @@ -639,7 +603,7 @@ public void StructuralEqualFailed() object? n = null; AssertEx.Throws(() => n.IsStructuralEqual("a")); AssertEx.Throws(() => "a".IsStructuralEqual(n)); - int i = 10; + var i = 10; long l = 10; AssertEx.Throws(() => i.IsStructuralEqual(l)); @@ -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); diff --git a/ChainingAssertion.MSTest.UnitTest/ChainingAssertion.MSTest.UnitTest.csproj b/ChainingAssertion.MSTest.UnitTest/ChainingAssertion.MSTest.UnitTest.csproj index c0f3696..beda8d0 100644 --- a/ChainingAssertion.MSTest.UnitTest/ChainingAssertion.MSTest.UnitTest.csproj +++ b/ChainingAssertion.MSTest.UnitTest/ChainingAssertion.MSTest.UnitTest.csproj @@ -1,7 +1,7 @@  - net6.0 + net6.0;net7.0;net8.0 enable nullable enable @@ -9,10 +9,10 @@ - - - - + + + + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/ChainingAssertion.NUnit.UnitTest/AssertExTest.cs b/ChainingAssertion.NUnit.UnitTest/AssertExTest.cs index 5eb7ecb..4973fe1 100644 --- a/ChainingAssertion.NUnit.UnitTest/AssertExTest.cs +++ b/ChainingAssertion.NUnit.UnitTest/AssertExTest.cs @@ -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); @@ -215,60 +215,27 @@ public void DynamicNullableTest() public class GenericPrivateMock { - private string PrivateGeneric(T1 t1a, T2 t2a, T1 t1b) - { - return "a"; - } + private string PrivateGeneric(T1 t1a, T2 t2a, T1 t1b) => "a"; - private string PrivateGeneric(T1 t1a, T2 t2a, T1 t1b) - { - return "b"; - } + private string PrivateGeneric(T1 t1a, T2 t2a, T1 t1b) => "b"; - private string PrivateGeneric(T1 t1a, T2 t2a, int i) - { - return "c"; - } + private string PrivateGeneric(T1 t1a, T2 t2a, int i) => "c"; - private string PrivateGeneric(T1 t1a, T2 t2a, int i, T2 t2b) - { - return "d"; - } + private string PrivateGeneric(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(T3 t3a, T2 t2, T1 t1, T3 t3b) - { - return "f"; - } + private string PrivateGeneric(T3 t3a, T2 t2, T1 t1, T3 t3b) => "f"; - private string PrivateGeneric() - { - return "g"; - } + private string PrivateGeneric() => "g"; - private string PrivateGeneric() - { - return "h"; - } + private string PrivateGeneric() => "h"; - private Type ReturnType(T t1, T t2) - { - return typeof(T); - } + private Type ReturnType(T t1, T t2) => typeof(T); - private Type ReturnType(IEnumerable t1, T t2) - { - return typeof(T); - } + private Type ReturnType(IEnumerable t1, T t2) => typeof(T); - private string DictGen(IDictionary> dict, T3 xxx) - { - return "dict"; - } + private string DictGen(IDictionary> dict, T3 t) => "dict"; } [Test] @@ -288,12 +255,18 @@ public void GenericPrivateTest() (d.PrivateGeneric(0.0, "", 0, 0.0) as string).Is("f"); (d.PrivateGeneric() 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(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(Enumerable.Range(1, 10), 0) as Type).Is(typeof(int)); (d.ReturnType>(Enumerable.Range(1, 10), new List()) as Type).Is(typeof(IEnumerable)); + + var dict = new Dictionary>(); + (d.DictGen(dict, 1.9) as string).Is("dict"); + (d.DictGen(dict, 1.9) as string).Is("dict"); } [Test] diff --git a/ChainingAssertion.xUnit.UnitTest/AssertExTest.cs b/ChainingAssertion.xUnit.UnitTest/AssertExTest.cs index d3a5bcf..882232c 100644 --- a/ChainingAssertion.xUnit.UnitTest/AssertExTest.cs +++ b/ChainingAssertion.xUnit.UnitTest/AssertExTest.cs @@ -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 }"); @@ -101,13 +101,13 @@ public void TestCaseTest(int x, int y, int z) } [Theory] - [MemberData("toaruSource")] + [MemberData(nameof(toaruSource))] public void TestTestCaseSource(int x, int y, string z) { string.Concat(x, y).Is(z); } - public static object[] toaruSource + public static IEnumerable toaruSource { get { @@ -211,74 +211,46 @@ public void DynamicNullableTest() { var d = new PrivateMock().AsDynamic(); - (d.NullableMethod((IEnumerable?)null) as string).Is("enumerable"); - (d.NullableMethod((List?)null) as string).Is("enumerable"); + Assert.Throws(() => { d.NullableMethod((IEnumerable?)null); }) + .IsNotNull() + .Message.StartsWith("\"NullableMethod\" ambiguous arguments") + .IsTrue(); + Assert.Throws(() => { d.NullableMethod((List?)null); }) + .IsNotNull() + .Message.StartsWith("\"NullableMethod\" ambiguous arguments") + .IsTrue(); (d.NullableMethod(Enumerable.Range(1, 10)) as string).Is("enumerable"); - (d.NullableMethod(new List().AsEnumerable()) as string).Is("enumerable"); - (d.NullableMethod(new List()) as string).Is("enumerable"); + (d.NullableMethod(new List().AsEnumerable()) as string).Is("list"); + (d.NullableMethod(new List()) as string).Is("list"); } public class GenericPrivateMock { - private string PrivateGeneric(T1 t1a, T2 t2a, T1 t1b) - { - return "a"; - } + private string PrivateGeneric(T1 t1a, T2 t2a, T1 t1b) => "a"; - private string PrivateGeneric(T1 t1a, T2 t2a, T1 t1b) - { - return "b"; - } + private string PrivateGeneric(T1 t1a, T2 t2a, T1 t1b) => "b"; - private string PrivateGeneric(T1 t1a, T2 t2a, int i) - { - return "c"; - } + private string PrivateGeneric(T1 t1a, T2 t2a, int i) => "c"; - private string PrivateGeneric(T1 t1a, T2 t2a, int i, T2 t2b) - { - return "d"; - } + private string PrivateGeneric(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(T3 t3a, T2 t2, T1 t1, T3 t3b) - { - return "f"; - } + private string PrivateGeneric(T3 t3a, T2 t2, T1 t1, T3 t3b) => "f"; - private string PrivateGeneric() - { - return "g"; - } + private string PrivateGeneric() => "g"; - private string PrivateGeneric() - { - return "h"; - } + private string PrivateGeneric() => "h"; - private Type ReturnType(T t1, T t2) - { - return typeof(T); - } + private Type ReturnType(T t1, T t2) => typeof(T); - private Type ReturnType(IEnumerable t1, T t2) - { - return typeof(T); - } + private Type ReturnType(IEnumerable t1, T t2) => typeof(T); - private string DictGen(IDictionary> dict, T3 xxx) - { - return "dict"; - } + private string DictGen(IDictionary> dict, T3 t) => "dict"; } - // Currently, this test is broken. It would be fixed in the future. - // [Fact] + [Fact] private void GenericPrivateTest() { var d = new GenericPrivateMock().AsDynamic(); @@ -295,12 +267,18 @@ private void GenericPrivateTest() (d.PrivateGeneric(0.0, "", 0, 0.0) as string).Is("f"); (d.PrivateGeneric() 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(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(Enumerable.Range(1, 10), 0) as Type).Is(typeof(int)); (d.ReturnType>(Enumerable.Range(1, 10), new List()) as Type).Is(typeof(IEnumerable)); + + var dict = new Dictionary>(); + (d.DictGen(dict, 1.9) as string).Is("dict"); + (d.DictGen(dict, 1.9) as string).Is("dict"); } [Fact] @@ -441,7 +419,7 @@ public void StructuralEqualFailed() object? n = null; Assert.Throws(() => n.IsStructuralEqual("a")); Assert.Throws(() => "a".IsStructuralEqual(n)); - int i = 10; + var i = 10; long l = 10; Assert.Throws(() => i.IsStructuralEqual(l)); @@ -570,7 +548,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); diff --git a/ChainingAssertion.xUnit.UnitTest/ChainingAssertion.xUnit.UnitTest.csproj b/ChainingAssertion.xUnit.UnitTest/ChainingAssertion.xUnit.UnitTest.csproj index 2092121..a91031b 100644 --- a/ChainingAssertion.xUnit.UnitTest/ChainingAssertion.xUnit.UnitTest.csproj +++ b/ChainingAssertion.xUnit.UnitTest/ChainingAssertion.xUnit.UnitTest.csproj @@ -1,20 +1,20 @@ - + - net6.0 + net6.0;net7.0;net8.0 enable nullable false - - - + + + runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all