public void UpdateFlight_SuccessfulyChangedDatainDatabase()
        {
            //Arrange
            var data = ExactOrAllflights.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 mockContext = new Mock <FlightManagerDbContext>();

            mockContext.Setup(x => x.Flights).Returns(mockSet.Object);


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

            service.UpdateFlight(flightView);
            var result = mockContext.Object.Flights.FirstOrDefault(x => x.UniquePlaneNumber == flightView.UniquePlaneNumber);

            //Assert
            Assert.AreEqual(result.UniquePlaneNumber, flight1.UniquePlaneNumber);
            mockContext.Verify(x => x.SaveChanges(), Times.Once());
        }
        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 void GetAllFlights_ReturnsAllFlightsFromDatabase()
        {
            var data = ExactOrAllflights.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 mockContext = new Mock <FlightManagerDbContext>();

            mockContext.Setup(x => x.Flights).Returns(mockSet.Object);

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

            //Assert
            Assert.AreEqual(2, Result.Count());
        }
        public void GetExactFlights_ReturnsFlightBy_GivenUniquePlaneNumber()
        {
            //Arrange
            var data = ExactOrAllflights.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 mockContext = new Mock <FlightManagerDbContext>();

            mockContext.Setup(x => x.Flights).Returns(mockSet.Object);
            var flight = data.FirstOrDefault(x => x.UniquePlaneNumber == 123456);

            //Act
            var service = new FlightService(mockContext.Object);
            var Result  = service.GetExactFlight(flight.UniquePlaneNumber);

            //Assert
            Assert.AreEqual(1, Result.Count());
        }