public async Task <Ticket> IssueNewTicket(string customer, int rateLevelId)
        {
            // Deny entry if the garage is full
            var ticketCount = await _context.Tickets.CountAsync();

            if (ticketCount >= _config.MaxParkingSpaces)
            {
                throw new LotFullException(_config.MaxParkingSpaces);
            }

            // Give a ticket
            var ticket = new Ticket
            {
                Customer    = customer,
                RateLevelId = rateLevelId
            };

            await _context.AddAsync(ticket);

            await _context.SaveChangesAsync();

            await _context.Entry(ticket).Reference(x => x.RateLevel).LoadAsync();

            return(ticket);
        }
示例#2
0
        public async Task ItCalculatesTheCorrectOwingAmount(DateTimeOffset issuedOn, TimeSpan rateDuration, decimal rateValue, decimal expectedTotal)
        {
            // arrange
            var config = new ParkingLotConfig {
                MaxParkingSpaces = 3
            };
            var ticketService = new TicketService(_context, config);
            var rateLevel     = new RateLevel
            {
                Name      = rateDuration.ToString(),
                Duration  = rateDuration,
                RateValue = rateValue
            };

            var ticket = new Ticket
            {
                Customer  = "Test Customer",
                RateLevel = rateLevel,
                IssuedOn  = issuedOn
            };

            await _context.AddAsync(ticket);

            await _context.SaveChangesAsync();

            // act
            var amountOwing = ticketService.GetAmountOwed(ticket);

            // assert
            Assert.Equal(expectedTotal, amountOwing);
        }
示例#3
0
        public async Task <int?> AddParkingLot(ParkingLotDto parkingLotDto)
        {
            if (parkingLotDto.Name == null || parkingLotDto.Location == null)
            {
                return(null);
            }

            ParkingLotEntity parkingLotEntity = new ParkingLotEntity(parkingLotDto);
            var addedParkingLot = await parkingLotDbContext.AddAsync(parkingLotEntity);

            await parkingLotDbContext.SaveChangesAsync();

            return(addedParkingLot.Entity.Id);
        }