Skip to content

Commit

Permalink
test(deps): replace Moq with NSubstitute
Browse files Browse the repository at this point in the history
  • Loading branch information
skwasjer committed Aug 26, 2023
1 parent f162700 commit d5f66a5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
27 changes: 13 additions & 14 deletions test/Correlate.Core.Tests/CorrelationManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CorrelationManagerTests : IDisposable
{
private const string GeneratedCorrelationId = "generated-correlation-id";
private readonly CorrelationContextAccessor _correlationContextAccessor;
private readonly Mock<ICorrelationIdFactory> _correlationIdFactoryMock;
private readonly ICorrelationIdFactory _correlationIdFactoryMock;
private readonly ILogger<CorrelationManager> _logger;
private readonly SerilogLoggerProvider _logProvider;
private readonly CorrelationManager _sut;
Expand All @@ -22,11 +22,10 @@ protected CorrelationManagerTests()
{
_correlationContextAccessor = new CorrelationContextAccessor();

_correlationIdFactoryMock = new Mock<ICorrelationIdFactory>();
_correlationIdFactoryMock = Substitute.For<ICorrelationIdFactory>();
_correlationIdFactoryMock
.Setup(m => m.Create())
.Returns(() => GeneratedCorrelationId)
.Verifiable();
.Create()
.Returns(GeneratedCorrelationId);

Logger serilogLogger = new LoggerConfiguration()
.WriteTo.TestCorrelator()
Expand All @@ -37,7 +36,7 @@ protected CorrelationManagerTests()

_sut = new CorrelationManager(
new CorrelationContextFactory(_correlationContextAccessor),
_correlationIdFactoryMock.Object,
_correlationIdFactoryMock,
_correlationContextAccessor,
_logger
);
Expand Down Expand Up @@ -269,7 +268,7 @@ public async Task When_running_correlated_task_with_correlation_id_should_use_it
return Task.CompletedTask;
});

_correlationIdFactoryMock.Verify(m => m.Create(), Times.Never);
_correlationIdFactoryMock.DidNotReceive().Create();
}

[Fact]
Expand All @@ -283,7 +282,7 @@ public async Task When_running_correlated_task_without_correlation_id_should_use
return Task.CompletedTask;
});

_correlationIdFactoryMock.Verify();
_correlationIdFactoryMock.Received(1).Create();
}

[Fact]
Expand Down Expand Up @@ -576,7 +575,7 @@ public void When_running_correlated_action_with_correlation_id_should_use_it()
_correlationContextAccessor.CorrelationContext?.CorrelationId.Should().Be(correlationId);
});

_correlationIdFactoryMock.Verify(m => m.Create(), Times.Never);
_correlationIdFactoryMock.DidNotReceive().Create();
}

[Fact]
Expand All @@ -589,7 +588,7 @@ public void When_running_correlated_action_without_correlation_id_should_use_gen
_correlationContextAccessor.CorrelationContext?.CorrelationId.Should().Be(GeneratedCorrelationId);
});

_correlationIdFactoryMock.Verify();
_correlationIdFactoryMock.Received(1).Create();
}

[Fact]
Expand Down Expand Up @@ -672,10 +671,10 @@ public void Given_null_argument_when_executing_it_should_throw(params object[] a
public static IEnumerable<object[]> NullArgumentTestCases()
{
var instance = new CorrelationManager(
Mock.Of<ICorrelationContextFactory>(),
Mock.Of<ICorrelationIdFactory>(),
Mock.Of<ICorrelationContextAccessor>(),
Mock.Of<ILogger<CorrelationManager>>()
Substitute.For<ICorrelationContextFactory>(),
Substitute.For<ICorrelationIdFactory>(),
Substitute.For<ICorrelationContextAccessor>(),
Substitute.For<ILogger<CorrelationManager>>()
);

static Task CorrelatedTask()
Expand Down
4 changes: 2 additions & 2 deletions test/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

<ItemGroup>
<Using Include="FluentAssertions" />
<Using Include="Moq" />
<Using Include="NSubstitute" />
<Using Include="Xunit" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="Moq" Version="[4.18.2]" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="xunit" Version="2.4.2" />
</ItemGroup>

Expand Down

0 comments on commit d5f66a5

Please sign in to comment.