public async Task WhenUtrechtCentraalExists_ShouldReturnWhateverTheMapperReturns()
        {
            // Arrange
            var location = _fixture.Create <PersistenceModel.Location>();

            location.Name = "Utrecht Centraal";

            var expected = _fixture.Create <Location>();

            _persistenceModelMapper
            .Map(Arg.Any <PersistenceModel.Location>())
            .Returns(expected);

            using (_context)
            {
                _context.Locations.Add(location);
                _context.SaveChanges();

                // Act
                var sut    = new LocationRepository(_context, _persistenceModelMapper);
                var actual = await sut.GetTrainStationLocation();

                // Assert
                actual.Should().Be(expected);
            }
        }
Exemplo n.º 2
0
        public async Task <TDomainModel> Get(Id <TDomainModel> id)
        {
            var data = await Get(id.ToGuid());

            if (data == null)
            {
                throw new KeyNotFoundException($"Cannot find {typeof(TDomainModel).FullName} with id {id}.");
            }

            return(_persistenceModelMapper.Map(data));
        }
        public async Task <Location> GetTrainStationLocation()
        {
            const string trainStationName = "Utrecht Centraal";

            try
            {
                var location = await _context.Locations
                               .Where(x => x.Name == trainStationName)
                               .SingleAsync();

                return(_persistenceModelMapper.Map(location));
            }
            catch (InvalidOperationException e)
            {
                throw new KeyNotFoundException($"Database should contain a record in the Locations table with name '{trainStationName}'.", e);
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        public async Task <Cab> GetNearestAvailableCab(Location location)
        {
            var query = from c in _context.Cabs
                        join d in _context.Distances
                        on new {
                FromLong = c.Longitude,
                FromLat  = c.Latitude,
                ToLong   = location.Longitude,
                ToLat    = location.Latitude
            }
            equals new
            {
                FromLong = d.FromLongitude,
                FromLat  = d.FromLatitude,
                ToLong   = d.ToLongitude,
                ToLat    = d.ToLatitude
            }
            orderby d.Kilometers ascending
            select c;

            var cab = await query.FirstAsync();

            return(_persistenceModelMapper.Map(cab));
        }