Пример #1
0
        public void AskFlightMereTime()
        {
            FlightCalculator calculator = new FlightCalculator();

            // Positions at the flight plan.
            DateTime        launchTime = new DateTime(2020, 5, 24, 20, 4, 30);
            InitialLocation launch     = new InitialLocation(100, 100, launchTime);
            FlightStatus    middle     = new FlightStatus(120, 200, 300);
            FlightStatus    end        = new FlightStatus(140, 250, 200);

            // Generate the flight plan based on those positions.
            FlightPlan flightPlan = new FlightPlan(256, "TestCompany", launch, new FlightStatus[2] {
                middle, end
            });


            DateTime mereTime = launchTime.AddSeconds(150);

            // The test asks for a point at mere time.
            var res = calculator.CreateFlightFromPlan(flightPlan, mereTime, false);

            // Check that expected values are retrieved.
            Assert.AreEqual(110, res.Longitude);
            Assert.AreEqual(150, res.Latitude);
        }
Пример #2
0
        public bool IsValid()
        {
            if (CompanyName == null)
            {
                return(false);
            }
            if (Segments == null || Segments.Count == 0)
            {
                return(false);
            }
            foreach (Segment segment in Segments)
            {
                if (!segment.IsValid())
                {
                    return(false);
                }
            }

            if (InitialLocation == null || !InitialLocation.IsValid())
            {
                return(false);
            }
            if (Passengers < 0)
            {
                return(false);
            }
            return(true);
        }
Пример #3
0
        /* todo
         * This method updates the data of a flight (especially location) and add it to
         * the relevant flights list.
         */
        private async Task <IEnumerable <FlightData> > UpdateAndAddFlight(DateTime relative_to,
                                                                          InitialLocation currentInitial, FlightPlan currentPlan, FlightData relevantFlightData,
                                                                          FlightPlan plan, IEnumerable <FlightData> relevantFlights)
        {
            var secondsInFlight = (relative_to - currentInitial.DateTime).TotalSeconds;

            IEnumerable <Segment> planSegments = await _flightContext.SegmentItems
                                                 .Where(x => x.FlightPlanId == currentPlan.Id).ToListAsync();

            var planSegmentDict = new SortedDictionary <int, Segment>();
            var index           = 0;

            foreach (var planSegment in planSegments)
            {
                planSegmentDict.Add(index, planSegment);
                index++;
            }

            FindAndUpdateLocation(relative_to, planSegmentDict,
                                  secondsInFlight, currentInitial, relevantFlightData, plan);

            relevantFlights = relevantFlights.Append(relevantFlightData);

            return(relevantFlights);
        }
        public string Post([FromBody] FlightPlan flightPlan)
        {
            string  x    = flightPlan.ToJson();
            JObject json = JObject.Parse(x);

            string companyName = json["company_name"].ToString();

            flightPlan.FlightId = GenerateFlightID(companyName);

            InitialLocation initialLocation = json["initial_location"].ToObject <InitialLocation>();

            Flight flight = new Flight()
            {
                FlightId    = flightPlan.FlightId,
                Longitude   = initialLocation.Longitude,
                Latitude    = initialLocation.Latitude,
                Passengers  = Int32.Parse(json["passengers"].ToString()),
                CompanyName = json["company_name"].ToString(),
                DateTime    = initialLocation.DateTime,
                IsExternal  = false
            };

            flightsManager.AddFlight(flight);
            flightPlansManager.AddFlightPlan(flightPlan);

            return(flightPlan.FlightId);
        }
        /**
         * Creates new initial location
         **/
        private InitialLocation AddNewLocation()
        {
            DateTime        time        = DateTime.Now;
            InitialLocation newLocation = new InitialLocation("ABcd1234", 30, 30, time);

            return(newLocation);
        }
Пример #6
0
        // Function that set the latitude and longitude according where the flight is.
        private void SetCurrentCoordinates(DateTime dateTimeRequest, DateTime startFlight, List <Segment> segmentList,
                                           Flights flight, InitialLocation initialLocation)
        {
            DateTime dateTimeTemp = startFlight;
            double   latitude;
            double   longitude;
            int      sumOfSeconds = 0;
            int      i            = 0;

            // Check which segment we need now.
            do
            {
                dateTimeTemp  = dateTimeTemp.AddSeconds(segmentList[i].Timespan_Seconds);
                sumOfSeconds += segmentList[i].Timespan_Seconds;
                i++;
            } while (dateTimeRequest.CompareTo(dateTimeTemp) >= 0 && i < segmentList.Count);
            // Get coordinates of start and end.double latitude1
            if (i >= 2)
            {
                latitude  = segmentList[i - 2].Latitude;
                longitude = segmentList[i - 2].Longitude;
            }
            else
            {
                latitude  = Convert.ToDouble(initialLocation.Latitude);
                longitude = Convert.ToDouble(initialLocation.Longitude);
            }
            DateTime temp1    = dateTimeRequest.AddSeconds(-(sumOfSeconds - segmentList[i - 1].Timespan_Seconds));
            double   leftTime = (temp1 - startFlight).TotalSeconds;

            CalculateNewLongitudeLatitude(flight, latitude, longitude, leftTime, segmentList[i - 1]);
        }
Пример #7
0
 public LoggingObject(Body pb, Body root)
 {
     Body            = pb;
     _root           = root;
     InitialLocation = pb.GetAbsoluteLocation();
     _lastLocation   = InitialLocation.NewX(InitialLocation.X + 1);
     _lastVisibility = !IsVisible();
 }
Пример #8
0
 public FlightPlan(int Passengers1, string CompanyName1, InitialLocation Initial1,
                   List <Segment> seg1)
 {
     Passengers      = Passengers1;
     CompanyName     = CompanyName1;
     InitialLocation = Initial1;
     Segments        = seg1;
 }
Пример #9
0
        public FlightPlan GetMockFlightPlan()
        {
            Coordinate      c    = new Coordinate(12, 32);
            InitialLocation il   = new InitialLocation(c, "2020-05-30T12:00:00Z");
            List <Segment>  segs = new List <Segment>();
            FlightPlan      fp   = new FlightPlan(12, "mock airlines", il, segs);

            return(fp);
        }
        public async Task PostFlightPlanTest()
        {
            // Assign

            InitialLocation location = new InitialLocation();
            DateTime        dateTime = new DateTime(2020, 5, 30, 18, 0, 0);

            location.DateTime  = dateTime;
            location.Longitude = 30.522;
            location.Latitude  = 34.943;
            Segment seg1 = new Segment();

            seg1.FlightId        = "EL-012345";
            seg1.Longitude       = 33.567;
            seg1.Latitude        = 31.865;
            seg1.TimespanSeconds = 180;

            Segment seg2 = new Segment();

            seg2.FlightId        = "EL-012345";
            seg2.Longitude       = 35.674;
            seg2.Latitude        = 30.651;
            seg2.TimespanSeconds = 720;

            List <Segment> segList = new List <Segment>();

            segList.Add(seg1);
            segList.Add(seg2);

            FlightPlan flightPlan1 = new FlightPlan();

            flightPlan1.Id              = 1255;
            flightPlan1.FlightId        = "EL-012345";
            flightPlan1.Passengers      = 168;
            flightPlan1.CompanyName     = "EL-AL";
            flightPlan1.InitialLocation = location;
            flightPlan1.SegmentsList    = segList;
            flightPlan1.IsExternal      = false;


            // Act

            double initialLatitude = 34.943;
            Task <ActionResult <FlightPlan> > apiFlight = fpc.PostFlightPlan(flightPlan1);
            var contextFlights = await _FlightDBContextMock.FlightItems.ToListAsync();

            var contextFlight = contextFlights.Where(a => a.FlightId.CompareTo("EL-012345") == 0).First();


            //Assert

            Assert.IsNotNull(contextFlight);
            Assert.IsTrue(contextFlight.FlightId.CompareTo("EL-012345") == 0);
            Assert.IsTrue(contextFlight.Passengers == 168);
            Assert.AreEqual(segList, contextFlight.SegmentsList);
            Assert.AreEqual(contextFlight.InitialLocation.Latitude, initialLatitude);
        }
Пример #11
0
        public async Task TestMethod1()
        {
            InitialLocation location = new InitialLocation
            {
                Latitude  = 33.244,
                Longitude = 31.12,
                Date_time = "2020-05-27T13:14:05Z"
            };


            List <Segment> segment = new List <Segment>
            {
                new Segment
                {
                    Latitude         = 12,
                    Longitude        = 14,
                    Timespan_seconds = 65
                }
            };

            //expectaion - mock
            var fakeFlightPlane = new FlightPlan {
                Company_name    = "test1",
                Passengers      = 200,
                InitialLocation = location,
                Segments        = segment
            };


            fm.AddFlighttPlan(fakeFlightPlane);
            string id = fm.GetID();

            //async to the server
            var foo = fm.GetFlightPlanById(id);

            Assert.IsTrue(fakeFlightPlane.Passengers == foo.Passengers);
            Assert.IsTrue(fakeFlightPlane.Company_name == foo.Company_name);

            //flights from controler
            var result = await flightTest.Get(id);

            //check that we get someting
            Assert.IsNotNull(result);


            //exercise between fake flight and expected flight
            Task <ActionResult <FlightPlan> > fp1 = flightTest.Get(id);
            var a           = fp1.Result;
            var b           = (OkObjectResult)fp1.Result.Result;
            var flightAsync = (FlightPlan)b.Value;

            Assert.IsTrue(fakeFlightPlane.Passengers == flightAsync.Passengers);
            Assert.IsTrue(fakeFlightPlane.Company_name == flightAsync.Company_name);
            Assert.IsTrue(fakeFlightPlane.InitialLocation.Latitude ==
                          flightAsync.InitialLocation.Latitude);
        }
Пример #12
0
        public Flight IsOccuringAtDateTime(FlightPlan fp, string flightID, DateTime cuurentTime)
        {
            DateTime initialCpy = fp.InitialLocation.DateTime;
            TimeSpan diff       = new TimeSpan();
            Segment  A          = new Segment();
            Segment  B          = new Segment();
            int      i          = 0;

            if (initialCpy >= cuurentTime)
            {
                return(null);
            }

            while (initialCpy < cuurentTime)
            {
                diff = cuurentTime - initialCpy;

                Segment s = GetIsegment(fp, i);
                if (s != null)
                {
                    initialCpy = initialCpy.AddSeconds(s.TimeSpanSeconds);
                }
                else
                {
                    return(null);
                }
                i++;
            }

            i--;

            // limit case
            if (i == 0)
            {
                A.Latitude  = fp.InitialLocation.Latitude;
                A.Longitude = fp.InitialLocation.Longitude;
            }
            else
            {
                A = GetIsegment(fp, i - 1);
            }

            B = GetIsegment(fp, i);
            double          frac    = diff.TotalSeconds / B.TimeSpanSeconds;
            InitialLocation currLoc = Interpolate(frac, A, B);

            // creating the new flight
            Flight newFlight = CreateFlightByFlightPlan(fp, flightID);

            newFlight.Longitude = currLoc.Longitude;
            newFlight.Latitude  = currLoc.Latitude;

            return(newFlight);
        }
Пример #13
0
        // Function that returns flight with the updated values of latitude and longitude, and set the property
        // Is_external according to the given isExternal.
        private Flights AddFlightWithDateTimeAndIsExternal(string id, DateTime dateTime, string isExternal)
        {
            List <Segment>  segmentList     = GetSegmentList(id);
            InitialLocation initialLocation = GetInitialLocation(id);
            // Create flight with the given values.
            Flights  flight             = CreateFlight(isExternal, id, initialLocation.Date_Time);
            DateTime dateTimeOfIdFlight = ConvertToDateTime(initialLocation.Date_Time);

            // Set the current coordinates.
            SetCurrentCoordinates(dateTime, dateTimeOfIdFlight, segmentList, flight, initialLocation);
            return(flight);
        }
Пример #14
0
        public InitialLocation Interpolate(double frac, Segment A, Segment B)
        {
            InitialLocation cur            = new InitialLocation();
            double          diffXCordinate = B.Latitude - A.Latitude;
            double          diffYCordinate = B.Longitude - A.Longitude;
            double          lat            = A.Latitude + diffXCordinate * frac;
            double          lon            = A.Longitude + diffYCordinate * frac;

            cur.Latitude  = lat;
            cur.Longitude = lon;
            return(cur);
        }
        /*
         * Create an InitialLocation object for the test
         */
        private static InitialLocation CreateTestInitialLocation(DateTime startTime)
        {
            var testInitialLocation = new InitialLocation
            {
                Id           = 1,
                FlightPlanId = 1,
                Longitude    = 33.24,
                Latitude     = 19.53,
                DateTime     = startTime
            };

            return(testInitialLocation);
        }
        /*
         * This method adds new initial locations we get from each flight in our DBs
         * and return it.
         */
        private InitialLocation AddInitialLocation(FlightPlan newFlightPlan, double longitude,
                                                   double latitude, DateTime dateTime)
        {
            var newInitialLocation = new InitialLocation
            {
                Latitude     = latitude,
                Longitude    = longitude,
                DateTime     = dateTime,
                FlightPlanId = newFlightPlan.Id
            };

            _flightContext.InitialLocationItems.Add(newInitialLocation);

            return(newInitialLocation);
        }
Пример #17
0
        public void TestMethod1()
        {
            // @@@Arrange@@@

            //create fp = (pass,name,init_loc,segments)
            int             passengers  = 250;
            string          companyName = "El-Down";
            InitialLocation init        = new InitialLocation(30, 30, "2020-05-27T00:00:00Z");
            Segment         a           = new Segment(33, 33, 10);
            Segment         b           = new Segment(40, 40, 20);
            List <Segment>  segments    = new List <Segment>();

            segments.Add(a);
            segments.Add(b);
            FlightPlan fp = new FlightPlan(passengers, companyName, init, segments);
            FlightData fd = new FlightData(fp);

            DateTime dateA     = DateTime.Parse("2020-05-27T00:00:00Z").ToUniversalTime(); // on start
            bool     expectedA = true;
            DateTime dateB     = DateTime.Parse("2020-05-27T00:00:30Z").ToUniversalTime(); // on end
            bool     expectedB = true;
            DateTime dateC     = DateTime.Parse("2020-05-27T00:00:07Z").ToUniversalTime(); // on middle
            bool     expectedC = true;
            DateTime dateD     = DateTime.Parse("2020-05-27T00:00:10Z").ToUniversalTime(); // on segment
            bool     expectedD = true;
            DateTime dateE     = DateTime.Parse("2020-05-27T00:00:31Z").ToUniversalTime(); // after flight
            bool     expectedE = false;
            DateTime dateF     = DateTime.Parse("2020-05-26T00:00:00Z").ToUniversalTime(); // before flight
            bool     expectedF = false;

            // @@@Act@@@

            bool actualA = fd.onAir(dateA);
            bool actualB = fd.onAir(dateB);
            bool actualC = fd.onAir(dateC);
            bool actualD = fd.onAir(dateD);
            bool actualE = fd.onAir(dateE);
            bool actualF = fd.onAir(dateF);

            // @@@Assert@@@

            Assert.AreEqual(expectedA, actualA);
            Assert.AreEqual(expectedB, actualB);
            Assert.AreEqual(expectedC, actualC);
            Assert.AreEqual(expectedD, actualD);
            Assert.AreEqual(expectedE, actualE);
            Assert.AreEqual(expectedF, actualF);
        }
        /**
         * Creates new flight plan
         **/
        private FlightPlan AddNewFlightPlan()
        {
            // set initial location
            InitialLocation newLocation = AddNewLocation();
            Segment         segment     = new Segment("ABcd1234", 32, 32, 650);

            FlightPlan newFlightPlan = new FlightPlan
            {
                Id              = "ABcd1234",
                Passengers      = 222,
                CompanyName     = "El-Al",
                InitialLocation = newLocation
            };

            return(newFlightPlan);
        }
Пример #19
0
        public FlightPlan GetFlightExpected()
        {
            int      passengers   = 2;
            string   company_name = "ISRAIR";
            string   time         = "2020-06-01T12:32:00Z";
            DateTime dt           = DateTime.Parse(time);

            dt = TimeZoneInfo.ConvertTimeToUtc(dt);
            InitialLocation initial_location = new InitialLocation(34.957610, 29.555631, dt);
            List <Segment>  segments         = new List <Segment>()
            {
                new Segment(35.211514, 31.769399, 10000)
            };
            FlightPlan flightPlanExpected = new FlightPlan(passengers, company_name,
                                                           initial_location, segments);

            return(flightPlanExpected);
        }
        public Task <FlightPlan> GetExternalFlightById(string id)
        {
            return(Task.Run(() =>
            {
                string company = "meshi";
                int passenger = 150;
                string time = "2020-06-01T12:32:00Z";
                DateTime dt = DateTime.Parse(time);
                dt = TimeZoneInfo.ConvertTimeToUtc(dt);
                //create initial location
                InitialLocation initialLocation = new InitialLocation(50, 70, dt);
                List <Segment> segmentsList = new List <Segment>();
                FlightPlan flightPlan = new FlightPlan(passenger, company,
                                                       initialLocation, segmentsList);

                return flightPlan;
            }));
        }
Пример #21
0
        /*
         * This method find the specific segment that the flight is in at given time, and updates it
         * live so we can see in each and every moment on the HTTP view where the flight is at
         */
        private static void FindAndUpdateLocation(DateTime relative_to,
                                                  SortedDictionary <int, Segment> planSegmentDict,
                                                  double secondsInFlight, InitialLocation currentInitial,
                                                  FlightData relevantFlightData, FlightPlan plan)
        {
            foreach (var k in planSegmentDict)
            {
                // if the seconds that passed since the beginning of the flight are greater
                // than this segment's duration
                if (secondsInFlight > k.Value.TimeSpanSeconds)
                {
                    secondsInFlight -= k.Value.TimeSpanSeconds;
                }
                else
                {
                    var    secondsInSegment = k.Value.TimeSpanSeconds - (int)secondsInFlight;
                    double lastLatitude;
                    double lastLongitude;
                    if (k.Key == 0)
                    {
                        lastLongitude = currentInitial.Longitude;
                        lastLatitude  = currentInitial.Latitude;
                    }
                    else
                    {
                        var previousSegment = planSegmentDict[k.Key - 1];
                        lastLongitude = previousSegment.Longitude;
                        lastLatitude  = previousSegment.Latitude;
                    }

                    var delta = 1 - secondsInSegment / (double)k.Value.TimeSpanSeconds;
                    relevantFlightData.Latitude =
                        lastLatitude + delta * (k.Value.Latitude - lastLatitude);
                    relevantFlightData.Longitude =
                        lastLongitude + delta * (k.Value.Longitude - lastLongitude);
                    planSegmentDict.Clear();
                    break;
                }
            }

            relevantFlightData.Passengers   = plan.Passengers;
            relevantFlightData.CompanyName  = plan.CompanyName;
            relevantFlightData.CurrDateTime = relative_to;
        }
Пример #22
0
        public void AskFlightAfterLand()
        {
            FlightCalculator calculator = new FlightCalculator();

            // Positions at the flight plan.
            DateTime        launchTime = new DateTime(2020, 5, 24, 20, 4, 30);
            InitialLocation launch     = new InitialLocation(100, 100, launchTime);
            FlightStatus    middle     = new FlightStatus(100, 200, 300);
            FlightStatus    end        = new FlightStatus(100, 250, 200);

            // Generate the flight plan based on those positions.
            FlightPlan flightPlan = new FlightPlan(256, "TestCompany", launch, new FlightStatus[2] {
                middle, end
            });

            // The test asks for a point after land time.
            DateTime afterLand = new DateTime(2021, 6, 27, 22, 41, 35);

            // The expected value is null.
            Assert.IsNull(calculator.CreateFlightFromPlan(flightPlan, afterLand, false));
        }
Пример #23
0
 public FlightPlanDB FlightsPlanById(string id)
 {
     if (id == "test1")
     {
         int      passengers   = 2;
         string   company_name = "ISRAIR";
         string   time         = "2020-06-01T12:32:00Z";
         DateTime dt           = DateTime.Parse(time);
         dt = TimeZoneInfo.ConvertTimeToUtc(dt);
         InitialLocation initial_location = new InitialLocation(34.957610, 29.555631, dt);
         List <Segment>  segments         = SegmentList("test1");
         FlightPlan      flightPlan       = new FlightPlan(passengers, company_name,
                                                           initial_location, segments);
         return(new FlightPlanDB("test1", flightPlan));
     }
     //test 2
     else
     {
         return(null);
     }
 }
        /*
         * This method updates all the related DBs with the new objects we just created
         * from the data we received. we return conflict if the object is already exist in our DBs
         * otherwise, we show the new flight data.
         */
        private async Task <IActionResult> UpdateDb(Flight newFlight, FlightPlan newFlightPlan,
                                                    InitialLocation newInitialLocation)
        {
            try
            {
                await _flightContext.SaveChangesAsync();
            }
            catch (DbUpdateException e)
            {
                if (FlightExists(newFlight.Id) || FlightPlanExists(newFlightPlan.Id) ||
                    InitialLocationExists(newInitialLocation.Id))
                {
                    return(Conflict());
                }

                Debug.WriteLine(e.Message);
                throw;
            }

            return(CreatedAtAction
                       ("GetFlightPlan", new { id = newFlightPlan.FlightId }, newFlightPlan));
        }
Пример #25
0
        public async Task <IEnumerable <Flight> > GetFlightsAsync([FromQuery(Name = "relative_to")] string relativeTime)
        {
            List <Flight> listtosend = new List <Flight>();
            DateTime      testme;

            if (!DateTime.TryParse(relativeTime, out testme))
            {
                return(null);
            }
            // DateTime mytime = DateTime.Parse(relativeTime);
            foreach (var mydata in flightplanmanager.flights)
            {
                DateTime damytime = mydata.initial_location.date_time;
                DateTime d1       = mydata.initial_location.date_time;

                int             size         = mydata.segments.Count;
                DateTime        firstcompare = mydata.initial_location.date_time;
                InitialLocation firstloack   = mydata.initial_location;
                for (int i = 0; i < size; i++)
                {
                    damytime = damytime.AddSeconds(mydata.segments[i].timespan_seconds);
                    DateTime d2         = damytime;
                    DateTime targetDt__ = DateTime.Parse(relativeTime);
                    DateTime targetDt   = TimeZoneInfo.ConvertTimeToUtc(targetDt__);
                    if (targetDt.Ticks > firstcompare.Ticks && targetDt.Ticks < d2.Ticks)
                    {
                        if (i > 0)
                        {
                            firstloack.latitude  = mydata.segments[i - 1].latitude;
                            firstloack.longitude = mydata.segments[i - 1].longitude;
                        }

                        Flight dammy = new Flight();
                        dammy.flight_id    = mydata.FlightPlanId;
                        dammy.company_name = mydata.company_name;
                        dammy.passengers   = mydata.passenger;
                        TimeSpan timespan       = targetDt - firstcompare;
                        TimeSpan allwaysegment  = d2 - firstcompare;
                        double   transitiontime = timespan.TotalSeconds;
                        double   allway         = allwaysegment.TotalSeconds;
                        double   calulate       = transitiontime / allway;
                        double   newlat         = firstloack.latitude + ((mydata.segments[i].latitude - firstloack.latitude) * calulate);
                        double   newlong        = firstloack.longitude + ((mydata.segments[i].longitude - firstloack.longitude) * calulate);
                        dammy.longitude   = newlong;
                        dammy.latitude    = newlat;
                        dammy.date_time   = targetDt;
                        dammy.is_external = false;
                        listtosend.Add(dammy);
                    }

                    mydata.endtime = damytime;
                    firstcompare   = damytime;

                    // addtolist
                    //  firstloack.latitude = mydata.segments[i].latitude;
                    //  firstloack.longitude = mydata.segments[i].longitude;
                }
            }

            if (Request.Query.ContainsKey("sync_all"))
            {
                foreach (var serverdata in iservermanager.allserverslist)
                {
                    List <Flight> extrenal = await askrequset(serverdata, relativeTime);

                    foreach (Flight fla in extrenal)
                    {
                        fla.is_external = true;
                    }
                    listtosend.AddRange(extrenal);
                }
            }
            return(listtosend);
        }
        public void TestMethod1()
        {
            //Arrage
            var options = new DbContextOptionsBuilder <FlightDbContext>().
                          UseInMemoryDatabase(databaseName: "dummy").Options;
            List <Segment> segs1 = new List <Segment>();

            segs1.Add(new Segment()
            {
                ID              = 1,
                Latitude        = 10,
                Longitude       = 10,
                TimespanSeconds = 100
            });
            List <Segment>  segs2 = new List <Segment>();
            List <Segment>  segs3 = new List <Segment>();
            List <Segment>  segs4 = new List <Segment>();
            InitialLocation init1 = new InitialLocation()
            {
                ID        = 1,
                Latitude  = 10,
                Longitude = 10,
                DateTime  = new System.DateTime()
            };
            InitialLocation init2 = new InitialLocation();
            InitialLocation init3 = new InitialLocation();
            InitialLocation init4 = new InitialLocation();
            FlightPlan      fp1   = new FlightPlan()
            {
                FlightID        = "AX100",
                CompanyName     = "OneLine",
                InitialLocation = init1,
                Passengers      = 123,
                Segments        = segs1
            };
            FlightPlan fp2 = new FlightPlan()
            {
                CompanyName     = "TwoLine",
                InitialLocation = init2,
                Passengers      = 456,
                Segments        = segs2
            };
            FlightPlan fp3 = new FlightPlan()
            {
                CompanyName     = "ThreeLine",
                InitialLocation = init3,
                Passengers      = 679,
                Segments        = segs3
            };
            FlightPlan fp4 = new FlightPlan()
            {
                CompanyName     = "FourLine",
                InitialLocation = init4,
                Passengers      = 84,
                Segments        = segs4
            };

            //Act
            using (var context = new FlightDbContext(options))
            {
                context.FlightPlan.Add(fp1);
                context.SaveChanges();
            }

            //Assert
            using (var context = new FlightDbContext(options))
            {
                var controller = new FlightPlanController(context);
                var flights    = controller.GetFlightPlan("AX100");
                var returnedID = (flights.Result.Value as FlightPlan).FlightID;
                Assert.AreEqual(fp1.FlightID, (flights.Result.Value as FlightPlan).FlightID);
            }
        }
        /*
         * Add test objects to the DB context
         */
        private static async Task AddElementsToDb(FlightContext context, Flight testFlight, FlightPlan testFlightPlan, InitialLocation testInitialLocation, Segment testSegmentFirst, Segment testSegmentSecond)
        {
            await context.FlightItems.AddAsync(testFlight);

            await context.FlightPlanItems.AddAsync(testFlightPlan);

            await context.InitialLocationItems.AddAsync(testInitialLocation);

            await context.SegmentItems.AddAsync(testSegmentFirst);

            await context.SegmentItems.AddAsync(testSegmentSecond);

            await context.SaveChangesAsync();
        }