Example #1
0
        public void TestGetAllFlightsPagination()
        {
            int page       = 2;
            int amount     = 1;
            var testFlight = GetTestFlights().Skip(page * (amount - 1)).Take(amount);

            var testAircraft = GetTestAircrafts();

            var mockRepoFlight   = new Mock <IFlightRepository>();
            var mockRepoAircraft = new Mock <IAircraftRepository>();

            mockRepoFlight.Setup(c => c.GetAll())
            .Returns(testFlight);
            mockRepoAircraft.Setup(c => c.GetAll());
            var controller = new FlightController(mockRepoFlight.Object, mockRepoAircraft.Object);

            // Act
            var result = controller.GetAllFlights(0, 0);

            // Assert
            var actionResult = Assert.IsType <ActionResult <IEnumerable <FlightModel> > >(result);
            var model        = Assert.IsType <OkObjectResult>(actionResult.Result);

            Assert.Single((model.Value as IEnumerable <FlightModel>));
        }
Example #2
0
        public void GetAllFlight_ReturnsNotnullList()
        {
            var mock             = new Mock <EFFlightRepository>(db);//repos
            FlightController obj = new FlightController(mock.Object);
            var data             = obj.GetAllFlights();

            Assert.IsNotNull(data);
        }
Example #3
0
        public void GetAllFlights_Valid_OkResult()
        {
            var mock             = new Mock <EFFlightRepository>(db);//repos
            FlightController obj = new FlightController(mock.Object);
            var data             = obj.GetAllFlights();
            var res = data as ObjectResult;

            Assert.AreEqual(200, res.StatusCode);
        }
Example #4
0
 public void GetAllFlights_INValid_BadResult()
 {
     try
     {
         var mock             = new Mock <EFFlightRepository>(db);//repos
         FlightController obj = new FlightController(mock.Object);
         var data             = obj.GetAllFlights();
         var res = data as BadRequestObjectResult;
         Assert.AreEqual(400, res.StatusCode);
     }
     catch (Exception e)
     {
         Assert.AreEqual("Object reference not set to an instance of an object.", e.Message);
     }
 }
Example #5
0
        public void TestGetAllFlights()
        {
            var testFlight   = GetTestFlights();
            var testAircraft = GetTestAircrafts();

            var mockRepoFlight   = new Mock <IFlightRepository>();
            var mockRepoAircraft = new Mock <IAircraftRepository>();

            mockRepoFlight.Setup(c => c.GetAll())
            .Returns(testFlight);
            mockRepoAircraft.Setup(c => c.GetAll());
            var controller = new FlightController(mockRepoFlight.Object, mockRepoAircraft.Object);

            // Act
            var result = controller.GetAllFlights(0, 0);

            // Assert
            var actionResult = Assert.IsType <ActionResult <IEnumerable <FlightModel> > >(result);
            var model        = Assert.IsType <OkObjectResult>(actionResult.Result);

            Assert.Equal(3, (model.Value as IEnumerable <FlightModel>).Count());
        }