Exemple #1
0
        public async Task Get_gives_null_for_non_existing_id()
        {
            var fileDataSourceOptions = new FileDataSourceOptions {
                FilePath = "./testhotelsrates.json"
            };
            var fileDataSourceOptionsMock = new Mock <IOptionsSnapshot <FileDataSourceOptions> >();

            fileDataSourceOptionsMock.Setup(m => m.Value)
            .Returns(fileDataSourceOptions);
            IHotelWithRatesRepository repo = new HotelWithRatesJsonFileRepository(fileDataSourceOptionsMock.Object);
            const int id = 50;

            var hotelWithRates = await repo.GetAsync(id, DateTime.Now);

            hotelWithRates.Should().BeNull();
        }
Exemple #2
0
        public async Task Get_gives_empty_hotelrates_for_non_existing_date()
        {
            var fileDataSourceOptions = new FileDataSourceOptions {
                FilePath = "./testhotelsrates.json"
            };
            var fileDataSourceOptionsMock = new Mock <IOptionsSnapshot <FileDataSourceOptions> >();

            fileDataSourceOptionsMock.Setup(m => m.Value)
            .Returns(fileDataSourceOptions);
            IHotelWithRatesRepository repo = new HotelWithRatesJsonFileRepository(fileDataSourceOptionsMock.Object);
            const int id          = 1;
            var       arrivalDate = DateTime.ParseExact("2021-04-12", "yyyy-MM-dd", CultureInfo.InvariantCulture);

            var hotelWithRates = await repo.GetAsync(id, arrivalDate);

            hotelWithRates.HotelRates.Should().BeEmpty();
        }
Exemple #3
0
        public async Task Get_gives_hotel_for_given_id_and_date()
        {
            var fileDataSourceOptions = new FileDataSourceOptions {
                FilePath = "./testhotelsrates.json"
            };
            var fileDataSourceOptionsMock = new Mock <IOptionsSnapshot <FileDataSourceOptions> >();

            fileDataSourceOptionsMock.Setup(m => m.Value)
            .Returns(fileDataSourceOptions);
            IHotelWithRatesRepository repo = new HotelWithRatesJsonFileRepository(fileDataSourceOptionsMock.Object);
            const int id          = 1;
            var       arrivalDate = DateTime.ParseExact("2016-03-15", "yyyy-MM-dd", CultureInfo.InvariantCulture);

            var hotelWithRates = await repo.GetAsync(id, arrivalDate);

            hotelWithRates.Hotel.HotelID.Should().Be(id);
            hotelWithRates.HotelRates.Should().HaveCount(1);
            hotelWithRates.HotelRates[0].TargetDay.Date.Should().Be(arrivalDate);
        }
Exemple #4
0
        public async Task GetAll_gives_all_hotelrates()
        {
            var dataSourceOptions = new FileDataSourceOptions {
                FilePath = "./testhotelsrates.json"
            };
            var fileOptionsMock = new Mock <IOptions <FileDataSourceOptions> >();

            fileOptionsMock.Setup(m => m.Value)
            .Returns(dataSourceOptions);
            IHotelRateRepository repository = new HotelRateJsonFileRepository(fileOptionsMock.Object);

            var hotelRatesResult = repository.GetAllAsync();

            var hotelRateIdsList = new List <string>();

            await foreach (var hotelRate in hotelRatesResult)
            {
                hotelRateIdsList.Add(hotelRate.RateID);
            }

            hotelRateIdsList.Should().Equal(new List <string> {
                "1", "2", "1", "2"
            });
        }
Exemple #5
0
 public HotelRateJsonFileRepository(IOptions <FileDataSourceOptions> options)
 {
     _dataSource = options.Value;
 }
Exemple #6
0
 public HotelWithRatesJsonFileRepository(IOptionsSnapshot <FileDataSourceOptions> dataSource)
 {
     _dataSource = dataSource.Value;
 }