public void Test6() //null
        {
            //Arrange

            TicketPL ticket = null;

            //Act
            Action act = () => serviceMock.Object.PutTicket(ticket);

            //Assert
            Assert.Throws <BL.Infrastructure.ValidationException>(act);
        }
        public void PutTicket(TicketPL ticket)
        {
            if (ticket == null || ticket.Id == 0 || ticket.FlightForeignKey == 0 || ticket.Price == 0)
            {
                throw new ValidationException($"Incorrect input values", "");
            }

            if (GetTicketsFromDS().FirstOrDefault(t => t.Id == ticket.Id) == null)
            {
                throw new ValidationException($"There is no ticket with id {ticket.Id}", "");
            }
            UOW.Set <Ticket>().Update(MapTicket(ticket, mapper));
            UOW.SaveChages();
        }
        public void Test3()
        {
            // Arrange
            var ticketPL = new TicketPL()
            {
                FlightForeignKey = 3, Price = 50, Id = 1
            };

            // Act
            var result = serviceTicket.MapTicket(ticketPL, mapper);

            // Assert
            Assert.Equal(ticketPL.Id, result.Id);
            Assert.Equal(ticketPL.Price, result.Price);
            Assert.Equal(ticketPL.FlightForeignKey, result.FlightForeignKey);
        }
        public void PostTicket(TicketPL ticket)
        {
            if (ticket == null || ticket.FlightForeignKey == 0 || ticket.Price == 0 || ticket.Id != 0)
            {
                throw new ValidationException($"Incorrect input values", "");
            }

            var fl = GetFlightsFromDS();

            if (fl.FirstOrDefault(f => f.Id == ticket.FlightForeignKey) == null)
            {
                throw new ValidationException($"There is no Flight with id {ticket.FlightForeignKey}", "");
            }

            UOW.Set <Ticket>().Create(MapTicket(ticket, mapper));
            UOW.SaveChages();
        }
Exemple #5
0
        public void Test2Update()
        {
            // Arrange
            var ticketPL = new TicketPL()
            {
                Id = 2, FlightForeignKey = 1, Price = 500
            };

            // Act
            serviceTicket.PutTicket(ticketPL);
            var num       = serviceTicket.GetFlightsFromDS().FirstOrDefault(f => f.Id == ticketPL.FlightForeignKey).Number;
            var ticketDto = serviceTicket.GetTickets().FirstOrDefault(t => t.Id == ticketPL.Id);

            // Assert
            Assert.Equal(ticketPL.Id, ticketDto.Id);
            Assert.Equal(num, ticketDto.FlightNumber);
            Assert.Equal(ticketPL.Price, ticketDto.Price);
        }
Exemple #6
0
        public void Test1Create()
        {
            // Arrange
            var ticketPL = new TicketPL()
            {
                FlightForeignKey = 3, Price = 50
            };

            // Act
            serviceTicket.PostTicket(ticketPL);

            var num       = serviceTicket.GetFlightsFromDS().FirstOrDefault(f => f.Id == ticketPL.FlightForeignKey).Number;
            var ticketDto = serviceTicket.GetTickets().OrderByDescending(t => t.Id).First();

            // Assert

            Assert.Equal(num, ticketDto.FlightNumber);
            Assert.Equal(ticketPL.Price, ticketDto.Price);
        }
        public void Test7(int fk, decimal pr, int id)  //Put
        {
            //Arrange

            var ticket = new TicketPL {
                FlightForeignKey = fk, Price = pr
            };

            if (id != 0)
            {
                ticket.Id = id;
            }

            serviceMock.Setup(serv => serv.GetFlightsFromDS()).Returns(flights);

            //Act
            Action act = () => serviceMock.Object.PutTicket(ticket);

            //Assert
            Assert.Throws <BL.Infrastructure.ValidationException>(act);
        }
Exemple #8
0
 public void Put(int id, [FromBody] TicketPL ticket)
 {
     ticket.Id = id;
     _serviceTicket.PutTicket(ticket);
 }
Exemple #9
0
 public void Post([FromBody] TicketPL ticket)
 {
     _serviceTicket.PostTicket(ticket);
 }
 public Ticket MapTicket(TicketPL ticket, IMapper mapper)
 {
     return(mapper.Map <Ticket>(ticket));
 }