Skip to content

Commit

Permalink
🧪 Switched Moq for NSubstitute (#90)
Browse files Browse the repository at this point in the history
Switched Moq for NSubstitute
  • Loading branch information
danielmackay authored Oct 14, 2023
1 parent 723087e commit f04a88f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
8 changes: 4 additions & 4 deletions Src/Infrastructure/Identity/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public ApplicationDbContext(
_operationalStoreOptions = operationalStoreOptions;
}

public DbSet<PersistedGrant> PersistedGrants { get; set; }
public DbSet<PersistedGrant> PersistedGrants { get; set; } = null!;

public DbSet<DeviceFlowCodes> DeviceFlowCodes { get; set; }
public DbSet<DeviceFlowCodes> DeviceFlowCodes { get; set; } = null!;

public DbSet<Key> Keys { get; set; }
public DbSet<Key> Keys { get; set; } = null!;

public DbSet<ServerSideSession> ServerSideSessions { get; set; }
public DbSet<ServerSideSession> ServerSideSessions { get; set; } = null!;

Task<int> IPersistedGrantDbContext.SaveChangesAsync() => base.SaveChangesAsync();

Expand Down
1 change: 0 additions & 1 deletion Tests/Application.UnitTests/Application.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.5" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="NSubstitute" Version="5.0.0" />
<PackageReference Include="Shouldly" Version="4.1.0" />
<PackageReference Include="xunit" Version="2.4.2" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using AutoFixture;
using MediatR;
using Moq;
using Northwind.Application.Customers.Commands.CreateCustomer;
using Northwind.Application.UnitTests.Common;
using Northwind.Domain.Customers;
using NSubstitute;
using Xunit;

namespace Northwind.Application.UnitTests.Customers.Commands.CreateCustomer;
Expand All @@ -14,8 +14,8 @@ public class CreateCustomerCommandTests : CommandTestBase
public void Handle_GivenValidRequest_ShouldRaiseCustomerCreatedNotification()
{
// Arrange
var mediatorMock = new Mock<IMediator>();
var sut = new CreateCustomerCommandHandler(_context, mediatorMock.Object);
var mediatorMock = Substitute.For<IMediator>();
var sut = new CreateCustomerCommandHandler(_context, mediatorMock);
var newCustomerId = new CustomerId("123");

var fixture = new Fixture();
Expand All @@ -29,8 +29,7 @@ public void Handle_GivenValidRequest_ShouldRaiseCustomerCreatedNotification()
var result = sut.Handle(command, CancellationToken.None);

// Assert
mediatorMock.Verify(
m => m.Publish(It.Is<CustomerCreated>(cc => cc.CustomerId == newCustomerId), It.IsAny<CancellationToken>()),
Times.Once);
mediatorMock.Received()
.Publish(Arg.Is<CustomerCreated>(cc => cc.CustomerId == newCustomerId), Arg.Any<CancellationToken>());
}
}

0 comments on commit f04a88f

Please sign in to comment.