Пример #1
0
        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);
            }
        }
Пример #2
0
        public async void Availability_Returns_BadRequest_When_DepartureAfterReturn()
        {
            var depDateTime    = new DateTime(2020, 08, 09);
            var returnDateTime = new DateTime(1984, 01, 02);
            var location       = "munich";

            _serviceMock.Setup(x => x.GetAvailablePilot(depDateTime, returnDateTime, location))
            .ReturnsAsync(await Task.FromResult((AvailabilityResponseStatus.WrongDates, new Pilot())));

            var result = await _sut.Availability(new AvailabilitySearch
            {
                DepDateTime    = depDateTime,
                ReturnDateTime = returnDateTime,
                Location       = location
            });

            var status = result.Result as BadRequestObjectResult;

            Assert.Equal(400, status.StatusCode);
        }
Пример #3
0
        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);
            }
        }