예제 #1
0
        private void UpdateAllTable()
        {
            FlightsService service = Service.getInstanse().flightService;
            DataTable      FlightPriceTable;

            if (service.GetFlightsPrice(out FlightPriceTable))
            {
                GridView.DataSource = FlightPriceTable;
                GridView.DataBind();
            }

            DataTable FlightCitiesTable;

            if (service.GetFlightsCities(out FlightCitiesTable))
            {
                DropDownListDeparture.Items.Clear();
                DropDownListArrival.Items.Clear();

                foreach (DataRow row in FlightCitiesTable.Rows)
                {
                    DropDownListDeparture.Items.Add((string)row[0]);
                    DropDownListArrival.Items.Add((string)row[0]);
                }
            }
        }
        public void Update_Bed()
        {
            //arange
            FlightsService fs = new FlightsService(unitOfWork, mapper, validator);

            var expected = new Flight
            {
                Id               = 1,
                FlightNumber     = "QW11",
                DeparturePoint   = "London",
                DepartureTime    = Convert.ToDateTime("2018-07-13T08:22:56.6404304+03:00"),
                DestinationPoint = "Ukraine",
                ArrivalTime      = Convert.ToDateTime("2018-07-13T08:22:56.6404304+03:00") + TimeSpan.FromHours(5)
            };

            var fightDtoToTest = new FlightDto
            {
                Id               = 1,
                FlightNumber     = "QW",
                DeparturePoint   = "London",
                DepartureTime    = Convert.ToDateTime("2018-07-13T08:22:56.6404304+03:00"),
                DestinationPoint = "Ukraine",
                ArrivalTime      = Convert.ToDateTime("2018-07-13T08:22:56.6404304+03:00") + TimeSpan.FromHours(5)
            };

            //act
            fs.Update(fightDtoToTest);

            var actual = (unitOfWork.Set <Flight>() as FakeRpository <Flight>).updatedItem;

            //assert

            Assert.IsNull(actual);
        }
        public async Task CreateAsync_ShouldSuccessfullyAddToDatabase()
        {
            // Arrange
            var context          = ApplicationDbContextInMemoryFactory.InitializeContext();
            var flightRepository = new EfDeletableEntityRepository <Flight>(context);

            var service    = new FlightsService(flightRepository);
            var inputModel = new FlightInputModel();

            inputModel.FlightNumber      = "FlightNumber";
            inputModel.AvailableSeats    = 20;
            inputModel.PricePerPerson    = 50;
            inputModel.ReservationType   = ReservationType.Flight;
            inputModel.StartPointId      = 1;
            inputModel.StartPointAirPort = "StartAirPort";
            inputModel.EndPointId        = 2;
            inputModel.EndPointAirPort   = "EndAirPort";
            inputModel.DepartureDateTime = new DateTime(2020, 03, 03, 13, 00, 00);
            inputModel.FlightTime        = new TimeSpan(30, 30, 00);
            inputModel.CompanyId         = 1;

            var expectedResult = 1;

            // Act
            await service.CreateAsync(inputModel);

            var actualResult = flightRepository.All().Count();

            // Assert
            Assert.True(expectedResult == actualResult);
        }
예제 #4
0
        /// <summary>
        /// Initialize data to show
        /// </summary>
        /// <param name="date">Date of flight</param>
        /// <param name="from">Location from</param>
        /// <param name="to">Location to</param>
        /// <param name="isReversed">Is flight return</param>
        /// <returns>Asynchronous result</returns>
        private async Task InitializeDataAsync(string date, List <string> from, List <string> to, bool isReversed = false)
        {
            var flightsService = new FlightsService(_httpService, _jsonConverter);
            var flyInfoOneWay  = await flightsService.ConfigurationOfFlightsAsync(date, from, to);

            AddToFlightsList(flyInfoOneWay, isReversed);
        }
예제 #5
0
        private void LoadData()
        {
            FlightsService service = Service.getInstanse().flightService;
            DataTable      AllFlightsTable;

            if (service.GetAllFlights(out AllFlightsTable))
            {
                IdTickets.Clear();
                foreach (DataRow row in AllFlightsTable.Rows)
                {
                    IdTickets.Add(Convert.ToInt32(row[0]));
                }
                AllFlightsTable.PrimaryKey = null;
                AllFlightsTable.Columns.RemoveAt(0);
                GridView.DataSource = AllFlightsTable;
                GridView.DataBind();
            }

            DropDownListDeparture.Items.Clear();
            DataTable FlightCityTable;

            if (service.GetFlightsCities(out FlightCityTable))
            {
                foreach (DataRow row in FlightCityTable.Rows)
                {
                    DropDownListDeparture.Items.Add((string)row[0]);
                }
            }
            OnChangeDepartureCity(null, EventArgs.Empty);
            UpdateEnableAddTicket();
        }
예제 #6
0
        protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int            Id      = IdTickets[e.RowIndex];
            FlightsService service = Service.getInstanse().flightService;

            service.CancelTicket(Id);
            LoadData();
        }
        public async Task EditAsync_ShouldWorkCorrectly()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var seeder  = new FlightsServiceTestsSeeder();
            await seeder.SeedFlightAsync(context);

            var flightRepository = new EfDeletableEntityRepository <Flight>(context);

            var service = new FlightsService(flightRepository);
            var flight  = flightRepository.All().First();
            var model   = new FlightViewModel
            {
                Id                = flight.Id,
                FlightNumber      = flight.FlightNumber,
                AvailableSeats    = flight.AvailableSeats,
                PricePerPerson    = flight.PricePerPerson,
                ReservationType   = flight.ReservationType,
                StartPointId      = flight.StartPointId,
                StartPointAirPort = flight.StartPointAirPort,
                EndPointId        = flight.EndPointId,
                EndPointAirPort   = flight.EndPointAirPort,
                DepartureDateTime = flight.DepartureDateTime,
                FlightTime        = flight.FlightTime,
                CompanyId         = flight.CompanyId,
            };

            model.FlightNumber      = "EditedFlightNumber";
            model.AvailableSeats    = 20;
            model.PricePerPerson    = 50;
            model.ReservationType   = ReservationType.Flight;
            model.StartPointId      = 1;
            model.StartPointAirPort = "EditedStartAirPort";
            model.EndPointId        = 2;
            model.EndPointAirPort   = "EditedEndAirPort";
            model.DepartureDateTime = new DateTime(2020, 03, 03, 13, 00, 00);
            model.FlightTime        = new TimeSpan(30, 30, 00);
            model.CompanyId         = 1;

            // Act
            await service.EditAsync(model.Id, model);

            var actualResult   = flightRepository.All().First();
            var expectedResult = model;

            // Assert
            Assert.True(expectedResult.FlightNumber == actualResult.FlightNumber);
            Assert.True(expectedResult.AvailableSeats == actualResult.AvailableSeats);
            Assert.True(expectedResult.PricePerPerson == actualResult.PricePerPerson);
            Assert.True(expectedResult.ReservationType == actualResult.ReservationType);
            Assert.True(expectedResult.StartPointId == actualResult.StartPointId);
            Assert.True(expectedResult.StartPointAirPort == actualResult.StartPointAirPort);
            Assert.True(expectedResult.EndPointId == actualResult.EndPointId);
            Assert.True(expectedResult.EndPointAirPort == actualResult.EndPointAirPort);
            Assert.True(expectedResult.DepartureDateTime == actualResult.DepartureDateTime);
            Assert.True(expectedResult.FlightTime == actualResult.FlightTime);
            Assert.True(expectedResult.CompanyId == actualResult.CompanyId);
        }
예제 #8
0
        protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            FlightsService service = Service.getInstanse().flightService;
            string         city    = GridView.Rows[e.RowIndex].Cells[1].Text;

            if (service.DeleteCity(city))
            {
                LoadData();
            }
        }
예제 #9
0
        protected void OnButtonPressedAddCity(object sender, EventArgs e)
        {
            FlightsService service = Service.getInstanse().flightService;
            string         city    = TextBoxCity.Text;

            if (service.AddCity(city))
            {
                LoadData();
            }
        }
예제 #10
0
        protected void OnRowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            int            index     = e.RowIndex;
            string         departure = GridView.Rows[index].Cells[1].Text;
            string         arrival   = GridView.Rows[index].Cells[2].Text;
            FlightsService service   = Service.getInstanse().flightService;

            service.DeleteFlightPrice(departure, arrival);
            UpdateAllTable();
        }
        public async Task <ContentResult> FlightsAsync()
        {
            string         textToReturn;
            WebhookRequest request;

            // Parse the body of the request using the Protobuf JSON parser,
            // not Json.NET.
            string requestJson;

            using (TextReader reader = new StreamReader(Request.Body))
            {
                requestJson = await reader.ReadToEndAsync();
            }


            //Parse the intent params
            request = jsonParser.Parse <WebhookRequest>(requestJson);

            // Get flight quote
            if (request.QueryResult.Action.Equals("findFlight"))
            {
                textToReturn = await FlightsService.getFlightPricesAsync(request, _apiContext);
            }

            // Add flight to database
            else if (request.QueryResult.Action.Equals("buyFlight"))
            {
                textToReturn = await FlightsService.addFlightToDatabase(request, _apiContext, _dbContext);
            }

            // See all flights in database
            else if (request.QueryResult.Action == "showAll")
            {
                textToReturn = await FlightsService.showAllFlightsInDatabase(_dbContext);
            }

            // Remove flight from the database
            else if (request.QueryResult.Action == "deleteFlight")
            {
                textToReturn = await FlightsService.deleteFlightFromDatabase(request, _dbContext);
            }


            else
            {
                textToReturn = "Something has gone wrong";
            }


            string responseJson = DialogService.populateResponse(textToReturn);
            var    content      = Content(responseJson, "application/json");

            return(content);
        }
예제 #12
0
        protected void OnButtonPressedBuy(object sender, EventArgs e)
        {
            FlightsService service = Service.getInstanse().flightService;
            string         name    = TextBoxName.Text;
            string         suranme = TextBoxSurname.Text;

            service.AddCustomer(name, suranme);
            service.BuyTicket(DropDownListDeparture.SelectedValue, DropDownListArrival.SelectedValue,
                              name, suranme);

            Response.Redirect("~/FinishBuyTicket.aspx?name=" + name + "&surname=" + suranme);
        }
예제 #13
0
        protected void OnRowEditing(object sender, GridViewEditEventArgs e)
        {
            string         departureCity = GridView.Rows[e.NewEditIndex].Cells[1].Text;
            string         arrivalCity   = GridView.Rows[e.NewEditIndex].Cells[2].Text;
            FlightsService service       = Service.getInstanse().flightService;

            if (service.GetFlightPriceId(departureCity, arrivalCity, out idFlightPrice))
            {
                GridView.EditIndex = e.NewEditIndex;
                UpdateAllTable();
            }
        }
예제 #14
0
        protected void OnButtonPressedAddNewTicket(object sender, EventArgs e)
        {
            string name          = TextBoxName.Text;
            string surname       = TextBoxSurname.Text;
            int    price         = Convert.ToInt32(TextBoxPrice.Text);
            string departureCity = DropDownListDeparture.SelectedValue;
            string arrivelCity   = DropDownListArrival.SelectedValue;

            FlightsService service = Service.getInstanse().flightService;

            service.AddCustomer(name, surname);
            service.BuyTicket(departureCity, arrivelCity, name, surname);
            LoadData();
        }
예제 #15
0
    public MainWindow() : base(Gtk.WindowType.Toplevel)
    {
        Build();

        calendarStartDate.Date = DateTime.Now.AddDays(1);
        SetDefaultEndDate();

        currencyConverter = BuildCurrencyConverter();

        logger         = new UILogger(txtInfo);
        flightsService = new FlightsService(currencyConverter, logger);
        tripService    = new TripService(logger);

        LoadAirports();
    }
예제 #16
0
        public void GetFlightAsyncTest()
        {
            base.ClearAll();

            var mockHttpService = new HttpService();

            Ioc.RegisterSingleton <IHttpService>(mockHttpService);

            var mockJsonConverter = new JsonConverter();

            Ioc.RegisterSingleton <IJsonConverter>(mockJsonConverter);

            var service = new FlightsService(mockHttpService, mockJsonConverter);

            NUnit.Framework.Assert.IsNotNull(service.GetFlightAsync("2017-01-19", "DME", "MSQ"));
        }
예제 #17
0
        public FlightsController()
        {
            _airportFlightsService = new FlightsService();
            var mapperConfig = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <FlightPostModel, FlightModel>();
                cfg.CreateMap <FlightViewModel, FlightModel>().ReverseMap();

                cfg.CreateMap <PilotPostModel, PilotModel>();
                cfg.CreateMap <PilotViewModel, PilotModel>().ReverseMap();

                cfg.CreateMap <PlanePostModel, PlaneModel>();
                cfg.CreateMap <PlaneViewModel, PlaneModel>().ReverseMap();
            });

            _mapper = new Mapper(mapperConfig);
        }
        public async Task IsExistingMethod_ShouldReturnFalseIfFlightNotExists()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var seeder  = new FlightsServiceTestsSeeder();
            await seeder.SeedFlightAsync(context);

            var flightRepository = new EfDeletableEntityRepository <Flight>(context);

            var service = new FlightsService(flightRepository);

            // Act
            var actualResult   = service.Exists("FlightId");
            var expectedResult = false;

            // Assert
            Assert.True(actualResult == expectedResult);
        }
예제 #19
0
        private void FillArrivalCity()
        {
            DropDownListArrival.Items.Clear();
            FlightsService service       = Service.getInstanse().flightService;
            string         DepartureCity = DropDownListDeparture.SelectedValue;

            DataTable table;

            if (!service.GetArrivalCitiesByDeparture(DepartureCity, out table))
            {
                return;
            }

            foreach (DataRow row in table.Rows)
            {
                DropDownListArrival.Items.Add((string)row[0]);
            }
        }
예제 #20
0
        protected void OnRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            string departure = e.NewValues[0].ToString();
            string arrival   = e.NewValues[1].ToString();
            string priceStr  = e.NewValues[2].ToString();

            if (departure == "" || arrival == "" || priceStr == "")
            {
                e.Cancel = true;
                return;
            }
            int            price   = Convert.ToInt32(priceStr);
            FlightsService service = Service.getInstanse().flightService;

            service.UpdateFlightPrice(idFlightPrice, departure, arrival, price);
            GridView.EditIndex = -1;
            UpdateAllTable();
        }
예제 #21
0
        public void testEntityFramwork()
        {
            var flightWrapper = new FlightWrapper(AirportPages.BenGurion);
            var flights       = new List <Flight>();

            for (int i = 0; i < 30; i++)
            {
                var date   = DateTime.Now.AddDays(i);
                var flight = flightWrapper.GetFlightsByDate(date);
                Console.WriteLine("{0}: {1} flights", date, flight.Count);
                flights = flights.Count == 0 ? flight : flights.Concat(flight).ToList();
            }
            Console.WriteLine(flights.Count);
            //var date = DateTime.Now;
            //var flights = flightWrapper.GetFlightsByDate(date);
            var flightsHandler = new FlightsService();

            flightsHandler.SaveFlights(flights);
            var f = flightsHandler.GetAll();
        }
예제 #22
0
 public void collectData()
 {
     try
     {
         var flightsWrapper = new FlightWrapper(AirportPages.BenGurion);
         var flightsHandler = new FlightsService();
         var date           = DateTime.Parse("24/03/2021 00:00:00");
         while (date < DateTime.Parse("29/03/2021 00:00:00"))
         {
             var flights = flightsWrapper.GetFlightsByDate(date);
             Console.WriteLine($"{date}: {flights.Count} flights");
             flightsHandler.SaveFlights(flights);
             date = date.AddDays(1);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw;
     }
 }
예제 #23
0
        protected void OnButtonPressedAddFlight(object sender, EventArgs e)
        {
            string arrival   = DropDownListArrival.SelectedValue;
            string departure = DropDownListDeparture.SelectedValue;
            string priceStr  = TextBoxPrice.Text;

            if (arrival == "" || departure == "" || priceStr == "")
            {
                return;
            }
            if (arrival == departure)
            {
                return;
            }
            int price = Convert.ToInt32(priceStr);

            FlightsService service = Service.getInstanse().flightService;

            service.AddFlightPrice(departure, arrival, price);
            UpdateAllTable();
        }
예제 #24
0
        protected void OnRowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            int id = IdTickets[e.RowIndex];

            FlightsService service   = Service.getInstanse().flightService;
            string         departure = e.NewValues[0].ToString();
            string         arrival   = e.NewValues[1].ToString();
            int            price     = Convert.ToInt32(e.NewValues[2].ToString());
            string         name      = e.NewValues[3].ToString();
            string         surname   = e.NewValues[4].ToString();

            int idFlightPriceId;

            if (service.GetFlightPriceId(departure, arrival, out idFlightPriceId))
            {
                if (service.UpdateTicket(id, idFlightPriceId, name, surname))
                {
                    GridView.EditIndex = -1;
                    LoadData();
                }
            }
        }
        public async Task DeleteAsync_ShouldSuccessfullyDelete()
        {
            // Arrange
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var seeder  = new FlightsServiceTestsSeeder();
            await seeder.SeedFlightAsync(context);

            var flightRepository = new EfDeletableEntityRepository <Flight>(context);

            var service  = new FlightsService(flightRepository);
            var flightId = flightRepository.All().First().Id;

            // Act
            var flightsCount = flightRepository.All().Count();
            await service.DeleteAsync(flightId);

            var actualResult   = flightRepository.All().Count();
            var expectedResult = flightsCount - 1;

            // Assert
            Assert.True(actualResult == expectedResult);
        }
        public void Make()
        {
            //arange
            FlightsService fs = new FlightsService(unitOfWork, mapper, validator);

            var expected = new Flight
            {
                Id               = 1,
                FlightNumber     = "QW11",
                DeparturePoint   = "London",
                DepartureTime    = Convert.ToDateTime("2018-07-13T08:22:56.6404304+03:00"),
                DestinationPoint = "Ukraine",
                ArrivalTime      = Convert.ToDateTime("2018-07-13T08:22:56.6404304+03:00") + TimeSpan.FromHours(5)
            };

            var fightDtoToMake = new FlightDto
            {
                Id               = 1,
                FlightNumber     = "QW11",
                DeparturePoint   = "London",
                DepartureTime    = Convert.ToDateTime("2018-07-13T08:22:56.6404304+03:00"),
                DestinationPoint = "Ukraine",
                ArrivalTime      = Convert.ToDateTime("2018-07-13T08:22:56.6404304+03:00") + TimeSpan.FromHours(5)
            };

            //act
            fs.Make(fightDtoToMake);

            var actual = (unitOfWork.Set <Flight>() as FakeRpository <Flight>).createdItem;

            //assert
            Assert.AreEqual(expected.Id, actual.Id);
            Assert.AreEqual(expected.FlightNumber, actual.FlightNumber);
            Assert.AreEqual(expected.DestinationPoint, actual.DestinationPoint);
            Assert.AreEqual(expected.DepartureTime, actual.DepartureTime);
            Assert.AreEqual(expected.DestinationPoint, actual.DestinationPoint);
            Assert.AreEqual(expected.ArrivalTime, actual.ArrivalTime);
        }
예제 #27
0
 public void Setup()
 {
     _service = new FlightsService();
 }
예제 #28
0
        public void testRemoveAll()
        {
            var flightsHandler = new FlightsService();

            flightsHandler.RemoveAll();
        }
예제 #29
0
 public void testQueryData()
 {
     var flightsHandler = new FlightsService();
     var maxDate        = flightsHandler.GetMaxDate();
     var f = flightsHandler.GetAll();
 }
예제 #30
0
 public void testGetFlightsByDate()
 {
     var date          = DateTime.Now;
     var flightService = new FlightsService();
     var f             = flightService.GetByDate(date);
 }
예제 #31
0
 public void CheckForNewFlights()
 {
     var flightService     = new FlightsService();
     var existingFlightIds = flightService.GetFlightIds();
 }