public void ShouldGetFlightPlan()
        {
            using (var mock = AutoMock.GetLoose())
            {
                FlightPlan flightPlan = new FlightPlan()
                {
                    company_name = "sd"
                };

                Task <FlightPlan> task1 = Task <FlightPlan> .FromResult(flightPlan);

                var x = new Mock <IFlightPlanManager>();

                x.Setup(x => x.GetFlightPlanByID("123")).Returns(task1);

                var controller = new FlightPlanController(x.Object);

                var actionResult = controller.GetFlightPlanById("123").Result;
                Microsoft.AspNetCore.Mvc.OkObjectResult okObjectResult = (Microsoft.AspNetCore.Mvc.OkObjectResult)actionResult;
                var        temp   = okObjectResult.Value;
                FlightPlan actual = (FlightPlan)temp;

                var expected = new FlightPlan()
                {
                    company_name = "sd"
                };
                Assert.True(actual != null);
                Assert.Equal(expected.company_name, actual.company_name);
            }
        }
        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 ShouldAddServer()
        {
            // Arrange
            Server server = new Server {
                ServerID = "test", ServerURL = "test"
            };
            var x = new Mock <IServerManager>();

            x.Setup(x => x.AddServer(server)).Returns(server);

            var httpContext = new DefaultHttpContext();

            var controllerContext = new ControllerContext()
            {
                HttpContext = httpContext,
            };
            //assign context to controller
            ServersController controller = new ServersController(x.Object)
            {
                ControllerContext = controllerContext,
            };

            //Act
            var actionResult = controller.Post(server).Result;

            Microsoft.AspNetCore.Mvc.OkObjectResult okObjectResult = (Microsoft.AspNetCore.Mvc.OkObjectResult)actionResult;
            var    temp      = okObjectResult.Value;
            Server actual    = (Server)temp;
            var    excpected = server;

            // Assert
            Assert.True(actual != null);

            Assert.Equal(excpected.ServerID, actual.ServerID);
            Assert.Equal(excpected.ServerURL, actual.ServerURL);
        }