Пример #1
0
        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 ItIssuesATicketIfThereIsASpace()
        {
            // arrange
            var config = new ParkingLotConfig {
                MaxParkingSpaces = 3
            };
            var ticketService = new TicketService(_context, config);
            var rateLevel     = new RateLevel
            {
                Name      = "Test Rate",
                RateValue = 1.25M
            };

            var tickets = new[]
            {
                new Ticket {
                    Customer = "Test Customer 1", RateLevel = rateLevel
                },
                new Ticket {
                    Customer = "Test Customer 2", RateLevel = rateLevel
                }
            };

            await _context.Tickets.AddRangeAsync(tickets);

            await _context.SaveChangesAsync();

            // act
            var newTicket = await ticketService.IssueNewTicket("cust", rateLevel.Id);

            // assert
            Assert.NotNull(newTicket);
            Assert.Equal("cust", newTicket.Customer);
        }
Пример #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);
        }