public CharterSchedule Build() { var schedule = new CharterSchedule("Emirates", "Pride 305", this._flightNo, 5); this._timeTables.ForEach(a => schedule.AddTimeTable(a)); return(schedule); }
public void should_generate_flights_based_on_charter_schedule_when_arrive_is_different_from_depart() { var schedule = new CharterSchedule("Qatar Airways", "Airbus", "4070", 250); var depart1 = TimeSpan.Parse("21:00"); var arrive1 = TimeSpan.Parse("03:00"); schedule.AddTimeTable(new CharterTimeTable(DayOfWeek.Monday, "IKA", "HKT", depart1, arrive1)); var start = DateTime.Parse("2019-08-19"); //Monday var end = DateTime.Parse("2019-08-22"); var expected = new List <Flight>() { new Flight() { Origin = "IKA", Destination = "HKT", FlightNo = "4070", Depart = DateTime.Parse("2019-08-19 21:00:00"), Arrive = DateTime.Parse("2019-08-20 03:00:00"), }, }; var actual = FlightGenerationService.Generate(start, end, schedule); actual.Should().BeEquivalentTo(expected); }
public Guid Create(CreateCharterScheduleDto dto) { var charterSchedule = new CharterSchedule(dto.Airline, dto.Airplane, dto.FlightNo, dto.Seats); foreach (var table in dto.TimeTables) { var depart = TimeSpan.Parse(table.DepartureTime); var arrive = TimeSpan.Parse(table.ArriveDate); charterSchedule.AddTimeTable(new CharterTimeTable(table.Day, table.Origin, table.Destination, depart, arrive)); } _dbContext.CharterSchedules.Add(charterSchedule); _dbContext.SaveChanges(); return(charterSchedule.Id); }
public void should_be_constructed_properly() { var airline = "Mahan"; var airplane = "Airbus-320"; var flightNo = "WK-550"; var seats = 120; var charter = new CharterSchedule(airline, airplane, flightNo, seats); charter.Id.Should().NotBeEmpty(); charter.Airline.Should().Be(airline); charter.Airplane.Should().Be(airplane); charter.FlightNo.Should().Be(flightNo); charter.Seats.Should().Be(seats); }
public static List <Flight> Generate(DateTime start, DateTime end, CharterSchedule baseSchedule) { var flights = new List <Flight>(); foreach (var date in EachDay(start, end)) { var candidate = baseSchedule.TimeTables.FirstOrDefault(a => a.Day == date.DayOfWeek); if (candidate == null) { continue; } var flight = new Flight() { FlightNo = baseSchedule.FlightNo, Origin = candidate.Origin, Destination = candidate.Destination, Depart = date.Add(candidate.Depart), Arrive = date.Add(candidate.Arrive), }; flights.Add(flight); } return(flights); }