public async Task TestCreateAircraft() { // Arrange string testId = "1100"; Flight flight = GetTestFlights().FirstOrDefault(p => p.Id == testId); Aircraft aircraft = GetTestAircrafts().FirstOrDefault(p => p.Id == testId); FlightModel flightmodel = GetTestFlightsModels().FirstOrDefault(p => p.Id == testId); AircraftModel aircraftmodel = GetTestAircraftsModels().FirstOrDefault(p => p.Id == testId); var mockRepoAircraft = new Mock <IAircraftRepository>(); var mockRepoFlight = new Mock <IFlightRepository>(); mockRepoFlight.Setup(c => c.Add(flight)); mockRepoAircraft.Setup(c => c.Add(aircraft)); var controller = new AircraftController(mockRepoAircraft.Object); // Act var result = controller.Post(aircraftmodel); // Assert var actionResult = Assert.IsType <OkResult>(result); var model = Assert.IsType <OkResult>(actionResult); }
public void TestGetAllAircraftsPagination() { int page = 2; int amount = 1; var testFlight = GetTestFlights(); var testAircraft = GetTestAircrafts().Skip(page * (amount - 1)).Take(amount);; var mockRepoAircraft = new Mock <IAircraftRepository>(); var mockRepoFlight = new Mock <IFlightRepository>(); mockRepoFlight.Setup(c => c.GetAll()) .Returns(testFlight); mockRepoAircraft.Setup(c => c.GetAll()) .Returns(testAircraft);; var controller = new AircraftController(mockRepoAircraft.Object); // Act var result = controller.GetAll(0, 0); // Assert var actionResult = Assert.IsType <ActionResult <IEnumerable <AircraftModel> > >(result); var model = Assert.IsType <OkObjectResult>(actionResult.Result); Assert.Single((model.Value as IEnumerable <AircraftModel>)); }
void HitPlayer(Collider2D coll) { AircraftController ac = coll.GetComponent <AircraftController> (); if (ac != null) { ac.Die(); } Explode(); }
public async Task TestPutAircraftNotFoundResult() { // Arrange & Act var mockRepoAircraft = new Mock <IAircraftRepository>(); var controller = new AircraftController(mockRepoAircraft.Object); controller.ModelState.AddModelError("error", "some error"); // Act var result = controller.Put(id: "0", model: null); // Assert Assert.IsType <NotFoundResult>(result); }
public async Task TestPutAircraftReturnsNotFoundResultId() { // Arrange String testId = "101"; Aircraft aircraft = GetTestAircrafts()[0]; AircraftModel aircraftmodel = GetTestAircraftsModels()[0]; var mockRepoAircraft = new Mock <IAircraftRepository>(); mockRepoAircraft.Setup(c => c.Update(aircraft)); var controller = new AircraftController(mockRepoAircraft.Object); // Act var result = controller.Put(testId, aircraftmodel); // Assert Assert.IsType <NotFoundResult>(result); }
public void TestGetAllAircrafts() { var testFlight = GetTestFlights(); var testAircraft = GetTestAircrafts(); var mockRepoAircraft = new Mock <IAircraftRepository>(); var mockRepoFlight = new Mock <IFlightRepository>(); mockRepoFlight.Setup(c => c.GetAll()) .Returns(testFlight); mockRepoAircraft.Setup(c => c.GetAll()) .Returns(testAircraft); var controller = new AircraftController(mockRepoAircraft.Object); // Act var result = controller.GetAll(0, 0); // Assert var actionResult = Assert.IsType <ActionResult <IEnumerable <AircraftModel> > >(result); var model = Assert.IsType <OkObjectResult>(actionResult.Result); Assert.Equal(3, (model.Value as IEnumerable <AircraftModel>).Count()); }