예제 #1
0
        public void LateRelativeDateTime()
        {
            // Arrange
            var mockFactory       = new Mock <IHttpClientFactory>();
            var clientHandlerStub = new DelegatingHandlerStub();
            var client            = new HttpClient(clientHandlerStub);

            mockFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client);

            IHttpClientFactory factory     = mockFactory.Object;
            IMemoryCache       memoryCache = new MemoryCache(new MemoryCacheOptions());

            Mock <IMemoryCache> cache = new Mock <IMemoryCache>();

            var myContext = new Mock <HttpContext>();

            DateTime   now        = DateTime.Now;
            FlightPlan flightPlan = new FlightPlan();

            flightPlan.passengers = 200;
            var          json      = JsonConvert.SerializeObject(flightPlan);
            var          byteArray = Encoding.ASCII.GetBytes(json);
            MemoryStream stream    = new MemoryStream(byteArray);

            stream.Flush();
            stream.Position = 0;

            myContext.SetupGet(x => x.Request.Body).Returns(stream);
            var controllerContext = new ControllerContext()
            {
                HttpContext = myContext.Object,
            };
            FlightPlanController controller = new FlightPlanController(memoryCache, factory)
            {
                ControllerContext = controllerContext,
            };

            // Act
            ActionResult <FlightPlan> answer = controller.AddFlightPlan(flightPlan);

            // Assert
            Assert.AreEqual(answer.Value, flightPlan);
        }
        public void ShouldAddFlightPlan()
        {
            using (var mock = AutoMock.GetLoose())
            {
                FlightPlan flightPlan = new FlightPlan()
                {
                    company_name = "bla"
                };
                var x = new Mock <IFlightPlanManager>();
                x.Setup(x => x.AddFlightPlan(flightPlan)).Returns(flightPlan);

                FlightPlanController f = new FlightPlanController(x.Object);
                var actionResult       = f.AddFlightPlan(flightPlan).Result;
                Microsoft.AspNetCore.Mvc.OkObjectResult okObjectResult = (Microsoft.AspNetCore.Mvc.OkObjectResult)actionResult;
                var        temp     = okObjectResult.Value;
                FlightPlan actual   = (FlightPlan)temp;
                var        expected = flightPlan;
                Assert.True(actual != null);
                Assert.Equal(expected.company_name, actual.company_name);
            }
        }
예제 #3
0
        public void Test_AddFlight()
        {
            // Setup
            Location location = new Location(38.112375, 23.879437, DateTime.UtcNow);

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

            segments.Add(new Segment(31.922629, 31.522594, 50)); // Egypt
            segments.Add(new Segment(32.426506, 34.743033, 50)); // Cyprus
            segments.Add(new Segment(26.209199, 35.055211, 50)); // Greece
            FlightPlan flightPlan = new FlightPlan(8, "Company", location, segments);

            var stubRemoteServersConnector = new RemoteServersConnector();
            var mockFlightsManager         = new FlightsManager(stubRemoteServersConnector);
            var flightPlanController       = new FlightPlanController(mockFlightsManager);

            // Act
            IActionResult addAction = flightPlanController.AddFlightPlan(flightPlan);

            // Assert
            Assert.IsType <OkResult>(addAction);
            Assert.Single(mockFlightsManager.GetRelativeFlights(DateTime.UtcNow, false));
        }
예제 #4
0
        public void GetFlightPlan()
        {
            // Arrange
            var mockFactory       = new Mock <IHttpClientFactory>();
            var clientHandlerStub = new DelegatingHandlerStub();
            var client            = new HttpClient(clientHandlerStub);

            mockFactory.Setup(_ => _.CreateClient(It.IsAny <string>())).Returns(client);

            IHttpClientFactory factory     = mockFactory.Object;
            IMemoryCache       memoryCache = new MemoryCache(new MemoryCacheOptions());

            Mock <IMemoryCache> cache = new Mock <IMemoryCache>();

            var myContext = new Mock <HttpContext>();

            DateTime   now        = DateTime.Now;
            FlightPlan flightPlan = new FlightPlan();

            flightPlan.company_name               = "swiss";
            flightPlan.passengers                 = 200;
            flightPlan.initial_location           = new InitialLocation();
            flightPlan.initial_location.date_time = DateTime.Now;
            flightPlan.segments = new List <Segments>();
            flightPlan.segments.Add(new Segments());
            flightPlan.segments[0].timespan_seconds = 100;

            var          json      = JsonConvert.SerializeObject(flightPlan);
            var          byteArray = Encoding.ASCII.GetBytes(json);
            MemoryStream stream    = new MemoryStream(byteArray);

            stream.Flush();
            stream.Position = 0;

            myContext.SetupGet(x => x.Request.Body).Returns(stream);
            var controllerContext = new ControllerContext()
            {
                HttpContext = myContext.Object,
            };
            FlightPlanController controller = new FlightPlanController(memoryCache, factory)
            {
                ControllerContext = controllerContext,
            };

            // Act
            controller.AddFlightPlan(flightPlan);

            // Arrange
            myContext = new Mock <HttpContext>();
            myContext.SetupGet(x => x.Request.QueryString).
            Returns(new QueryString("?relative_to=" + DateTime.Now));
            controllerContext = new ControllerContext()
            {
                HttpContext = myContext.Object,
            };
            controller = new FlightPlanController(memoryCache, factory)
            {
                ControllerContext = controllerContext,
            };

            //Act
            var list = controller.GetFlightsByDateAsync(DateTime.Now);

            // Assert
            Assert.IsTrue(list.Result.Value.Count == 1);

            // Act
            Task <ActionResult <FlightPlan> > answer =
                controller.GetFlightPlanById(list.Result.Value[0].flight_id);

            // Assert
            Assert.AreEqual(answer.Result.Value, flightPlan);

            // Act
            controller.DeleteFlight(list.Result.Value[0].flight_id);
            list = controller.GetFlightsByDateAsync(DateTime.Now);

            // Assert
            Assert.IsTrue(list.Result.Value.Count == 0);
        }