public async Task GetFlightByFlightNumber_Failure_FlightNotFoundException_404() { Mock <FlightService> service = new Mock <FlightService>(); service.Setup(s => s.GetFlightByFlightNumber(1)).Throws(new FlightNotFoundException()); FlightController controller = new FlightController(service.Object); ObjectResult response = await controller.GetFlightByFlightNumber(1) as ObjectResult; Assert.IsNotNull(response); Assert.AreEqual((int)HttpStatusCode.NotFound, response.StatusCode); Assert.AreEqual("The flight was not found in the database", response.Value); }
public async Task GetFlightByFlightNumber_Failure_ArgumentException_400(int flightNumber) { Mock <FlightService> service = new Mock <FlightService>(); service.Setup(s => s.GetFlightByFlightNumber(1)).Throws(new ArgumentException()); FlightController controller = new FlightController(service.Object); ObjectResult response = await controller.GetFlightByFlightNumber(flightNumber) as ObjectResult; Assert.IsNotNull(response); Assert.AreEqual((int)HttpStatusCode.BadRequest, response.StatusCode); Assert.AreEqual("Bad request", response.Value); }
public async Task GetFlightByFlightNumber_Success() { Mock <FlightService> service = new Mock <FlightService>(); FlightView returnedFlightView = new FlightView("0", ("Lagos", "LOS"), ("Marrakesh", "RAK")); service.Setup(s => s.GetFlightByFlightNumber(0)).Returns(Task.FromResult(returnedFlightView)); FlightController controller = new FlightController(service.Object); ObjectResult response = await controller.GetFlightByFlightNumber(0) as ObjectResult; Assert.IsNotNull(response); Assert.AreEqual((int)HttpStatusCode.OK, response.StatusCode); FlightView content = response.Value as FlightView; Assert.IsNotNull(content); Assert.AreEqual(returnedFlightView, content); }