Skip to content

Commit

Permalink
Replace Moq with NSubstitute
Browse files Browse the repository at this point in the history
  • Loading branch information
christophwille committed Aug 16, 2023
1 parent a0ba223 commit 7c8b497
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
24 changes: 12 additions & 12 deletions ILSpy.Tests/Analyzers/MemberImplementsInterfaceAnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
using ICSharpCode.ILSpy.Analyzers;
using ICSharpCode.ILSpy.Analyzers.Builtin;

using Moq;
using NSubstitute;

using NUnit.Framework;

Expand Down Expand Up @@ -77,12 +77,12 @@ public void VerifyDoesNotShowForNoSymbol()
public void VerifyDoesNotShowForNonMembers(SymbolKind symbolKind)
{
// Arrange
var symbolMock = new Mock<ISymbol>();
symbolMock.Setup(s => s.SymbolKind).Returns(symbolKind);
var symbolMock = Substitute.For<ISymbol>();
symbolMock.SymbolKind.Returns(symbolKind);
var analyzer = new MemberImplementsInterfaceAnalyzer();

// Act
var shouldShow = analyzer.Show(symbolMock.Object);
var shouldShow = analyzer.Show(symbolMock);

// Assert
Assert.IsFalse(shouldShow, $"The analyzer will be unexpectedly shown for symbol '{symbolKind}'");
Expand All @@ -97,7 +97,7 @@ public void VerifyDoesNotShowForStaticMembers(SymbolKind symbolKind)
var analyzer = new MemberImplementsInterfaceAnalyzer();

// Act
var shouldShow = analyzer.Show(memberMock.Object);
var shouldShow = analyzer.Show(memberMock);

// Assert
Assert.IsFalse(shouldShow, $"The analyzer will be unexpectedly shown for static symbol '{symbolKind}'");
Expand All @@ -114,7 +114,7 @@ public void VerifyDoesNotShowForUnsupportedTypes(
var analyzer = new MemberImplementsInterfaceAnalyzer();

// Act
var shouldShow = analyzer.Show(memberMock.Object);
var shouldShow = analyzer.Show(memberMock);

// Assert
Assert.IsFalse(shouldShow, $"The analyzer will be unexpectedly shown for symbol '{symbolKind}' and '{typeKind}'");
Expand All @@ -131,7 +131,7 @@ public void VerifyShowsForSupportedTypes(
var analyzer = new MemberImplementsInterfaceAnalyzer();

// Act
var shouldShow = analyzer.Show(memberMock.Object);
var shouldShow = analyzer.Show(memberMock);

// Assert
Assert.IsTrue(shouldShow, $"The analyzer will not be shown for symbol '{symbolKind}' and '{typeKind}'");
Expand Down Expand Up @@ -163,12 +163,12 @@ private ISymbol SetupSymbolForAnalysis(Type type, string methodName)
return typeDefinition.Methods.First(m => m.Name == methodName);
}

private static Mock<IMember> SetupMemberMock(SymbolKind symbolKind, TypeKind typeKind, bool isStatic)
private static IMember SetupMemberMock(SymbolKind symbolKind, TypeKind typeKind, bool isStatic)
{
var memberMock = new Mock<IMember>();
memberMock.Setup(m => m.SymbolKind).Returns(symbolKind);
memberMock.Setup(m => m.DeclaringTypeDefinition.Kind).Returns(typeKind);
memberMock.Setup(m => m.IsStatic).Returns(isStatic);
var memberMock = Substitute.For<IMember>();
memberMock.SymbolKind.Returns(symbolKind);
memberMock.DeclaringTypeDefinition.Kind.Returns(typeKind);
memberMock.IsStatic.Returns(isStatic);
return memberMock;
}

Expand Down
6 changes: 5 additions & 1 deletion ILSpy.Tests/ILSpy.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@

<ItemGroup>
<PackageReference Include="DiffLib" Version="$(DiffLibVersion)" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="NSubstitute.Analyzers.CSharp" Version="1.0.16">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Collections.Immutable" Version="$(SystemCollectionsImmutableVersion)" />
<PackageReference Include="System.Reflection.Metadata" Version="$(SystemReflectionMetadataVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="$(RoslynVersion)" />
Expand All @@ -54,7 +59,6 @@
<PackageReference Include="NUnit" Version="$(NUnitVersion)" />
<!-- used for xml test result files -->
<PackageReference Include="JunitXml.TestLogger" Version="$(JUnitXmlTestLoggerVersion)" />
<PackageReference Include="Moq" Version="$(MoqVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<JUnitXmlTestLoggerVersion>3.0.124</JUnitXmlTestLoggerVersion>
<CoverletCollectorVersion>3.2.0</CoverletCollectorVersion>
<MicrosoftNETTestSdkVersion>17.5.0</MicrosoftNETTestSdkVersion>
<MoqVersion>4.18.4</MoqVersion>
<DiffLibVersion>2017.7.26.1241</DiffLibVersion>
<!-- Microsoft.CodeAnalysis.* -->
<RoslynVersion>4.6.0</RoslynVersion>
Expand Down

0 comments on commit 7c8b497

Please sign in to comment.