예제 #1
0
 public void TypeSafeIndexer()
 {
     FlightCollection flights = new FlightCollection();
     Flight firstFlight = new Flight();
     firstFlight.FlightNumber = "1";
     flights.Add(firstFlight);
     flights.Add(new Flight());
     Flight f1 = flights[0];
     Assert.IsNotNull(f1);
     Assert.AreEqual("1", f1.FlightNumber);
 }
예제 #2
0
		public void XmlSerialisationTest()
		{
			Flight flightBefore = new Flight(1, "UA 0123", new Airport(), new Airport(), new Aircraft(), DateTime.MinValue, new Cabin[1] {new Cabin(CabinClass.Business, 2, 8, "A")});

			XmlSerializer s = new XmlSerializer(typeof(Flight));
			StringWriter sw = new StringWriter();
			s.Serialize(sw, flightBefore);
			StringReader sr = new StringReader (sw.ToString());
			Flight flightAfter = (Flight) s.Deserialize (sr);

			Assert.AreEqual(flightAfter.Id, 1);
			Assert.AreEqual(flightAfter.FlightNumber, "UA 0123");
			Assert.AreEqual(flightAfter.DepartureTime, DateTime.MinValue);
			Assert.AreEqual(flightBefore.SeatPlan, flightAfter.SeatPlan);
		}
예제 #3
0
		/// <summary>
		/// Adds an <see cref="SpringAir.Domain.Flight"/> to the end of this collection.
		/// </summary>
		/// <param name="value">
		/// The <see cref="SpringAir.Domain.Flight"/> to be added to the end of the collection.
		/// </param>
		/// <returns>
		/// The index at which the <see cref="SpringAir.Domain.Flight"/> has been added.
		/// </returns>
		public int Add(Flight value)
		{
			return base.List.Add(value);
		}
예제 #4
0
        public FlightCollection GetFlights(Airport origin, Airport destination, DateTime departureDate)
        {
            #region Sanity Checks
            AssertUtils.ArgumentNotNull(origin, "origin");
            AssertUtils.ArgumentNotNull(destination, "destination");
            #endregion

            FlightCollection flights = new FlightCollection();
            
            
            IDbParametersBuilder builder = new DbParametersBuilder(DbProvider);
            builder.Create().Name("departureDate").Type(DbType.Date).Value(departureDate);
            builder.Create().Name("departureAirport").Type(DbType.Int32).Value(origin.Id);
            builder.Create().Name("destinationAirport").Type(DbType.Int32).Value(destination.Id);

#if NET_2_0            
            AdoTemplate.QueryWithRowCallbackDelegate(CommandType.Text, FlightsQuery, 
                                                 delegate(IDataReader dataReader)
                                                 {
                                                     int flightId = dataReader.GetInt32(0);
                                                     string flightNumber = dataReader.GetString(1);
                                                     Aircraft aircraft = aircraftDao.GetAircraft(dataReader.GetInt32(2));

                                                     //TODO: Load cabins from the database
                                                     Cabin[] cabins = aircraft.Cabins;

                                                     Flight flight = new Flight(flightId, flightNumber, origin, destination, aircraft, departureDate, cabins);
                                                     flights.Add(flight); 
                                                 }, 
                                             
                                             
                                             builder.GetParameters());
#else
      AdoTemplate.QueryWithRowCallback(CommandType.Text, FlightsQuery,
                                        new FlightRowCallback(flights, aircraftDao, origin,destination,departureDate ),
                                        builder.GetParameters());      
#endif
            
            
            /*
            IDbCommand command = GetCommand(FlightsQuery);
            using(new ConnectionManager(command.Connection))
            {
                SetFlightQueryParameters(command, departureDate, origin.Id, destination.Id);
                using (SqlDataReader reader = (SqlDataReader) command.ExecuteReader())
                {
                    while(reader.Read())
                    {
                        int flightId = reader.GetInt32(0);
                        string flightNumber = reader.GetString(1);
                        Aircraft aircraft = aircraftDao.GetAircraft(reader.GetInt32(2));

                        //TODO: Load cabins from the database
                        Cabin[] cabins = aircraft.Cabins;

                        Flight flight = new Flight(flightId, flightNumber, origin, destination, aircraft, departureDate, cabins);
                        flights.Add(flight);
                    }
                }
            }
             */
            return flights;
        }
예제 #5
0
        public void ProcessRow(IDataReader dataReader)
        {
            int flightId = dataReader.GetInt32(0);
            string flightNumber = dataReader.GetString(1);
            Aircraft aircraft = aircraftDao.GetAircraft(dataReader.GetInt32(2));

            //TODO: Load cabins from the database
            Cabin[] cabins = aircraft.Cabins;

            Flight flight = new Flight(flightId, flightNumber, origin, destination, aircraft, departureDate, cabins);
            flights.Add(flight); 
        }