/// <summary/> public FlightServiceClient(HttpClient httpClient) { _httpClient = httpClient; AirlineSection = new AirlineSection(httpClient); FlightSection = new FlightSection(httpClient); }
private void InsertPermanentData() { Airport originAirport = new Airport(ConstantTestData.OriginAirport); Airport destinationAirport = new Airport(ConstantTestData.DestionationAirport); Airline airline = new Airline(ConstantTestData.AirlineName); Flight flight = new Flight(airline, originAirport, destinationAirport, new DateTime(3000, 12, 1), ConstantTestData.FlightId); Flight fullFlight = new Flight(airline, originAirport, destinationAirport, new DateTime(3000, 12, 1), ConstantTestData.FullFlight); fullFlight.Sections.Add(new FlightSection(ConstantTestData.FlightSectionRows, ConstantTestData.FlightSectionColumns, SeatClass.first)); FlightSection section = new FlightSection(ConstantTestData.FlightSectionRows, ConstantTestData.FlightSectionColumns, SeatClass.first); flight.Sections.Add(section); airline.Flights.Add(flight); section.Seats[ConstantTestData.FlightSectionRows - 1, ConstantTestData.FlightSectionColumns - 1].IsBooked = true; this.Context.Airports.Add(originAirport); this.Context.Airports.Add(destinationAirport); this.Context.Airlines.Add(airline); this.Context.Flights.Add(flight); this.Context.Flights.Add(fullFlight); }
public bool SeatExistsAndNotTaken(string airline, string flightId, string seatType, int row, int col) { Airline targetAirline = context.Airlines.Where(a => a.AirlineName == airline).SingleOrDefault(); Flight targetFlight = targetAirline.Flights.Where(f => f.FlightId == flightId).FirstOrDefault(); FlightSection targetFlightSection = targetFlight.FlightSections.Where(s => s.FlightSectionType.FlightSectionName == seatType).FirstOrDefault(); return(targetFlightSection.Seats.Where(seat => seat.Row == row && seat.Column == col && seat.IsTaken == false).Any()); }
public void CreateSectionWithValidData(string airlineName, string flightId, int rows, int cols, SeatClass seatClass) { FlightSection section = this._sectionService.CreateAndAddNewSectionToFlight(airlineName, flightId, rows, cols, seatClass); var flight = this.Context.Flights.FirstOrDefault(f => f.Id == flightId); Assert.Contains(section, flight.Sections); }
public void invalidConstructorInput() { //Arrange FlightSection flightSection = new FlightSection(SeatClass.First, 100, 100); //Act //Assert }
public void validConstructorLowInput() { //Arrange FlightSection flightSection = new FlightSection(SeatClass.First); //Act //Assert }
public void BookSeat(string airline, string flightId, string seatType, int row, int col) { Airline targetAirline = context.Airlines.Where(a => a.AirlineName == airline).SingleOrDefault(); Flight targetFlight = targetAirline.Flights.Where(f => f.FlightId == flightId).FirstOrDefault(); FlightSection targetFlightSection = targetFlight.FlightSections.Where(s => s.FlightSectionType.FlightSectionName == seatType).FirstOrDefault(); Seat targetSeat = targetFlightSection.Seats.Where(seat => seat.Row == row && seat.Column == col && seat.IsTaken == false).FirstOrDefault(); targetSeat.IsTaken = true; context.SaveChanges(); }
public void findAvailableSeat() { //Arrange FlightSection flightSection = new FlightSection(SeatClass.First, 1, 1); //Act bool actual = flightSection.HasAvailableSeats(); //Assert Assert.AreEqual(true, actual); }
public FlightSection CreateAndAddNewSectionToFlight(string airlineName, string flightId, int rows, int cols, SeatClass seatClass) { Flight flight = _flightService.GetFlightByIdAndAirline(flightId, airlineName); FlightSection section = new FlightSection(rows, cols, seatClass); CheckIfFlightContainsSectionAndAddNewSection(seatClass, flight, section); return(section); }
public void HasAvailableSeats_ListWithAvailableSeats_ShouldPassTest() { // Arrange bool expected = true; // Act FlightSection flightSection = new FlightSection(SeatClass.ECONOMY, 4, 4); bool actual = flightSection.HasAvailableSeats(); // Assert Assert.Equal(expected, actual); }
public void bookAvailableSeat() { //Arrange FlightSection flightSection = new FlightSection(SeatClass.First, 1, 1); //Act bool actual = flightSection.BookSeat(); //books the only available seat bool actual1 = flightSection.BookSeat(); //tries to book non available seat //Assert Assert.AreEqual(true, actual); Assert.AreEqual(false, actual1); }
public void AddSeatsToSectionWithValidData(string airlineName, string flightId, int extraRows, int extraCols, SeatClass seatClass) { FlightSection oldSection = this.Context .Flights.FirstOrDefault(f => f.Id == flightId && f.Airline.Name == airlineName) .Sections.FirstOrDefault(s => s.SeatClass == seatClass); FlightSection newSection = this._sectionService.AddSeatsToSection(airlineName, flightId, extraRows, extraCols, seatClass); Assert.Equal(oldSection.Rows + extraRows, newSection.Rows); Assert.Equal(oldSection.Columns + extraCols, newSection.Columns); //This seat is booked in the base class and should stay booked even after adding new seats; Assert.True(newSection.Seats[ConstantTestData.FlightSectionRows - 1, ConstantTestData.FlightSectionColumns - 1].IsBooked); }
public void addFlightSectionTest() { //Arrange Airline airline = new Airline("ABC"); Airport origin = new Airport("HAM"); Airport destination = new Airport("DAM"); Flight flight = new Flight(airline, origin, destination, 2020, 8, 13, "123"); FlightSection section = new FlightSection(SeatClass.Business, 5, 5); //Act var actual = flight.AddFlightSection(section); //ok flight.AddFlightSection(section); //throws exception because the section is already in //Assert Assert.AreEqual(actual, true); }
public void FlightHasNoAvailableSeatsAfterFullyBooked() { Flight flight = this.Context.Flights.FirstOrDefault(f => f.Id == ConstantTestData.FullFlight); FlightSection section = flight.Sections.FirstOrDefault(s => s.SeatClass == SeatClass.first); Assert.True(flight.hasAvalableSeats); for (int row = 0; row < section.Seats.GetLength(0); row++) { for (int col = 0; col < section.Seats.GetLength(1); col++) { section.Seats[row, col].IsBooked = true; } } Assert.False(flight.hasAvalableSeats); }
public void Constructor_InitializeSeats_ShouldPassTest() { // Arrange List <Seat> expected = new List <Seat> { new Seat(new (1, 'A'), false), new Seat(new (1, 'B'), false), new Seat(new (1, 'C'), false), new Seat(new (1, 'D'), false) }; // Act FlightSection flightSection = new FlightSection(SeatClass.ECONOMY, 1, 4); List <Seat> actual = flightSection.Seats; // Assert Assert.Equal(expected, actual); }
public void HasAvailableSeats_ListWithUnavailableSeats_ShouldPassTest() { // Arrange bool expected = false; // Act FlightSection flightSection = new FlightSection(SeatClass.ECONOMY, 4, 4); // Book all available seats for (int i = 0; i < flightSection.Seats.Count; i++) { flightSection.BookSeat(); } bool actual = flightSection.HasAvailableSeats(); // Assert Assert.Equal(expected, actual); }
public FlightSection AddSeatsToSection(string airlineName, string flightId, int extraRows, int extraCols, SeatClass seatClass) { var flight = this._flightService.GetFlightByIdAndAirline(flightId, airlineName); if (flight == null) { throw new ArgumentException("Flight not found!"); } var oldSection = flight.Sections.FirstOrDefault(s => s.SeatClass == seatClass); if (oldSection == null) { throw new ArgumentException($"Flight doesn't have {seatClass} section"); } if (extraRows == 0 && extraCols == 0) { throw new ArgumentException("Addictional rows and cols should be greater than 0"); } var newRows = oldSection.Seats.GetLength(0) + extraRows; var newCols = oldSection.Seats.GetLength(1) + extraCols; var newSection = new FlightSection(newRows, newCols, oldSection.SeatClass); flight.Sections.Remove(oldSection); CheckIfFlightContainsSectionAndAddNewSection(newSection.SeatClass, flight, newSection); for (int row = 0; row < oldSection.Seats.GetLength(0); row++) { for (int col = 0; col < oldSection.Seats.GetLength(1); col++) { newSection.Seats[row, col] = oldSection.Seats[row, col]; } } return(newSection); }
public void CreateSection_CreateValidFlightSection_ShouldPassTest() { // Arrange SystemManager systemManager = new SystemManager(); systemManager.CreateAirline("QWE"); systemManager.CreateAirport("WER"); systemManager.CreateAirport("REW"); systemManager.CreateFlight("QWE", "WER", "REW", 1872, 2, 2, "1234"); FlightSection expected = new FlightSection(SeatClass.ECONOMY, 4, 5); // Act systemManager.CreateSection("QWE", "1234", 4, 5, SeatClass.ECONOMY); FlightSection actual = systemManager.Airlines[0].Flights[0].FlightSections[0]; // Assert Assert.Equal(expected, actual); }
public void Constructor_InvalidColUnderZero_ShouldPassTest() { // Arrange ArgumentException expected = new ArgumentException("Row or Col are invalid."); // Act ArgumentException actual = null; try { FlightSection flightSection = new FlightSection(SeatClass.FIRST, 10, -5); } catch (ArgumentException ex) { actual = ex; } // Assert Assert.Equal(expected.Message, actual.Message); }
public void bookingTest() { //Arrange Airline airline = new Airline("ABC"); Airport origin = new Airport("HAM"); Airport destination = new Airport("DAM"); Flight flight = new Flight(airline, origin, destination, 2020, 8, 13, "123"); FlightSection section = new FlightSection(SeatClass.Business, 1, 1); flight.AddFlightSection(section); //Act var actual = flight.BookSeat(SeatClass.Business, 1, 'A'); var actual1 = flight.BookSeat(SeatClass.Business, 1, 'A'); //tries to book already booked seat var actual2 = flight.BookSeat(SeatClass.Economy, 2, 'C'); //tries to book non existing seat //Assert Assert.AreEqual(true, actual); Assert.AreEqual(false, actual1); Assert.AreEqual(false, actual2); }
public void availableSeatsTest() { //Arrange Airline airline = new Airline("ABC"); Airport origin = new Airport("HAM"); Airport destination = new Airport("DAM"); Flight flight = new Flight(airline, origin, destination, 2020, 8, 13, "123"); FlightSection section = new FlightSection(SeatClass.Business, 1, 1); flight.AddFlightSection(section); //Act var actual = flight.hasAvailableSeats(); //true becuse there is one seat available flight.BookSeat(SeatClass.Business, 1, 'A'); //books the only avaiable seat var actual1 = flight.hasAvailableSeats(); // //Assert Assert.AreEqual(true, actual); Assert.AreEqual(false, actual1); }
public Seat BookSeat(string airlineName, string flightId, SeatClass seatClass, int row, char colSymbol) { Flight flight = this._flightService.GetFlightByIdAndAirline(flightId, airlineName); FlightSection section = this._flightService.GetFlightSection(seatClass, flight); if (section == null) { throw new ArgumentException($"This flight does't have {seatClass} section"); } try { int col = (int)(colSymbol - 'A'); Seat seat = section.Seats[row - 1, col]; if (seat.IsBooked) { throw new ArgumentException($"Seat {seat.Id} is already booked"); } else { seat.IsBooked = true; } return(seat); } catch (IndexOutOfRangeException) { throw new ArgumentException("Seat doesn't exist"); } catch (Exception) { throw; } }
private static void CheckIfFlightContainsSectionAndAddNewSection(SeatClass seatClass, Flight flight, FlightSection section) { if (flight.Sections.Any(s => s.SeatClass == seatClass)) { throw new ArgumentException("Section already exists"); } flight.Sections.Add(section); }