public CrewOnDemandServiceTests() { _repositoryMock = new Mock <ICrewOnDemandRepository>(); _publisherMock = new Mock <IBookingCreatedPublisher>(); _telemetryClient = new TelemetryClient(TelemetryConfiguration.CreateDefault()); _sut = new CrewOnDemandService(_repositoryMock.Object, _telemetryClient, _publisherMock.Object); }
public async void Availability_Returns_CorrectResult(DateTime depDate, DateTime returnDate, string location, int expectedPilotId) { var options = new DbContextOptionsBuilder <CrewOnDemandContext>() .UseInMemoryDatabase(databaseName: "db_seeded_with_bookings_1") .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 PilotsController(service); var actionResult = await sut.Availability(new AvailabilitySearch { DepDateTime = depDate, ReturnDateTime = returnDate, Location = location }); Assert.IsType <OkObjectResult>(actionResult.Result); var result = actionResult.Result as OkObjectResult; var pilotResult = result.Value as Pilot; Assert.Equal(expectedPilotId, pilotResult.Id); } }
public async void Availability_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 PilotsController(service); var actionResult = await sut.Availability(new AvailabilitySearch { DepDateTime = new DateTime(2020, 1, 1), ReturnDateTime = new DateTime(2000, 1, 1), Location = "munich" }); Assert.IsType <BadRequestObjectResult>(actionResult.Result); } }
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); } } }