diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0016f00..19d5e4a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: fail-fast: false matrix: os: [windows-latest, macOS-latest, ubuntu-latest] - dotnet: [7.0.100] + dotnet: [7.0.302] runs-on: ${{ matrix.os }} steps: diff --git a/src/NHamcrest.NUnit.Examples/NHamcrest.NUnit.Examples.csproj b/src/NHamcrest.NUnit.Examples/NHamcrest.NUnit.Examples.csproj index 968b984..e8346de 100644 --- a/src/NHamcrest.NUnit.Examples/NHamcrest.NUnit.Examples.csproj +++ b/src/NHamcrest.NUnit.Examples/NHamcrest.NUnit.Examples.csproj @@ -4,9 +4,9 @@ net7.0 - + - + diff --git a/src/NHamcrest.NUnit/AssertEx.cs b/src/NHamcrest.NUnit/AssertEx.cs index 1b1b724..fee462c 100644 --- a/src/NHamcrest.NUnit/AssertEx.cs +++ b/src/NHamcrest.NUnit/AssertEx.cs @@ -46,7 +46,7 @@ public static void That(T actual, IMatcher matcher, string message, params { if (matcher.Matches(actual)) return; - + var writer = new TextMessageWriter(message, args); WriteExpected(matcher, writer); @@ -67,7 +67,7 @@ private static void WriteExpected(ISelfDescribing matcher, TextWriter writer) private static void WriteActual(T actual, IMatcher matcher, TextWriter writer) { - writer.Write(" But "); + writer.Write(TextMessageWriter.Pfx_Actual); var mismatchDescription = new StringDescription(); matcher.DescribeMismatch(actual, mismatchDescription); writer.Write(mismatchDescription.ToString()); diff --git a/src/NHamcrest.NUnit/NHamcrest.NUnit.csproj b/src/NHamcrest.NUnit/NHamcrest.NUnit.csproj index d77a977..dcfb82b 100644 --- a/src/NHamcrest.NUnit/NHamcrest.NUnit.csproj +++ b/src/NHamcrest.NUnit/NHamcrest.NUnit.csproj @@ -4,18 +4,16 @@ netstandard2.0;net7.0 true False - Copyright © 2022 - 3.1.0 - 3.1.0-$(VersionSuffix) + Copyright © 2023 + 3.2.0 + 3.2.0-$(VersionSuffix) Adapter for NUnit for using NHamcrest library - Graham Hay, Algirdas Lašas - - + Graham Hay, Algirdas Lašas, Constantin Tews https://github.com/nhamcrest/NHamcrest/blob/master/LICENCE.txt https://github.com/nhamcrest/NHamcrest unittesting hamcrest matcher test - 3.1.0.0 - 3.1.0.0 + 3.2.0.0 + 3.2.0.0 diff --git a/src/NHamcrest.Tests/Core/IsEqualTests.cs b/src/NHamcrest.Tests/Core/IsEqualTests.cs index 34b4634..8fb7c71 100644 --- a/src/NHamcrest.Tests/Core/IsEqualTests.cs +++ b/src/NHamcrest.Tests/Core/IsEqualTests.cs @@ -1,4 +1,3 @@ - using NHamcrest.Core; using Xunit; using NHAssert = NHamcrest.Tests.Internal.Assert; @@ -43,7 +42,7 @@ public void Append_description() isEqual.DescribeTo(description); - Assert.Equal("\"" + test + "\"", description.ToString()); + Assert.Equal($"\"{test}\"", description.ToString()); } } } \ No newline at end of file diff --git a/src/NHamcrest.Tests/Core/IsExtensionsTests.cs b/src/NHamcrest.Tests/Core/IsExtensionsTests.cs new file mode 100644 index 0000000..ea2c524 --- /dev/null +++ b/src/NHamcrest.Tests/Core/IsExtensionsTests.cs @@ -0,0 +1,33 @@ +using Xunit; +using NHAssert = NHamcrest.Tests.Internal.Assert; +using static NHamcrest.Extensions.IsExtensions; + +namespace NHamcrest.Tests.Core +{ + public class IsExtensionsTests + { + [Fact] + public void Match_if_bool_is_equal_with_IsExtension() + { + NHAssert.That(true, Is(true)); + } + + [Fact] + public void Match_if_string_is_equal_with_IsExtension() + { + NHAssert.That("test", Is("test")); + } + + [Fact] + public void Match_if_int_is_equal_with_IsExtension() + { + NHAssert.That(1, Is(1)); + } + + [Fact] + public void Match_if_decimal_is_equal_with_IsExtension() + { + NHAssert.That(1m, Is(1m)); + } + } +} diff --git a/src/NHamcrest.Tests/NHamcrest.Tests.csproj b/src/NHamcrest.Tests/NHamcrest.Tests.csproj index 5a8fe50..5ba09a3 100644 --- a/src/NHamcrest.Tests/NHamcrest.Tests.csproj +++ b/src/NHamcrest.Tests/NHamcrest.Tests.csproj @@ -2,7 +2,7 @@ net7.0 - 3.1.0 + 3.2.0 @@ -14,9 +14,9 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - - + + + diff --git a/src/NHamcrest.XUnit.Examples/NHamcrest.XUnit.Examples.csproj b/src/NHamcrest.XUnit.Examples/NHamcrest.XUnit.Examples.csproj index 877a250..d08848b 100644 --- a/src/NHamcrest.XUnit.Examples/NHamcrest.XUnit.Examples.csproj +++ b/src/NHamcrest.XUnit.Examples/NHamcrest.XUnit.Examples.csproj @@ -4,7 +4,7 @@ net7.0 - + diff --git a/src/NHamcrest.XUnit/AssertEx.cs b/src/NHamcrest.XUnit/AssertEx.cs index 53d41c8..e18b78f 100644 --- a/src/NHamcrest.XUnit/AssertEx.cs +++ b/src/NHamcrest.XUnit/AssertEx.cs @@ -15,6 +15,32 @@ public class Assert : Xunit.Assert /// /// public static void That(T actual, IMatcher matcher) + { + That(actual, matcher, null); + } + + /// + /// Checks if actual matches in IMatcher. + /// + /// + /// + /// + /// + public static void That(T actual, IMatcher matcher, string message) + { + That(actual, matcher, message, null); + } + + /// + /// Checks if actual matches in IMatcher. + /// + /// + /// + /// + /// + /// + /// + public static void That(T actual, IMatcher matcher, string message, params object[] args) { if (matcher.Matches(actual)) return; @@ -25,7 +51,11 @@ public static void That(T actual, IMatcher matcher) var mismatchDescription = new StringDescription(); matcher.DescribeMismatch(actual, mismatchDescription); - throw new MatchException(description.ToString(), mismatchDescription.ToString(), null); + string userMessage = args != null && args.Length > 0 + ? string.Format(message, args) + : message; + + throw new MatchException(description.ToString(), mismatchDescription.ToString(), userMessage); } } -} +} \ No newline at end of file diff --git a/src/NHamcrest.XUnit/NHamcrest.XUnit.csproj b/src/NHamcrest.XUnit/NHamcrest.XUnit.csproj index 4813b76..59ce78b 100644 --- a/src/NHamcrest.XUnit/NHamcrest.XUnit.csproj +++ b/src/NHamcrest.XUnit/NHamcrest.XUnit.csproj @@ -4,16 +4,16 @@ netstandard2.0;net7.0 true False - Copyright © 2022 - 3.1.0 - 3.1.0-$(VersionSuffix) + Copyright © 2023 + 3.2.0 + 3.2.0-$(VersionSuffix) Adapter for xunit for using NHamcrest library - Graham Hay, Algirdas Lašas + Graham Hay, Algirdas Lašas, Constantin Tews https://github.com/nhamcrest/NHamcrest/blob/master/LICENCE.txt https://github.com/nhamcrest/NHamcrest unittesting hamcrest matcher test - 3.1.0.0 - 3.1.0.0 + 3.2.0.0 + 3.2.0.0 diff --git a/src/NHamcrest/Core/StructuralComparisonMatcher.cs b/src/NHamcrest/Core/StructuralComparisonMatcher.cs index b028937..73060e3 100644 --- a/src/NHamcrest/Core/StructuralComparisonMatcher.cs +++ b/src/NHamcrest/Core/StructuralComparisonMatcher.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; +using NHamcrest.Extensions; namespace NHamcrest.Core { diff --git a/src/NHamcrest/Extensions/IsExtensions.cs b/src/NHamcrest/Extensions/IsExtensions.cs new file mode 100644 index 0000000..487b231 --- /dev/null +++ b/src/NHamcrest/Extensions/IsExtensions.cs @@ -0,0 +1,10 @@ +namespace NHamcrest.Extensions +{ + public static class IsExtensions + { + public static IMatcher Is(T value) + { + return NHamcrest.Is.EqualTo(value); + } + } +} \ No newline at end of file diff --git a/src/NHamcrest/Core/TypeExtensions.cs b/src/NHamcrest/Extensions/TypeExtensions.cs similarity index 55% rename from src/NHamcrest/Core/TypeExtensions.cs rename to src/NHamcrest/Extensions/TypeExtensions.cs index e6b75e4..77c447c 100644 --- a/src/NHamcrest/Core/TypeExtensions.cs +++ b/src/NHamcrest/Extensions/TypeExtensions.cs @@ -2,25 +2,24 @@ using System.Linq; using System.Reflection; -namespace NHamcrest.Core +namespace NHamcrest.Extensions { internal static class TypeExtensions { - public static bool IsSimpleType( - this Type type) + public static bool IsSimpleType(this Type type) { return type.GetTypeInfo().IsValueType || type.GetTypeInfo().IsPrimitive || new[] { - typeof(String), - typeof(Decimal), - typeof(DateTime), - typeof(DateTimeOffset), - typeof(TimeSpan), - typeof(Guid) + typeof(string), + typeof(decimal), + typeof(DateTime), + typeof(DateTimeOffset), + typeof(TimeSpan), + typeof(Guid) }.Contains(type) || Convert.GetTypeCode(type) != TypeCode.Object; } } -} +} \ No newline at end of file diff --git a/src/NHamcrest/NHamcrest.csproj b/src/NHamcrest/NHamcrest.csproj index f26036d..9512c98 100644 --- a/src/NHamcrest/NHamcrest.csproj +++ b/src/NHamcrest/NHamcrest.csproj @@ -4,18 +4,16 @@ netstandard2.0;net7.0 true False - Copyright © 2022 - 3.1.0 - 3.1.0-$(VersionSuffix) + Copyright © 2023 + 3.2.0 + 3.2.0-$(VersionSuffix) .NET port of Hamcrest, a matcher library with some extra matchers - Graham Hay, Algirdas Lašas - - + Graham Hay, Algirdas Lašas, Constantin Tews https://github.com/nhamcrest/NHamcrest/blob/master/LICENCE.txt https://github.com/nhamcrest/NHamcrest unittesting hamcrest matcher test - 3.1.0.0 - 3.1.0.0 + 3.2.0.0 + 3.2.0.0 1701;1702;1705;1591 diff --git a/src/NHamcrest/app.config b/src/NHamcrest/app.config deleted file mode 100644 index df20690..0000000 --- a/src/NHamcrest/app.config +++ /dev/null @@ -1,3 +0,0 @@ - - -