public void DeleteFlight_ShouldRemoveDataFromDatabase_Successfuly()
        {
            //Arrange
            var data = ExactOrAllflights.AsQueryable();

            var ReservData = reservations1.AsQueryable();

            var mockSet = new Mock <DbSet <Flight> >();

            mockSet.As <IQueryable <Flight> >().Setup(m => m.Provider).Returns(data.Provider);
            mockSet.As <IQueryable <Flight> >().Setup(m => m.Expression).Returns(data.Expression);
            mockSet.As <IQueryable <Flight> >().Setup(m => m.ElementType).Returns(data.ElementType);
            mockSet.As <IQueryable <Flight> >().Setup(m => m.GetEnumerator()).Returns(() => data.GetEnumerator());

            var mockSetReservations = new Mock <DbSet <Reservation> >();

            mockSetReservations.As <IQueryable <Reservation> >().Setup(m => m.Provider).Returns(ReservData.Provider);
            mockSetReservations.As <IQueryable <Reservation> >().Setup(m => m.Expression).Returns(ReservData.Expression);
            mockSetReservations.As <IQueryable <Reservation> >().Setup(m => m.ElementType).Returns(ReservData.ElementType);
            mockSetReservations.As <IQueryable <Reservation> >().Setup(m => m.GetEnumerator()).Returns(() => ReservData.GetEnumerator());

            var mockContext = new Mock <FlightManagerDbContext>();

            mockContext.Setup(x => x.Flights).Returns(mockSet.Object);
            mockContext.Setup(x => x.Reservations).Returns(mockSetReservations.Object);
            var PlaneIdToDelete = data.FirstOrDefault(x => x.UniquePlaneNumber == ExactOrAllflights[0].UniquePlaneNumber).UniquePlaneNumber;

            //Act
            var service = new FlightService(mockContext.Object);

            service.DeleteFlight(PlaneIdToDelete);

            //Assert
            mockContext.Verify(x => x.SaveChanges(), Times.Once());
        }
        public IActionResult DeleteConfirmed(int id)
        {
            var flight = _flightService.GetFlightByCondition(b => b.FlightID == id).FirstOrDefault();

            _flightService.DeleteFlight(flight);
            _flightService.Save();
            return(RedirectToAction(nameof(Index)));
        }
Ejemplo n.º 3
0
        public async Task <IHttpActionResult> DeleteFlight(int id)
        {
            await FlightService.DeleteFlight(id);

            return(Ok());
        }