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); }
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(); } } }
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; }
public void TestMethod2() { FlightPlanController fp = new FlightPlanController(); // send a fake id, and if we get null from the controller is good. JsonResult temp = fp.Get("ffgk"); Assert.IsNull(temp.Value); }