Exemple #1
0
        public async Task GetFlightPlanExpectedTrue()
        {
            // Arrange
            Location location = new Location();

            location.Flight_id = "Ag123456";
            var insertedFlight = new FlightPlan
            {
                Flight_id        = "Ag123456",
                Passengers       = 101,
                Company_name     = "AmitGuy",
                Initial_location = location
            };

            // Act
            flightPlanContext.FlightPlan.Add(insertedFlight);
            flightPlanContext.SaveChanges();
            var flightPlans = await flightPlanContext.FlightPlan.ToListAsync();

            var flightPlan = flightPlans.Where(a => a.Passengers == 101).ToList();

            Task <ActionResult <FlightPlan> > existingFlightPlanReturned = testedCotroller.GetFlightPlan("Ag123456");

            // Assert
            Assert.IsNotNull(existingFlightPlanReturned);
            Assert.IsTrue("Ag123456" == existingFlightPlanReturned.Result.Value.Flight_id);
            Assert.IsTrue("Ag123456" == existingFlightPlanReturned.Result.Value.Initial_location.Flight_id);
            Assert.IsTrue("AmitGuy" == existingFlightPlanReturned.Result.Value.Company_name);
            Assert.IsTrue(101 == existingFlightPlanReturned.Result.Value.Passengers);
        }
        public async Task GetFlightPlan_ShouldReturnFlightPlan_WhenFlightPlanExists()
        {
            Location location = new Location();

            location.ID = "DF562344";
            // Arrange
            var flightPlanDto = new FlightPlan
            {
                ID              = "NL145289",
                Passengers      = 257,
                CompanyName     = "el al",
                InitialLocation = location
            };

            flightDBContextMock.FlightPlan.Add(flightPlanDto);
            flightDBContextMock.SaveChanges();
            // Act
            var flightPlan = await flightDBContextMock.FlightPlan.FindAsync("NL145289");

            Task <ActionResult <FlightPlan> > fp1 = sut.GetFlightPlan("NL145289");

            // Assert

            /** check some attrubutes of the FlightPlan feilds in DB
             * */
            Assert.IsTrue("NL145289" == flightPlan.ID);
            Assert.IsTrue(257 == flightPlan.Passengers);
            Assert.IsTrue("el al" == flightPlan.CompanyName);
            Assert.IsTrue("DF562344" == flightPlan.InitialLocation.ID);

            /** check GetFlightPlan method
             */
            // true because we added a flight plan with that id to the DB
            Assert.IsNotNull(fp1);
        }
Exemple #3
0
        public async Task GetFlightPlan_FlighInDb_ReturnFlightDbAsync()
        {
            //Arrange
            string         id       = "test1";
            FlightPlan     Expected = GetFlightExpected();
            StubSQLCommand stub     = new StubSQLCommand();
            //FakeExternalFlight fakeExternalFlight = new FakeExternalFlight();
            Mock <IExternalFlights> mock = new Mock <IExternalFlights>();

            //FlightPlan fake = FakeExternalFlight();
            mock.Setup(x => x.GetExternalFlightById(id))
            .Returns(FakeExternalFlight());
            //injection with the fake data
            FlightPlanController flightPlanController =
                new FlightPlanController(mock.Object, stub);

            //Act
            var result = await flightPlanController.GetFlightPlan(id);

            ActionResult mod          = result.Result;
            var          ok           = mod as OkObjectResult;
            FlightPlan   resultFlight = (FlightPlan)ok.Value;
            // var flight = result.Value;
            //var flight = result.Result;
            //var a=flight.();


            //Assert
            var object1Json = JsonConvert.SerializeObject(Expected);
            var object2Json = JsonConvert.SerializeObject(resultFlight);

            Assert.AreEqual(object1Json, object2Json);
            //   Assert.AreEqual(Expected.C );
            mock.Verify(x => x.GetExternalFlightById(id), Times.Never);
        }
        public async Task GetFlightPlan_ShouldReturnFlightPlanById_fromExternalServer()
        {
            //arrange - create In Memory Database
            var options = new DbContextOptionsBuilder <DBInteractor>()
                          .UseInMemoryDatabase(databaseName: "filghtContolDB")
                          .Options;

            //// Create mocked Context by seeding Data as per Schema///
            using (var context = new DBInteractor(options))
            {
                context.Servers.Add(new Server
                {
                    Id  = "1",
                    Url = "serverTest"
                });
                context.ExternalFlights.Add(new ExternalFlight
                {
                    FlightId          = "1",
                    ExternalServerUrl = "serverTest"
                });

                context.SaveChanges();
            }

            //act
            using (var context = new DBInteractor(options))
            {
                var stub = new StubIServerManager();

                FlightPlanController controller = new FlightPlanController(context)
                {
                    ServerManagerProp = stub
                };
                var actionResult = await controller.GetFlightPlan("1");

                var okObject = actionResult as OkObjectResult;
                //var actualResult = result.Value;
                var flight = JsonConvert.DeserializeObject <FlightPlan>(okObject.Value.ToString());
                Assert.AreEqual(1, flight.Passengers);
                Assert.AreEqual("testCompany", flight.CompanyName);
                Assert.AreEqual(3, flight.Segments.Count);
                Assert.AreEqual(20, flight.InitialLocation.Latitude);
                Assert.AreEqual(25, flight.InitialLocation.Longitude);
            }
        }
Exemple #5
0
        public async Task TestGetFlightPlan()
        {
            //Arrange
            // the plan to post
            FlightPlan plan   = new FlightPlan(1, "1", new Location(0, 0, DateTime.UtcNow), new LinkedList <Segment>());
            var        planID = "as1234";


            var plansDictStub = new ConcurrentDictionary <string, FlightPlan>();

            plansDictStub.TryAdd(planID, plan);

            var httpFactoryMock = new Mock <IHttpClientFactory>();

            httpFactoryMock.Setup(f => f.CreateClient("api")).Returns(new HttpClient());


            //the controller
            FlightPlanController controller = new FlightPlanController(
                plansDictStub,
                new Dictionary <string, Server>(),
                new Dictionary <string, string>(),
                httpFactoryMock.Object
                );
            var expected = plan;
            //Act
            var respone = await controller.GetFlightPlan(planID);

            var actual = respone.Result as OkObjectResult;

            //Assert
            if (actual != null)
            {
                Assert.AreEqual(expected, actual.Value);
            }
        }
        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);
            }
        }