示例#1
0
        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>();
            }
        }
示例#2
0
        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()));
            }
        }
示例#3
0
        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));
            }
        }
示例#4
0
        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));
            }
        }
示例#5
0
        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);
            }
        }