public static void ClassInit(TestContext context)
        {
            flightServiceMock    = new Mock <FlightService>();
            flightController     = new FlightController(flightServiceMock.Object);
            flightPlanController = new FlightPlanController(flightServiceMock.Object);

            //Take current Time
            postDateTime = DateTime.Now;
            postDateTime = postDateTime.ToUniversalTime();
            //Create Json with current time
            string dateAsString = postDateTime.ToString("yyyy-MM-ddTHH:mm:ssZ");

            string jsonFlight = @"{""passengers"": 216,
    ""company_name"": ""SwissAir"",
    ""initial_location"": {
        ""longitude"": 33.000,
        ""latitude"": 31.000,
        ""date_time"": """ + dateAsString + @"""
    },
    ""segments"": [
        {
            ""longitude"": 33.500,
            ""latitude"": 31.500,
            ""timespan_seconds"": 600
        }
    ]}";

            //Post Flight
            flightPlanController.Post(jsonFlight);
        }
Exemple #2
0
        public async void Are_Post_and_Then_Get_The_Same_For_FlightPlan()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <FlightPlanDBContext>()
                          .UseInMemoryDatabase(databaseName: "Test database");
            var mockDB = new Mock <FlightPlanDBContext>(options)
            {
                CallBase = true
            };

            var flightPlanController = new FlightPlanController(null, mockDB.Object);
            var testPlan             = GetTestFlightPlanVer1();

            //Act
            await flightPlanController.Post(testPlan);

            var ans = await flightPlanController.Get("AAAA-0001");

            //Assert
            Assert.Equal(testPlan.CompanyName, ans.Value.CompanyName);
            Assert.Equal(testPlan.InitialLocation.Latitude, ans.Value.InitialLocation.Latitude);
            Assert.Equal(testPlan.InitialLocation.Longitude, ans.Value.InitialLocation.Longitude);
            Assert.Equal(testPlan.Passengers, ans.Value.Passengers);
            Assert.Equal(testPlan.Segments, ans.Value.Segments);
        }
        public void TestMethod1()
        {
            FlightPlanController fp = new FlightPlanController();
            // read a 100 flight plan from the json file
            string            json        = File.ReadAllText("./FlightplanMultiple (100).json");
            List <FlightPlan> flightsPlan = JsonConvert.DeserializeObject <List <FlightPlan> >(json);

            // send all the flight plan to the controller
            for (int i = 0; i < flightsPlan.Count; i++)
            {
                fp.Post(flightsPlan[i]);
            }
            // for all plight plan, we sent get reqest to the controller with the id and check if we gat the same flight plan
            for (int i = 0; i < flightsPlan.Count; i++)
            {
                string name = flightsPlan[i].Company_name + i;

                JsonResult temp   = fp.Get(name);
                FlightPlan answer = (FlightPlan)temp.Value;
                // if the flight plan is't not the same, the test is fail.
                if (!isEqualFP(answer, flightsPlan[i]))
                {
                    Assert.Fail();
                }
            }
        }
Exemple #4
0
        public void Get_flightPlanExists_ReturnsFlightPlan()
        {
            var mockFlightPlanManager    = new FlightPlanManager(flightPlansStub, externalFlightsStub);
            var mockFlightPlanController = new FlightPlanController(mockFlightPlanManager);
            var testPlan = new FlightPlan(200, "ELAL",
                                          new InitialLocation()
            {
                Latitude  = 34.234,
                Longitude = 21.234,
                Date_Time = "2020-12-27T00:01:30Z"
            }, new List <Segment>()
            {
                new Segment()
                {
                    Latitude         = 32.234,
                    Longitude        = 26.234,
                    Timespan_Seconds = 650
                }
            });

            var response  = mockFlightPlanController.Post(testPlan);
            var okResult  = response as OkObjectResult;
            var flightRes = (FlightPlan)okResult.Value;

            Assert.Same(flightRes, testPlan);
        }
        public static void ClassInit(TestContext context)
        {
            flightServiceMock    = new Mock <FlightService>();
            flightPlanController = new FlightPlanController(flightServiceMock.Object);
            string jsonFlight = @"{""passengers"": 216,
    ""company_name"": ""SwissAir"",
    ""initial_location"": {
        ""longitude"": 33.000,
        ""latitude"": 31.000,
        ""date_time"": ""2020-12-26T18:00:00Z""
    },
    ""segments"": [
        {
            ""longitude"": 33.500,
            ""latitude"": 31.500,
            ""timespan_seconds"": 600
        }
    ]}";
            ActionResult <FlightPlan> returned = flightPlanController.Post(jsonFlight);
            var result = returned.Result as OkObjectResult;
            var plan   = result.Value as FlightPlan;

            flightControlResult = flightPlanController.Get(plan.FlightId);
            var returnedResult = flightControlResult.Result as OkObjectResult;

            returnedPlan = result.Value as FlightPlan;
        }
Exemple #6
0
        public void InvalidPostSegments()
        {
            var mockRepo1            = new Mock <IFlightPlanManager>();
            var mockRepo2            = new Mock <IServerManager>();
            var flightPlanController = new FlightPlanController(mockRepo1.Object, mockRepo2.Object);

            Assert.Null(flightPlanController.Post(GetFligtPlanTest(120, "SwissAir", false)));
        }
Exemple #7
0
        public void InvalidPostCompanyName()
        {
            var mockRepo1            = new Mock <IFlightPlanManager>();
            var mockRepo2            = new Mock <IServerManager>();
            var flightPlanController = new FlightPlanController(mockRepo1.Object, mockRepo2.Object);

            Assert.Null(flightPlanController.Post(GetFligtPlanTest(120, null, true)));
        }
Exemple #8
0
        public void PostFlghtPlanTest(FlightPlan flightPlan, ObjectResult expectedResult)
        {
            // Arrange.
            IDataAccess          demoDataAccess       = new DemoDataAccess();
            IFlightPlanManager   flightPlanManager    = new FlightPlanManager(demoDataAccess);
            FlightPlanController flightPlanController =
                new FlightPlanController(flightPlanManager);

            // Act.
            ActionResult <string> actionResult = flightPlanController.Post(flightPlan);

            // Assert.
            Assert.IsInstanceOfType(actionResult.Result, expectedResult.GetType());
        }
 public void _FlightPlanControllerPostTest()
 {
     using (var mock = AutoMock.GetLoose())
     {
         FlightPlan fp = new FlightPlan()
         {
             company_name = "testCompany"
         };
         var x = new Mock <IFlightPlanManager>();
         x.Setup(x => x.addFlightPlan(fp)).Returns(fp);
         FlightPlanController f = new FlightPlanController(x.Object);
         var actual             = f.Post(fp);
         var expected           = fp;
         Assert.True(actual != null);
         Assert.Equal(expected.company_name, actual.company_name);
     }
 }
Exemple #10
0
        void instalationplan()
        {
            var        flight = new FlightsController();
            Flightplan k      = new Flightplan();

            segments newseg = new segments();

            newseg.setall(22, 22, 2000);
            k.company_name     = "test";
            k.initial_location = new InitialLocation();
            DateTime tt = new DateTime();

            tt = DateTime.Now;
            k.initial_location.setalll(22, 22, tt);
            k.segments = new System.Collections.Generic.List <segments>();
            k.segments.Add(newseg);
            // flightplanmanager.flights.Add(k);
            flightplancontrol.Post(k);
        }
Exemple #11
0
        public void CheckFlights()
        {
            // Create new cache memory and it's keys.
            var cache = new Microsoft.Extensions.Caching.Memory.
                        MemoryCache(new MemoryCacheOptions());
            List <Server> serversList            = new List <Server>();
            List <string> keysList               = new List <string>();
            Dictionary <string, string> serverOf = new Dictionary <string, string>();

            cache.Set("servers", serversList);
            cache.Set("keys", keysList);
            cache.Set("serverOfIds", serverOf);

            // Check Post method of flight plans.
            FlightPlanController fpController = new FlightPlanController(cache)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = new DefaultHttpContext()
                }
            };
            FlightPlan fp = new FlightPlan();

            // Fill flightPlan fields for posting it.
            fp.Passengers                = 200;
            fp.CompanyName               = "SwissAir";
            fp.InitialLocation           = new Location();
            fp.InitialLocation.Longitude = 35;
            fp.InitialLocation.Latitude  = 32;
            fp.InitialLocation.DateTime  = DateTime.UtcNow;
            fp.Segments = new List <Segment>();
            Segment seg = new Segment();

            seg.Longitude       = 36;
            seg.Latitude        = 33;
            seg.TimespanSeconds = 650;
            fp.Segments.Add(seg);
            // Post the preapared flightPlan.
            ActionResult resp = fpController.Post(fp);
            ObjectResult res  = resp as ObjectResult;

            // Check the status code of the response and check it equals
            // to the flight plan which was sent.
            Assert.AreEqual(res.StatusCode, 201);
            Assert.AreEqual(res.Value, fp);
            var iter = fpController.HttpContext.Response.Headers.Values.GetEnumerator();

            iter.MoveNext();
            // Get the interal flight id.
            string internalFlightId = iter.Current.ToArray()[0];

            // Check Post method of servers.
            ServersController serverController = new ServersController(cache);
            Server            testServer       = new Server();

            testServer.Id  = "test";
            testServer.Url = "http://www.testServer.com/";
            // Post the prepared server.
            resp = serverController.Post(testServer);
            res  = resp as ObjectResult;
            // Check the status code of the response and check it equals
            // to the server which was sent.
            Assert.AreEqual(res.StatusCode, 201);
            Assert.AreEqual(res.Value, testServer);

            // Inject fake MessegeHandler to HttpClient.
            // Create new HttpClient and override it's response method with a stub one.
            HttpClient client = new HttpClient(new HttpMessageHandlerStub());
            // Check get method of flights.
            FlightsController flightController = new FlightsController(cache, client)
            {
                ControllerContext = new ControllerContext
                {
                    HttpContext = new DefaultHttpContext()
                }
            };

            // Add sync_all to query.
            flightController.HttpContext.Request.QueryString = new QueryString("?sync_all");
            Task <ActionResult <List <Flight> > > respFlights = flightController.Get(DateTime.UtcNow);

            res = respFlights.Result.Result as ObjectResult;
            Assert.AreEqual(res.StatusCode, 200);
            // Check that we get two flights-
            // the first one is the one was sent earlier in this test.
            // the second one is a fake external flight which was generated by the stub.
            Assert.AreEqual(((List <Flight>)res.Value).Count, 2);
            Flight internalFlight = ((List <Flight>)res.Value)[0];
            Flight externalFlight = ((List <Flight>)res.Value)[1];

            Assert.AreEqual(internalFlight.FlightId, internalFlightId);
            Assert.AreEqual(internalFlight.IsExternal, false);
            Assert.AreEqual(externalFlight.FlightId, "FP00000000");
            Assert.AreEqual(externalFlight.IsExternal, true);
        }