public async Task PostFlightPlanTest() { // Assign InitialLocation location = new InitialLocation(); DateTime dateTime = new DateTime(2020, 5, 30, 18, 0, 0); location.DateTime = dateTime; location.Longitude = 30.522; location.Latitude = 34.943; Segment seg1 = new Segment(); seg1.FlightId = "EL-012345"; seg1.Longitude = 33.567; seg1.Latitude = 31.865; seg1.TimespanSeconds = 180; Segment seg2 = new Segment(); seg2.FlightId = "EL-012345"; seg2.Longitude = 35.674; seg2.Latitude = 30.651; seg2.TimespanSeconds = 720; List <Segment> segList = new List <Segment>(); segList.Add(seg1); segList.Add(seg2); FlightPlan flightPlan1 = new FlightPlan(); flightPlan1.Id = 1255; flightPlan1.FlightId = "EL-012345"; flightPlan1.Passengers = 168; flightPlan1.CompanyName = "EL-AL"; flightPlan1.InitialLocation = location; flightPlan1.SegmentsList = segList; flightPlan1.IsExternal = false; // Act double initialLatitude = 34.943; Task <ActionResult <FlightPlan> > apiFlight = fpc.PostFlightPlan(flightPlan1); var contextFlights = await _FlightDBContextMock.FlightItems.ToListAsync(); var contextFlight = contextFlights.Where(a => a.FlightId.CompareTo("EL-012345") == 0).First(); //Assert Assert.IsNotNull(contextFlight); Assert.IsTrue(contextFlight.FlightId.CompareTo("EL-012345") == 0); Assert.IsTrue(contextFlight.Passengers == 168); Assert.AreEqual(segList, contextFlight.SegmentsList); Assert.AreEqual(contextFlight.InitialLocation.Latitude, initialLatitude); }
public void PostFlightPlan_ReturnValidResponse() { FlightPlanController fpController = new FlightPlanController(_mockRepo); FlightPlan mockFlightPlan = GetMockFlightPlan(); var expected = _mockRepo.PostFlightPlanOutput; var answer = fpController.PostFlightPlan(mockFlightPlan); OkObjectResult result = (OkObjectResult)answer.Result; var actual = result.Value; Assert.AreEqual(actual, expected, "Invalid Answer in Post FlightPlan method."); }
public async Task PostInValidFlightPlanReturnStatusCode() { //arrange FlightPlanDto flightPlanDto = FlightPlanGenerator.testFlightPlan; flightPlanDto.InitialLocation.Latitude = 200; var flightPlanController = new FlightPlanController(new Mock <IRepository>().Object); //act var result = await flightPlanController.PostFlightPlan(flightPlanDto); //assert Assert.AreEqual(StatusCodes.Status400BadRequest, ((ContentResult)result.Result).StatusCode); }
public async Task PostFlightPlanFailedReturnStatusCode() { //arrange var repositoryMock = new Mock <IRepository>(); FlightPlanDto flightPlanDto = null; repositoryMock.Setup(r => r.AddFlightPlan(null)).Throws(new System.Exception()); var flightPlanController = new FlightPlanController(repositoryMock.Object); //act var result = await flightPlanController.PostFlightPlan(flightPlanDto); //assert Assert.AreEqual(StatusCodes.Status500InternalServerError, ((ContentResult)result.Result).StatusCode); }
public async Task PostFlightPlanSucceedsReturnFlightPlanDto() { //arrange var repositoryMock = new Mock <IRepository>(); FlightPlanDto flightPlanDto = FlightPlanGenerator.testFlightPlan; var flightPlan = FromDto(flightPlanDto); repositoryMock.Setup(r => r.AddFlightPlan(flightPlanDto)).ReturnsAsync(flightPlan); var flightPlanController = new FlightPlanController(repositoryMock.Object); //act var result = await flightPlanController.PostFlightPlan(flightPlanDto); //assert Assert.AreEqual(flightPlanDto, ((CreatedAtActionResult)result.Result).Value); }
public async Task PostFlightPlan() { // Arrange var flightPlan = new FlightPlan { Flight_id = "Ag123456", Passengers = 101, Company_name = "AmitGuy", Initial_location = new Location() }; // Act Task <ActionResult <FlightPlan> > postedFlight = testedCotroller.PostFlightPlan(flightPlan); var flightPlans = await flightPlanContext.FlightPlan.ToListAsync(); FlightPlan resultFlight = flightPlans.Where(a => a.Flight_id.CompareTo(flightPlan.Flight_id) == 0).First(); // Assert Assert.IsNotNull(resultFlight); Assert.IsTrue(resultFlight.Company_name.CompareTo(flightPlan.Company_name) == 0); Assert.IsTrue(resultFlight.Passengers == flightPlan.Passengers); }