public async void Book_Returns_BadRequest_When_DepartureAfterReturn() { var depDateTime = new DateTime(2020, 08, 09); var returnDateTime = new DateTime(1984, 01, 02); var pilotId = 1; _serviceMock.Setup(x => x.BookPilot(depDateTime, returnDateTime, pilotId)) .ReturnsAsync(await Task.FromResult(BookingResponseStatus.WrongDates)); var result = await _sut.Book(new BookingRequest { DepDateTime = depDateTime, ReturnDateTime = returnDateTime, PilotId = pilotId }); var status = result as BadRequestObjectResult; Assert.Equal(400, status.StatusCode); }
public async void Book_Returns_BadRequest_When_DepartureAfterReturn() { var options = new DbContextOptionsBuilder <CrewOnDemandContext>() .UseInMemoryDatabase(databaseName: "db_empty") .Options; using (var context = new CrewOnDemandContext(options)) { var repository = new CrewOnDemandRepository(context); var service = new CrewOnDemandService(repository, _telemetryClient, new BookingCreatedPublisher(_telemetryClient)); var sut = new FlightsController(service); var actionResult = await sut.Book(new BookingRequest { DepDateTime = new DateTime(2020, 1, 1), ReturnDateTime = new DateTime(2000, 1, 1), PilotId = 1 }); Assert.IsType <BadRequestObjectResult>(actionResult); } }
public async void Book_Returns_CorrectResult(DateTime depDate, DateTime returnDate, int pilotId, bool expectedResult) { var options = new DbContextOptionsBuilder <CrewOnDemandContext>() .UseInMemoryDatabase(databaseName: "db_seeded_with_bookings") .Options; using (var context = new CrewOnDemandContext(options)) { context.Database.EnsureCreated(); context.Bookings.AddRange(_fakeBookings); context.SaveChanges(); var repository = new CrewOnDemandRepository(context); var service = new CrewOnDemandService(repository, _telemetryClient, new BookingCreatedPublisher(_telemetryClient)); var sut = new FlightsController(service); var actionResult = await sut.Book(new BookingRequest { DepDateTime = depDate, ReturnDateTime = returnDate, PilotId = pilotId }); if (expectedResult) { Assert.IsType <StatusCodeResult>(actionResult); var result = actionResult as StatusCodeResult; Assert.Equal(201, result.StatusCode); } else { Assert.IsType <ConflictObjectResult>(actionResult); } } }