Skip to content

Commit

Permalink
Repalce Moq to NSubstitute
Browse files Browse the repository at this point in the history
  • Loading branch information
Romfos committed Nov 18, 2023
1 parent a3a36e2 commit 7489642
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
18 changes: 9 additions & 9 deletions src/TestFixture.Tests/Services/TestFixtureBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Moq;
using NSubstitute;
using System;
using System.Collections.Generic;
using TestFixture.Services;
Expand All @@ -7,54 +7,54 @@ namespace TestFixture.Tests.Services;

internal sealed class TestFixtureBuilder
{
private readonly Mock<IRandomService> mock = new();
private readonly IRandomService substitute = Substitute.For<IRandomService>();

public TestFixtureBuilder With(params int[] values)
{
var queue = new Queue<int>(values);
mock.SetupGet(x => x.Int32).Returns(queue.Dequeue);
substitute.Int32.Returns(x => queue.Dequeue());
return this;
}

public TestFixtureBuilder With(params double[] values)
{
var queue = new Queue<double>(values);
mock.SetupGet(x => x.Double).Returns(queue.Dequeue);
substitute.Double.Returns(x => queue.Dequeue());
return this;
}

public TestFixtureBuilder With(params Guid[] values)
{
var queue = new Queue<Guid>(values);
mock.SetupGet(x => x.Guid).Returns(queue.Dequeue);
substitute.Guid.Returns(x => queue.Dequeue());
return this;
}

public TestFixtureBuilder With(params string[] values)
{
var queue = new Queue<string>(values);
mock.SetupGet(x => x.String).Returns(queue.Dequeue);
substitute.String.Returns(x => queue.Dequeue());
return this;
}

public TestFixtureBuilder With(params long[] values)
{
var queue = new Queue<long>(values);
mock.SetupGet(x => x.Int64).Returns(queue.Dequeue);
substitute.Int64.Returns(x => queue.Dequeue());
return this;
}

public TestFixtureBuilder With(params DateTime[] values)
{
var queue = new Queue<DateTime>(values);
mock.SetupGet(x => x.DateTime).Returns(queue.Dequeue);
substitute.DateTime.Returns(x => queue.Dequeue());
return this;
}

public Fixture Build()
{
var fixture = new Fixture();
fixture.RegisterInstance(mock.Object);
fixture.RegisterInstance(substitute);
return fixture;
}
}
2 changes: 1 addition & 1 deletion src/TestFixture.Tests/TestFixture.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.0" />
<PackageReference Include="MSTest" Version="3.1.1" />
<PackageReference Include="Moq" Version="4.20.69" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
</ItemGroup>

Expand Down

0 comments on commit 7489642

Please sign in to comment.