public async Task WhenItemDoesNotExists_ShouldThrowKeyNotFoundException() { // Arrange var cabId = _fixture.Create <Id <Cab> >(); var dbContext = new DispatchingDbContextBuilder() .Build(); // Act using (dbContext) { var sut = new CabRepository(dbContext, _domainModelMapper, _persistenceModelMapper); Func <Task> act = async() => await sut.Get(cabId); // Assert act.Should().Throw <KeyNotFoundException>(); } }
public async Task WhenData_ShouldMapToDomainModel() { // Arrange var dbContext = new DispatchingDbContextBuilder(_fixture.Create <string>()) .WithCustomerLocation(_location) .WithCab(_nearestCabId, _distance) .Build(); // Act using (dbContext) { var sut = new CabRepository(dbContext, _domainModelMapper, _persistenceModelMapper); await sut.GetNearestAvailableCab(_location); // Assert _persistenceModelMapper .Received(1) .Map(Arg.Is(dbContext.Cabs.Single())); } }
public async Task WhenItemExists_ShouldMapEntityIntoDomainModel() { // Arrange var cab = _fixture.Create <PersistenceModel.Cab>(); var cabId = new Id <Cab>(cab.Id); var dbContext = new DispatchingDbContextBuilder() .WithCab(cab) .Build(); // Act using (dbContext) { var sut = new CabRepository(dbContext, _domainModelMapper, _persistenceModelMapper); await sut.Get(cabId); // Assert _persistenceModelMapper .Received(1) .Map(Arg.Is <PersistenceModel.Cab>(x => x.Id == cab.Id)); } }
public async Task WhenLocation_ShouldReturnNearestCab() { // Arrange var dbContext = new DispatchingDbContextBuilder() .WithCustomerLocation(_location) .WithCab(_nearestCabId, _distance) .WithCab(_fixture.Create <Guid>(), _distance + _fixture.Create <decimal>()) .Build(); // Act using (dbContext) { var sut = new CabRepository(dbContext, _domainModelMapper, _persistenceModelMapper); await sut.GetNearestAvailableCab(_location); // Assert _persistenceModelMapper .Received(1) .Map(Arg.Is <PersistenceModel.Cab>(x => x.Id == _nearestCabId)); } }
public async Task WhenLocation_ShouldReturnResultFromPersistenceModelMapper() { // Arrange var dbContext = new DispatchingDbContextBuilder() .WithCustomerLocation(_location) .WithCab(_nearestCabId, _distance) .Build(); var expected = _fixture.Create <Cab>(); _persistenceModelMapper .Map(Arg.Any <PersistenceModel.Cab>()) .Returns(expected); // Act using (dbContext) { var sut = new CabRepository(dbContext, _domainModelMapper, _persistenceModelMapper); var actual = await sut.GetNearestAvailableCab(_location); // Assert actual.Should().Be(expected); } }