示例#1
0
        static void Main(string[] args)
        {
            IPAddress   adresaLocala = IPAddress.Parse("127.0.0.1");
            TcpListener serverSocket = new TcpListener(adresaLocala, 6500);
            TcpClient   clientSocket = default(TcpClient);
            int         counter      = 0;

            repo = new FlightRepo();
            serv = new FlightService(repo);

            serverSocket.Start();
            Console.WriteLine(" >> " + "Server Started");

            counter = 0;
            while (true)
            {
                counter     += 1;
                clientSocket = serverSocket.AcceptTcpClient();
                Console.WriteLine(" >> " + "Client No:" + Convert.ToString(counter) + " started!");
                ClientAdministrator client = new ClientAdministrator();
                client.startClient(clientSocket, Convert.ToString(counter), serv);
            }
            clientSocket.Close();
            serverSocket.Stop();
            Console.WriteLine(" >> " + "exit");
            Console.ReadLine();
        }
        public async Task TestWhetherFlightGotAdded()
        {
            var repo    = new FlightRepo(_context);
            var takeOff = new DateTime(2020, 5, 5, 8, 30, 0);
            var flight  = CreateFlight(takeOff, "*****@*****.**");

            await repo.Add(flight);

            var result = await(_context.Flights.Where(f => f.FlightId == flight.FlightId)).FirstOrDefaultAsync();

            Assert.IsNotNull(result);
        }
        public async Task TestWhetherFlightGotDeleted()
        {
            var repo    = new FlightRepo(_context);
            var takeOff = new DateTime(2020, 4, 4, 8, 30, 0);
            var flight  = CreateFlight(takeOff, "*****@*****.**");

            await AddForTest(flight);

            await repo.Delete(flight.TimeOfFlight, "VR-140");

            var result = await(_context.Flights.Where(f => f.TimeOfFlight == flight.TimeOfFlight && f.RouteId == "VR-140")).FirstOrDefaultAsync();

            Assert.IsNull(result);
        }
示例#4
0
        /*Will Return all flights found between two dates
         * Times in between flights are all available time slots
         */
        public static async Task <List <DateTime> > getAvailableTimes(FlightRepo _db_flights, DateTime start, DateTime end)
        {
            DateTime        current        = start;
            List <DateTime> allFlightTimes = new List <DateTime>();

            //Get all flights for each day between two time periods
            while (current.DayOfYear <= end.DayOfYear)
            {
                var dayFlights = await _db_flights.GetAll(current);

                foreach (var flight in dayFlights)
                {
                    allFlightTimes.Append(flight.TimeOfFlight);
                }
                current = current.AddDays(1);
            }

            //return allFlightTimes; Could return all unavailable times if better for front end

            /*
             * Assuming that flights are schedule rounded to the
             * quarter hour
             */
            List <DateTime> allAvailableTimes = new List <DateTime>();

            current = start;
            while (current.DayOfYear <= end.DayOfYear)
            {
                //When current time passes earliest time, earliest time
                //is removed from list
                if (current.TimeOfDay > allFlightTimes[0].TimeOfDay)
                {
                    allFlightTimes.RemoveRange(0, 1);
                }

                //Add current time to available times if it does not
                //conflict with next earliest time
                if (current.TimeOfDay != allFlightTimes[0].TimeOfDay)
                {
                    allAvailableTimes.Add(current);
                }

                current = current.AddMinutes(15);
            }

            return(allAvailableTimes);
        }
        public async Task TestWhetherFlightWasModified()
        {
            var repo      = new FlightRepo(_context);
            var takeOff   = new DateTime(2020, 6, 6, 8, 30, 0);
            var flight    = CreateFlight(takeOff, "*****@*****.**");
            var oldFlight = flight;

            await AddForTest(flight);

            flight.FlightSpeed = 500;
            await repo.Update(flight);

            var flights = await _context.Flights.ToListAsync();

            var foundFlight = flights.Where(f => f.FlightSpeed == flight.FlightSpeed).FirstOrDefault();

            Assert.IsTrue(foundFlight.FlightSpeed == flight.FlightSpeed && foundFlight.FlightId == oldFlight.FlightId);
        }
示例#6
0
 public FlightService(FlightRepo repo)
 {
     _repo = repo;
 }
示例#7
0
 /* Set context upon instantiation of controller */
 public ScheduleController(PilotRepo db_pilots, FlightRepo db_flights, RouteRepo db_route)
 {
     _db_pilots  = db_pilots;
     _db_flights = db_flights;
     _db_route   = db_route;
 }
示例#8
0
 public FlightService(FlightRepo frep)
 {
     this.repo = frep;
 }
 /*set pilot repo pattern upon instantiation of flights controller*/
 public FlightsController(FlightRepo db_flights, RouteRepo db_route, PilotRepo db_pilot)
 {
     _db_flights = db_flights;
     _db_route   = db_route;
     _db_pilot   = db_pilot;
 }
        public async Task TestWhetherAddFlightDeconflictThrowsSqlException()
        {
            // ARRANGE - setup repo, make a flight and 2 others-- one that conflicts and one that doesn't
            var repo    = new FlightRepo(_context);
            var takeOff = new DateTime(2019, 3, 20, 9, 30, 0);               // 9:30am, March 20th, 2019 - first flight
            var flight  = CreateFlight(takeOff);
            var takeOffConflictBefore = new DateTime(2019, 3, 20, 9, 20, 0); // 9:20am, March 20th, 2019 - conflicting flight (before first flight)
            var flightConflictBefore  = CreateFlight(takeOffConflictBefore);
            var takeOffConflictAfter  = new DateTime(2019, 3, 20, 9, 40, 0); // 9:40am, March 20th, 2019 - conflicting flight (after first flight)
            var flightConflictAfter   = CreateFlight(takeOffConflictBefore);
            var takeOffNoConflict     = new DateTime(2018, 3, 20, 9, 30, 0); // 9:30am, March 20th, 2018 - non-conflicting flight
            var flightNoConflict      = CreateFlight(takeOffNoConflict);

            // ACT - add the flights to the db
            try // add first flight
            {
                await repo.Add(flight);
            }
            catch (DbUpdateException) { Assert.IsTrue(false); }         // manually throw Assertion Exception
            catch (InvalidOperationException) { Assert.IsTrue(false); } // this Add shouldn't create conflict

            try // add non-conflicting flight
            {
                await repo.Add(flightNoConflict);
            }
            catch (DbUpdateException) { Assert.IsTrue(false); }         // manually throw Assertion Exception
            catch (InvalidOperationException) { Assert.IsTrue(false); } // this Add shouldn't create conflict


            try // add conflicting flight before, should throw a DbUpdateException upon Add attempt
            {
                await repo.Add(flightConflictBefore);

                Assert.IsTrue(false); // shouldn't get here
            }
            catch (DbUpdateException) { /* Should be caught here */ }
            catch (InvalidOperationException) { /* And here */ }


            try // add conflicting flight after, should throw a DbUpdateException upon Add attempt
            {
                await repo.Add(flightConflictAfter);

                Assert.IsTrue(false);
            }
            catch (DbUpdateException) { /* Should be caught here */ }
            catch (InvalidOperationException) { /* And here */ }

            // get the current list of flights to be sure the conflicting flight wasn't added
            var resultFlights = await _context.Flights.ToListAsync();

            // look for the conflicting flights in the db list -- result should be empty
            var resultBefore = resultFlights.Where(f => DateTime.Compare(f.TimeOfFlight, flightConflictBefore.TimeOfFlight) == 0 &&
                                                   flightConflictBefore.PilotEmailId == f.PilotEmailId);
            var resultAfter = resultFlights.Where(f => DateTime.Compare(f.TimeOfFlight, flightConflictAfter.TimeOfFlight) == 0 &&
                                                  flightConflictBefore.PilotEmailId == f.PilotEmailId);

            // ASSERT - should return no result
            Assert.IsEmpty(resultBefore);
            Assert.IsEmpty(resultAfter);
        }