/// <summary> /// AddFlight(Flight flight) adds the flight to the Flights table /// </summary> /// <param name="flight">object of type flight</param> /// <returns>integer value indicating the FlightId of the added foodItem</returns> public int AddFlight(Flight flight) { //check the validity of the input if (ModelState.IsValid) { try { //Call AddFlight method to fetch all Flight int FlightId = fs.AddFlight(flight); //return the response return(FlightId); } catch (FlightException) { //rethrow throw; } } else { //throw user defined exception object throw new FlightException("The entered details to fetch the Flight are not valid"); } }
//This test expects AddFlight to succeed for default fake conditions public void AddFlight_Should_Succeed() { //Arrange var input = new FlightToDisplay() { DepartureAirportID = 1, DestinationAirportID = 2 }; //Act var oldFlightsCount = flightsCount; var res = sut.AddFlight(input); //Assert Assert.AreEqual(AddResultStatus.Success, res.Status); Assert.AreEqual(oldFlightsCount + 1, flightsCount); }
public IActionResult Create([Bind("FlightID,AirplaneID,ReservationID")] Flight flight) { if (ModelState.IsValid) { _flightService.AddFlight(flight); _flightService.Save(); return(RedirectToAction(nameof(Index))); } return(View(flight)); }
public static async Task DownloadOne() { var client = new SledClient(); try { var flight = await client.Fetch("1993-1100"); var service = new FlightService(); await service.AddFlight(flight); } catch (FlightDoesNotExistException) { Console.WriteLine("That flight does not exist!"); } }
public async Task <IHttpActionResult> Put(FlightRequest flightRequest) { var flight = Mapper.Map <Flight>(flightRequest); if (await FlightService.Exists(flight)) { return(Conflict()); } var response = await FlightService.AddFlight(flight); if (response.Succeeded) { var flightUrl = $"{Request.RequestUri}/{response.Entity.Id}"; var flightResponse = Mapper.Map <FlightResponse>(response.Entity); return(Created(flightUrl, flightResponse)); } return(new BadRequest(response.Errors, Request)); }
public void CallSaveChangesOnUsitData_WhenCityIsPassed() { // Arrange var mockedData = new Mock <IUsitData>(); var mockedMapedFlightFactory = new Mock <IMappedClassFactory>(); var flightService = new FlightService(mockedMapedFlightFactory.Object, mockedData.Object); var mockedFlightRepository = new Mock <IGenericRepository <Flight> >(); mockedData.Setup(d => d.Flights).Returns(mockedFlightRepository.Object); var flight = new Flight() { Id = 2 }; // Act flightService.AddFlight(flight); // Assert mockedData.Verify(d => d.SaveChanges(), Times.Once); }
public static async Task DownloadAll(int?firstYear = 1993, int firstNum = 1001, int?lastYear = null, int?lastNum = null) { var proxyHost = ConfigurationManager.AppSettings["Proxy.Host"]; var proxyPort = ConfigurationManager.AppSettings["Proxy.Port"]; var proxyUser = ConfigurationManager.AppSettings["Proxy.User"]; var proxyPass = ConfigurationManager.AppSettings["Proxy.Pass"]; var client = new SledClient(proxyHost, Convert.ToInt32(proxyPort), proxyUser, proxyPass); var service = new FlightService(); var keepGoing = true; var year = firstYear; var num = firstNum; var numAttempts = 0; var yearAttempts = 0; var threshold = 5; do { try { Console.Write("Trying to get flight {0}-{1}... ", year, num); var flight = await client.Fetch(String.Format("{0}-{1}", year, num)); Console.Write("Scraped! "); await service.AddFlight(flight); Console.WriteLine("Saved!"); // reset our bad record counters numAttempts = 0; yearAttempts = 0; // bump the record number num++; } catch (FlightDoesNotExistException) { Console.WriteLine("Flight not found."); num++; numAttempts++; // if we've tried as many records as we're allowed we should have hit the last record - reset the num and bump to the next year if (numAttempts >= threshold) { Console.WriteLine("Threshold reached. Moving to next year."); year++; num = 1001; // we only bump year attempts when we increment years yearAttempts++; // reset the num attempts so we try at least 5 per year numAttempts = 0; } if (yearAttempts >= threshold) { Console.WriteLine("Threshold reached. We're done."); keepGoing = false; } } // if we've hit the declared limit, give up if (lastYear.HasValue && lastNum.HasValue && year >= lastYear && num >= lastNum) { keepGoing = false; } if (keepGoing) { Thread.Sleep(500); } } while (keepGoing); }