Exemplo n.º 1
0
        public async Task GetFlights_Failure_ArgumentException_500()
        {
            Mock <FlightService> service = new Mock <FlightService>();

            service.Setup(s => s.GetFlights()).Throws(new ArgumentException());

            FlightController controller = new FlightController(service.Object);
            ObjectResult     response   = await controller.GetFlights() as ObjectResult;

            Assert.IsNotNull(response);
            Assert.AreEqual((int)HttpStatusCode.InternalServerError, response.StatusCode);
            Assert.AreEqual("An error occurred", response.Value);
        }
Exemplo n.º 2
0
        public async Task GetFlights_Failure_FlightNotFoundException_404()
        {
            Mock <FlightService> service = new Mock <FlightService>();

            service.Setup(s => s.GetFlights()).Throws(new FlightNotFoundException());

            FlightController controller = new FlightController(service.Object);
            ObjectResult     response   = await controller.GetFlights() as ObjectResult;

            Assert.IsNotNull(response);
            Assert.AreEqual((int)HttpStatusCode.NotFound, response.StatusCode);
            Assert.AreEqual("No flights were found in the database", response.Value);
        }
Exemplo n.º 3
0
        public void Test1()
        {
            //preparacion
            var Origen            = "MDE";
            var Destino           = "BOG";
            var FechaVuelo        = DateTime.Now.AddDays(1); //la fecha que se le debe enviar debe ser de hoy en adelante
            var resultadoEsperado = JsonResult;


            FlightController objetoPrueba = new FlightController();

            //ejecucion
            var resultado = objetoPrueba.GetFlights(Origen, Destino, FechaVuelo);

            //comprobacion
            Assert.Pass();
        }
Exemplo n.º 4
0
        public async Task HomeController_GetFlights_Should_Return_Convenient_FlightsAsync(int departure, int destination, DateTime startDate, DateTime endDate)
        {
            var controller = new FlightController(_flightService.Object);

            var response = await controller.GetFlights(new FlightRequestDto()
            {
                DepartureId = departure, DestinationId = destination, StartDate = startDate
            });

            var okResult = response as OkObjectResult;

            okResult.Should().NotBeNull();

            ICollection <FlightResponseDto> flightResponse = okResult.Value as ICollection <FlightResponseDto>;

            flightResponse.Count.Should().Be(flights.Where(t => t.Destination.Id == destination &&
                                                           t.Departure.Id == departure &&
                                                           t.Flightdate >= startDate && t.Flightdate <= endDate).ToList().Count);
        }
Exemplo n.º 5
0
    static void Main(string[] args)
    {
        string command = "N";

        while (command != "Y")
        {
            Console.WriteLine("Where are you flying from?");
            string departure = Console.ReadLine();

            Console.WriteLine("Where are you flying to");
            string arrival = Console.ReadLine();

            Console.WriteLine("when do you want to leave MMM dd, yyyy");
            string departureDate = Console.ReadLine();
            departureDate = DateTime.Parse(departureDate).ToString("MMM dd, yyyy");

            Console.WriteLine("# of adults");
            var adultsInput = Console.ReadLine();
            int adults      = int.Parse(adultsInput);

            IWebDriver       driver = new BrowserDriver("chrome").GetDriver();
            FlightController fc     = new FlightController();

            driver.Url = fc.urlGenerator("frontier", departure, arrival, departureDate, adults);

            fc.SearchForElementsByCss(driver, "#flight-section-container", 10);

            System.Threading.Thread.Sleep(2000);    // for raising accuracy

            List <Flight> flightlist = fc.GetFlights(driver, ".ibe-flight-info-container .ibe-flight-info");

            fc.printFlights(flightlist);

            Console.WriteLine("Thanks for using our system, close now? (Y/N)");
            command = Console.ReadLine(); //if Y close the program
        }
    }
Exemplo n.º 6
0
        public async Task GetFlights_Success()
        {
            Mock <FlightService> service = new Mock <FlightService>();

            List <FlightView> returnFlightViews = new List <FlightView>(2)
            {
                new FlightView("1932", ("Groningen", "GRQ"), ("Phoenix", "PHX")),
                new FlightView("841", ("New York City", "JFK"), ("London", "LHR"))
            };

            service.Setup(s => s.GetFlights()).Returns(FlightViewAsyncGenerator(returnFlightViews));

            FlightController controller = new FlightController(service.Object);
            ObjectResult     response   = await controller.GetFlights() as ObjectResult;

            Assert.IsNotNull(response);
            Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode);

            Queue <FlightView> content = response.Value as Queue <FlightView>;

            Assert.IsNotNull(content);

            Assert.IsTrue(returnFlightViews.All(flight => content.Contains(flight)));
        }