Skip to content

Commit

Permalink
Add NUnit.Analyzers (#229)
Browse files Browse the repository at this point in the history
+semver:patch
  • Loading branch information
hazzik authored May 3, 2024
1 parent cb880f3 commit d75c41f
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<ItemGroup>
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0" PrivateAssets="all" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static void CompareAndLogList<T>(this MethodEnvironment env, IList<T> lin

try
{
CollectionAssert.AreEqual(linqResult, ddResult);
Assert.That(ddResult, Is.EqualTo(linqResult).AsCollection);
}
catch (Exception)
{
Expand All @@ -37,7 +37,7 @@ public static void CompareAndLogNonGenericList(this MethodEnvironment env, IList

try
{
CollectionAssert.AreEqual(linqResult, ddResult);
Assert.That(ddResult, Is.EqualTo(linqResult).AsCollection);
}
catch (Exception)
{
Expand All @@ -55,7 +55,7 @@ public static void CompareAndLogSingleton<T>(this MethodEnvironment env, T linqR

try
{
Assert.AreEqual(linqResult, ddResult);
Assert.That(ddResult, Is.EqualTo(linqResult));
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,21 @@
// Contributed by @JonPSmith (GitHub) www.thereformedprogrammer.com

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using NUnit.Framework;
using NUnit.Framework.Constraints;

namespace DelegateDecompiler.EntityFramework.Tests.Helpers
{
internal static class ExtendAsserts
{


internal static void ShouldEqual(this string actualValue, string expectedValue, string errorMessage = null)
{
Assert.AreEqual(expectedValue, actualValue, errorMessage);
Assert.That(actualValue, Is.EqualTo(expectedValue), errorMessage);
}

internal static void ShouldStartWith(this string actualValue, string expectedValue, string errorMessage = null)
{
StringAssert.StartsWith(expectedValue, actualValue, errorMessage);
}

internal static void ShouldEndWith(this string actualValue, string expectedValue, string errorMessage = null)
{
StringAssert.EndsWith(expectedValue, actualValue, errorMessage);
Assert.That(actualValue, Does.StartWith(expectedValue), errorMessage);
}

internal static void ShouldContain(this string actualValue, string expectedValue, string errorMessage = null)
Expand All @@ -36,64 +26,14 @@ internal static void ShouldContain(this string actualValue, string expectedValue
Assert.That(actualValue, constraint, errorMessage);
}

internal static void ShouldNotEqual(this string actualValue, string expectedValue, string errorMessage = null)
{
Assert.True(expectedValue != actualValue, errorMessage);
}

internal static void ShouldEqualWithTolerance(this float actualValue, double expectedValue, double tolerance, string errorMessage = null)
{
Assert.AreEqual(expectedValue, actualValue, tolerance, errorMessage);
}

internal static void ShouldEqualWithTolerance(this long actualValue, long expectedValue, int tolerance, string errorMessage = null)
{
Assert.AreEqual(expectedValue, actualValue, tolerance, errorMessage);
}

internal static void ShouldEqualWithTolerance(this double actualValue, double expectedValue, double tolerance, string errorMessage = null)
{
Assert.AreEqual(expectedValue, actualValue, tolerance, errorMessage);
}

internal static void ShouldEqualWithTolerance(this int actualValue, int expectedValue, int tolerance, string errorMessage = null)
{
Assert.AreEqual(expectedValue, actualValue, tolerance, errorMessage);
}

internal static void ShouldEqual<T>(this T actualValue, T expectedValue, string errorMessage = null)
{
Assert.AreEqual(expectedValue, actualValue, errorMessage);
}

internal static void ShouldEqual<T>(this T actualValue, T expectedValue, IEnumerable<string> errorMessages)
{
Assert.AreEqual(expectedValue, actualValue, string.Join("\n", errorMessages));
}

internal static void ShouldEqual<T>(this T actualValue, T expectedValue, IEnumerable<ValidationResult> validationResults)
{
Assert.AreEqual(expectedValue, actualValue, string.Join("\n", validationResults.Select(x => x.ErrorMessage)));
}

internal static void ShouldNotEqual<T>(this T actualValue, T unexpectedValue, string errorMessage = null)
{
Assert.AreNotEqual(unexpectedValue, actualValue);
}

internal static void ShouldNotEqualNull<T>(this T actualValue, string errorMessage = null) where T : class
{
Assert.NotNull(actualValue);
Assert.That(actualValue, Is.EqualTo(expectedValue), errorMessage);
}

internal static void ShouldBeGreaterThan(this int actualValue, int greaterThanThis, string errorMessage = null)
{
Assert.Greater(actualValue, greaterThanThis);
}

internal static void IsA<T>(this object actualValue, string errorMessage = null) where T : class
{
Assert.True(actualValue.GetType() == typeof(T), "expected type {0}, but was of type {1}", typeof(T).Name, actualValue.GetType().Name);
Assert.That(actualValue, Is.GreaterThan(greaterThanThis), errorMessage);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.14" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0" PrivateAssets="all" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.30" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0" PrivateAssets="all" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.10" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0" PrivateAssets="all" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.1" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0" PrivateAssets="all" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="8.0.0" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0" PrivateAssets="all" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/DelegateDecompiler.Tests/ConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void ShouldBeAbleToConfigure()
var configuration = new DefaultConfiguration();
Configuration.Configure(configuration);
var configured = Configuration.Instance;
Assert.AreSame(configuration, configured);
Assert.That(configured, Is.SameAs(configuration));
}
}
}
12 changes: 6 additions & 6 deletions src/DelegateDecompiler.Tests/DecompilerTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ protected static void Test<T>(Expression<T> expected, T compiled)
Console.WriteLine(x);
var y = decompiled.Body.ToString();
Console.WriteLine(y);
Assert.AreEqual(x, y);
Assert.AreEqual(DebugView(expected.Body), DebugView(decompiled.Body));
Assert.That(y, Is.EqualTo(x));
Assert.That(DebugView(decompiled.Body), Is.EqualTo(DebugView(expected.Body)));
}

protected static void Test<T>(Expression<T> expected, MethodInfo compiled)
Expand All @@ -37,8 +37,8 @@ protected static void Test<T>(Expression<T> expected, MethodInfo compiled)
Console.WriteLine(x);
var y = decompiled.Body.ToString();
Console.WriteLine(y);
Assert.AreEqual(x, y);
Assert.AreEqual(DebugView(expected.Body), DebugView(decompiled.Body));
Assert.That(y, Is.EqualTo(x));
Assert.That(DebugView(decompiled.Body), Is.EqualTo(DebugView(expected.Body)));
}

protected static void Test<T>(Expression<T> expected1, Expression<T> expected2, T compiled, bool compareDebugView = true)
Expand All @@ -59,9 +59,9 @@ protected static void Test<T>(Expression<T> expected1, Expression<T> expected2,

protected static void AssertAreEqual(Expression expected, Expression actual, bool compareDebugView = true)
{
Assert.AreEqual(expected.ToString(), actual.ToString());
Assert.That(actual.ToString(), Is.EqualTo(expected.ToString()));
if (compareDebugView)
Assert.AreEqual(DebugView(expected), DebugView(actual));
Assert.That(DebugView(actual), Is.EqualTo(DebugView(expected)));
}

protected static void AssertAreEqual(Expression expected1, Expression expected2, Expression actual, bool compareDebugView = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.2" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0" PrivateAssets="all" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
</ItemGroup>

Expand Down

0 comments on commit d75c41f

Please sign in to comment.