public static void Main(string[] args) { IFlightDataProvider flightDataProvider = new FlightMockDataProvider(); var schedule = flightDataProvider.Load(); IFlightRepository repository = new FlightRepository(); repository.Initialize(schedule); var filePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Data", "coding-assigment-orders.json"); IOrderDataProvider orderDataProvider = new OrderFileDataProvider(filePath); var orders = orderDataProvider.Load(); IItineraryBuilder manager = new ItineraryBuilder(repository); var itineraries = manager.GenerateItineraries(orders); IFlightSchedulePresenter schedulePresenter = new FlightScheduleConsolePresenter(); schedulePresenter.Print(schedule); IItineraryPresenter itineraryPresenter = new ItineraryConsolePresenter(); itineraryPresenter.Print(itineraries); Console.ReadKey(); }
public void DepartureBiggerThanArrivalPutTest() { Flight testflight = new Flight(); Location loc_departure = new Location(); Location loc_arrival = new Location(); Airplane airplane = new Airplane(); loc_departure.Id = 1; loc_arrival.Id = 2; airplane.Id = 1; testflight.plane = airplane; testflight.price = 100; testflight.departure = "12-11-2020 01:00:00"; testflight.arrival = "12-11-2020 02:00:00"; testflight.loc_departure = loc_departure; testflight.loc_arrival = loc_arrival; int id = FlightRepository.Add(testflight); testflight.departure = "12-13-2020 01:00:00"; testflight.arrival = "12-12-2020 02:00:00"; testflight.Id = id; var result = controller.Put(testflight); Assert.IsInstanceOf <BadRequestObjectResult>(result.Result); }
public void Flight_AddNew() { FlightRepository repository = new FlightRepository(dbConnectionString); var flightList = repository.GetAll(); var prevCount = flightList.ToList().Count; var rndNo = new Random().Next(10, 999); Flight flight = new Flight { Number = "FL" + rndNo.ToString(), Name = "Test Flight Name", DepartureCity = "Craigieburn", DepartureTime = DateTime.Now, ArrivalCity = "Melbourne", ArrivalTime = DateTime.Now.AddHours(4), PassengerCapacity = 20 }; var result = repository.Add(flight); flightList = repository.GetAll(); var afterCount = flightList.ToList().Count; Assert.AreEqual(1, result); Assert.IsTrue(prevCount > 0); Assert.IsTrue(afterCount > 0); Assert.IsTrue(afterCount > prevCount); }
public async Task Should_GetScheduledFlight() { // Arrange var fileManagerMock = new Mock <IFileManager <Flight> >(); var flight = new Flight() { Id = 1, Passengers = new List <Passenger>(), FlightRoute = new FlightRoute("test", "test"), Plane = new Plane(), }; var flightList = new List <Flight>(); flightList.Add(flight); fileManagerMock.Setup(x => x.ReadFromJsonAsync(It.IsAny <string>())).ReturnsAsync(flightList); var sut = new FlightRepository(fileManagerMock.Object); // Act var result = await sut.GetScheduledFlightAsync(1); // Assert Assert.Equal(flight.Id, result.Id); Assert.Empty(result.Passengers); Assert.IsType <Plane>(result.Plane); Assert.Equal(flight.FlightRoute.Origin, result.FlightRoute.Origin); Assert.Equal(flight.FlightRoute.Destination, result.FlightRoute.Destination); }
public BookingService(BookingRepository bookingRepository, FlightRepository flightRepository, CustomerRepository customerRepository) { _bookingRepository = bookingRepository; _flightRepository = flightRepository; _customerRepository = customerRepository; }
public async Task Should_ScheduleFlights_GivenFileManagerIsNull() { // Arrange var flightList = new List <Flight>() { new Flight() { Id = 2, Passengers = new List <Passenger>(), FlightRoute = new FlightRoute("test", "test"), Plane = new Plane(), } }; var fileManagerMock = new Mock <IFileManager <Flight> >(); fileManagerMock.Setup(x => x.ReadFromJsonAsync(It.IsAny <string>())).ReturnsAsync(new List <Flight>()); var matchObj = new List <Flight>(); fileManagerMock.Setup(x => x.WriteToJsonAsync(It.IsAny <string>(), It.IsAny <List <Flight> >())).Callback <string, List <Flight> >((str, obj) => matchObj.AddRange(obj)); var sut = new FlightRepository(fileManagerMock.Object); // Act await sut.ScheduleFlightsAsync(flightList); Assert.NotEmpty(matchObj); Assert.Equal(flightList[0].Id, matchObj[0].Id); }
public async Task Should_ScheduleFlights_GivenFileManagerIsNotNull() { // Arrange var storeList = new List <Flight>() { new Flight() { Id = 1, Passengers = new List <Passenger>(), FlightRoute = new FlightRoute("test", "test"), Plane = new Plane(), } }; var flightList = new List <Flight>() { new Flight() { Id = 2, Passengers = new List <Passenger>(), FlightRoute = new FlightRoute("test", "test"), Plane = new Plane(), } }; var fileManagerMock = new Mock <IFileManager <Flight> >(); fileManagerMock.Setup(x => x.ReadFromJsonAsync(It.IsAny <string>())).Verifiable(); var sut = new FlightRepository(fileManagerMock.Object); // Act await sut.ScheduleFlightsAsync(flightList); fileManagerMock.Verify(); }
public async Task <HttpResponseMessage> AddFlight([FromBody] FlightInput flightInput) { var geometry = BsonDocument.Parse(flightInput.Geo.ToString()); AirCraft airCraft = await AirCraftRepository.GetAirCraftById(new ObjectId(flightInput.AircraftId)); Flight flight = new Flight() { Aircraft = airCraft, Altitude = flightInput.Altitude, Date = Convert.ToDateTime(flightInput.Date).ToUniversalTime(), Duration = flightInput.Duration, Geo = new GeoBson() { type = geometry["Type"].AsString, coordinates = new BsonArray(geometry["Coords"].AsBsonArray) } }; if (await FlightRepository.AddFlight(flight)) { return(Request.CreateResponse(HttpStatusCode.OK, "Successfully Added!")); } else { return(Request.CreateResponse(HttpStatusCode.InternalServerError, "While adding new Flight, error occurred!")); } }
/// <summary> /// Initializes a new instance of the <see cref="BookingService"/> class. /// </summary> /// <param name="bookingRepository">The booking repository.</param> /// <param name="flightRepository">The flight repository.</param> /// <param name="personRepository">The person repository.</param> public BookingService(BookingRepository bookingRepository, FlightRepository flightRepository, PersonRepository personRepository) : base(bookingRepository) { _bookingRepository = bookingRepository; _flightRepository = flightRepository; _personRepository = personRepository; }
public void TestSetUp() { var connection = @"Server=DESKTOP-DMYTRO\SQLEXPRESS;Initial Catalog=Academy;Trusted_Connection=True;ConnectRetryCount=0"; DbContextOptionsBuilder <MyContext> t = new DbContextOptionsBuilder <MyContext>(); t.UseSqlServer(connection); mc = new MyContext(t.Options); CrewRepository crewRepository = new CrewRepository(mc); PilotRepository pilotRepository = new PilotRepository(mc); StewardessRepository stewardessRepository = new StewardessRepository(mc); FlightRepository flightRepository = new FlightRepository(mc); TicketRepository ticketRepository = new TicketRepository(mc); TakeOffRepository takeOffRepository = new TakeOffRepository(mc); PlaneRepository planeRepository = new PlaneRepository(mc); PlaneTypeRepository planeTypeRepository = new PlaneTypeRepository(mc); UnitOfWork unitOfWork = new UnitOfWork(crewRepository, flightRepository, pilotRepository, planeRepository, planeTypeRepository, stewardessRepository, takeOffRepository, ticketRepository, mc); CrewService crewService = new CrewService(unitOfWork); FlightService flightService = new FlightService(unitOfWork); StewardessService stewardessService = new StewardessService(unitOfWork); PilotService pilotService = new PilotService(unitOfWork); TicketService ticketService = new TicketService(unitOfWork); TakeOffService takeOffService = new TakeOffService(unitOfWork); PlaneService planeService = new PlaneService(unitOfWork); PlaneTypeService planeTypeService = new PlaneTypeService(unitOfWork); pilotController = new PilotController(pilotService); flightController = new FlightController(flightService); }
public void UpdateUsingTwoRepositories() { LocationRepository locationRepository = new LocationRepository(); FlightRepository flightRepository = new FlightRepository(); Flight flight, flightFromDb; Location location; using (TransactionScope scope = new TransactionScope()) { // Update flight and location flight = flightRepository.FindBy(f => f.FlightNumber == "BY001").Single(); flight.FlightNumber = "BY001_updated"; // Since the flight was retrieved using the current repository, // we don't need to call the Edit method flightRepository.Save(); location = locationRepository.FindBy(l => l.City == "Rome").Single(); location.City = "Rome_updated"; // Since the location was retrieved using the current repository, // we don't need to call the Edit method locationRepository.Save(); //TODO: Lab 02, Exercise 2 Task 5.2 : Get flight to check is updated //TODO : Revert transaction } //TODO: Lab 02, Exercise 2 Task 5.4 : Check that update flight has been reverted locationRepository.Dispose(); flightRepository.Dispose(); }
public void GetOutboundFlightTest() { List <Entity> flights = FlightRepository.GetOutboundFlights(testflight.loc_departure.Id, testflight.loc_arrival.Id , testflight.departure); Assert.True(flights.Count() > 0); }
public static bool ApproveFlight(int code, decimal actualBudget) { var user = UserSession.Current.User; if (user != null) { var repo = new FlightRepository(empty: false, actionCode: (int)Constants.FlightAction.Code, code: code); var flight = repo.List.FirstOrDefault(); if (flight != null) { flight.Status = (int)Constants.WorkflowStatus.Approved; flight.ActualBudget = actualBudget; flight.DateCreate = Constants.TotalMilliseconds; flight = repo.UpdateFlight(flight, new List <int>() { (int)Constants.FlightField.ActualBudget, (int)Constants.FlightField.Status, (int)Constants.FlightField.DateCreate }); if (flight == null) { return(false); } var task = new Task(() => InformationManager.FlightApprove(flight.Plan, flight)); task.Start(); var plan = flight.Plan; UpdatePlan(plan); return(true); } return(false); } throw new Exception(); }
public void DeleteFlightTest() { FlightRepository.Delete(new Flight(id)); Entity flight = FlightRepository.Find(id); Assert.That(flight, Is.Null); }
public static List <Flight> GetFlightsPlan(int code) { var user = UserSession.Current.User; var repo = new FlightRepository(false, (int)Constants.FlightAction.Plan, code); return(repo.List); }
public static bool CreateFlight(int planCode, decimal plannedBudget, string comment) { var user = UserSession.Current.User; if (user != null) { Flight flight = new Flight() { PlanCode = planCode, PlannedBudget = plannedBudget, Comment = comment, OwnerCode = user.Code, DateCreate = Constants.TotalMilliseconds, Status = (int)Constants.WorkflowStatus.InPlanned, ActualBudget = default(decimal) }; var repo = new FlightRepository(); var code = repo.InsertData(flight); if (code > Constants.DEFAULT_CODE) { var task = new Task(() => InformationManager.CreateFlight(flight.Plan, flight)); task.Start(); UpdatePlan(flight.Plan, true); } return(code > Constants.DEFAULT_CODE); } throw new Exception(); }
public void UpdateFlight() { // This test checks if the repository is able of updating an entity // that was updated outside of the repository (for example, // an updated entity sent to the service) // The instance created here has the same values as the DB entity Flight flight = new Flight { FlightId = 3, FlightNumber = "BY002" }; // Update the flight number flight.FlightNumber = "BY002_updated"; //TODO: Lab 02 Exercise 2, Task 4.1 : Implement the UpdateFlight Method FlightRepository repository; using (repository = new FlightRepository()) { repository.Edit(flight); repository.Save(); } using (repository = new FlightRepository()) { Flight updatedFlight = repository.FindBy(f => f.FlightNumber == "BY002_updated").FirstOrDefault(); Assert.IsNotNull(updatedFlight); } }
public async Task ClubServiceAircrafFlightTest() { ImportDataTest import = new ImportDataTest(); import.InitContext(); try { _context = import._context; cr = new ClubRepository(_context); AircraftLogBookRepository acr = new AircraftLogBookRepository(_context); FlightRepository fr = new FlightRepository(_context); MemberRepository mr = new MemberRepository(_context); AircraftRepository ar = new AircraftRepository(_context); ClubService clubService = new ClubService(cr, mr, fr, ar, acr, null); int aircraftId = 8; ICollection <Flight> flights = await clubService.GetClubAircraftFlight("BAZ", aircraftId); var group = flights.GroupBy(o => o.Pilot); foreach (var g in group) { System.Diagnostics.Debug.WriteLine(g.FirstOrDefault()?.Pilot?.FirstName); foreach (var gi in g) { System.Diagnostics.Debug.WriteLine(gi.ToString()); } } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
private void RefreshcbBuses() { CitiRepository cityRep = new CitiRepository(); RefreshBindingSourse(); dtpDepartureDate.MinDate = DateTime.Now; dtpArrivalDate.MinDate = DateTime.Now; dtpFinalDateFlight.MinDate = DateTime.Now; cbCityStart.DisplayMember = "CityName"; cbCityStart.ValueMember = "CityId"; cbCityStart.DataSource = cityRep.GetAll(); cbCityEnd.DisplayMember = "CityName"; cbCityEnd.ValueMember = "CityId"; cbCityEnd.DataSource = cityRep.GetAll(); BusRepository busRep = new BusRepository(); FlightRepository flightRep = new FlightRepository(); var busybus = flightRep.GetAll().Select(p => p.BusId).ToList(); int count = 0; var tempBuses = busRep.GetAll(); while (count < busybus.Count) { tempBuses = tempBuses.Where(p => p.BusId != busybus[count]).ToList(); count++; } cbBuses.DisplayMember = "BusName"; cbBuses.ValueMember = "BusId"; cbBuses.DataSource = tempBuses; }
public static void Register(HttpConfiguration config) { //// Web API configuration and services //// Web API routes //config.MapHttpAttributeRoutes(); //config.Routes.MapHttpRoute( // name: "DefaultApi", // routeTemplate: "api/{controller}/{id}", // defaults: new { id = RouteParameter.Optional } //); // Web API configuration and services // Web API routes GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear(); config.MapHttpAttributeRoutes(); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); DB.Initialize(); AirCraftRepository.Init(); FlightRepository.Init(); AirportRepository.Init(); }
public void DeleteTest() { Flight testflight = new Flight(); Location loc_departure = new Location(); Location loc_arrival = new Location(); Airplane airplane = new Airplane(); loc_departure.Id = 1; loc_arrival.Id = 2; airplane.Id = 1; testflight.plane = airplane; testflight.price = 100; testflight.departure = "12-11-2020"; testflight.arrival = "12-21-2020"; testflight.loc_departure = loc_departure; testflight.loc_arrival = loc_arrival; int id = FlightRepository.Add(testflight); var result = controller.Delete(id); Assert.IsInstanceOf <OkObjectResult>(result.Result); }
public void GetRoundTripFlightTest() { List <Entity> flights = FlightRepository.GetRoundTripFlights(testflight.loc_departure.Id, 6 , "12-11-2020", "12-21-2020"); Assert.True(flights.Count() > 0); }
public async Task TestInitialize() { DbContextOptions <FlyingDutchmanAirlinesContext> dbContextOptions = new DbContextOptionsBuilder <FlyingDutchmanAirlinesContext>().UseInMemoryDatabase("FlyingDutchman") .Options; _context = new FlyingDutchmanAirlinesContext_Stub(dbContextOptions); Flight flight = new Flight { FlightNumber = 1, Origin = 1, Destination = 2 }; Flight flight2 = new Flight { FlightNumber = 10, Origin = 3, Destination = 4 }; _context.Flight.Add(flight); _context.Flight.Add(flight2); await _context.SaveChangesAsync(); _repository = new FlightRepository(_context); Assert.IsNotNull(_repository); }
public FlightService(IMapper mapper, FlightRepository repository, AbstractValidator <FlightDto> validator) { _mapper = mapper; _repository = repository; _validator = validator; }
public UserFavoritesController() { context = new ApplicationDbContext(); userFavoritesRepository = new UserFavoriteRepository(context); applicationUserRepository = new ApplicationUserRepository(context); flightRepository = new FlightRepository(context); unitOfWork = new UnitOfWork(context); }
public void SearchAllSortByFirstClassPrice() { var repository = FlightRepository.Instance(); var flights = repository.Search(null, null, "FirstClassPrice"); Assert.IsTrue(flights.First().FirstClassPrice < flights.Last().FirstClassPrice); }
public AddPassengerCommandHandlerBuilder WithFlight(string flightNumber) { Flight = new Flight { Number = flightNumber }; FlightRepository.Setup(x => x.GetAll()).Returns(new[] { Flight, }); return(this); }
public void SearchAllSortByDeparts() { var repository = FlightRepository.Instance(); var flights = repository.Search(null, null, "Departs"); Assert.IsTrue(flights.First().Departs.CompareTo(flights.Last().Departs) == -1); }
public void FlightRepo() { IFlightRepository repo = new FlightRepository(); IFlightServices Business = new FlightServices(repo); //var res = Business.GetFlightById("2"); //Assert.AreEqual("Kigali", res.Destination); }
public void Flight_FindById() { FlightRepository repository = new FlightRepository(dbConnectionString); var flight = repository.Find(1); Assert.IsNotNull(flight); Assert.AreEqual("FL001", flight.Number); Assert.AreEqual(6, flight.PassengerCapacity); }