public void Updates_to_existing_tours_succeed() { //TODO - check values are updated Assert.DoesNotThrowAsync(async() => { var tourRepository = new TourRepository(); var providerRepository = new ProviderRepository(); var logger = new Mock <ILogger>(); var apiDownloader = new Mock <IApiDownloader>(); apiDownloader.Setup(api => api.Download()).ReturnsAsync(_newUpdatesForTour1); var importer = new Importer( tourRepository: tourRepository, providerRepository: providerRepository, apiDownloader: apiDownloader.Object, logger: logger.Object); await importer.Execute(providerId: 1); var tour1 = tourRepository.Get(tourId: 1); tour1.Result.Availabilities.Count.Should().Be(_newUpdatesForTour1.Body.Count); var orderedResults = tour1.Result.Availabilities.OrderBy(a => a.StartDate).ToList(); for (var i = 0; i < _newUpdatesForTour1.Body.Count; i++) { orderedResults[i].StartDate.Should().Be(DateTime.Parse(_newUpdatesForTour1.Body[i].DepartureDate)); //TODO - test the pricing algorithm explicitly orderedResults[i].AdultPrice.Should().Be(_newUpdatesForTour1.Body[i].Price + (_newUpdatesForTour1.Body[i].Price * 0.15m) - (_newUpdatesForTour1.Body[i].Price * 0.95m)); orderedResults[i].TourDuration.Should().Be(_newUpdatesForTour1.Body[i].Nights); orderedResults[i].AvailabilityCount.Should().Be(_newUpdatesForTour1.Body[i].Spaces); } }); }
public void Execute() { Assert.DoesNotThrowAsync(async() => { var tourRepository = new TourRepository(); var providerRepository = new ProviderRepository(); var apiDownloader = new Mock <IApiDownloader>(); apiDownloader.Setup(p => p.Download()).ReturnsAsync(_availabilityResponse); var logger = Mock.Of <ILogger>(); var importer = new Importer(tourRepository, providerRepository, apiDownloader.Object, logger); await importer.Execute(1); for (int index = 1; index < 3; index++) { var tour = await tourRepository.Get(index); var availabilities = _tourAvailabilities.Where(p => p.TourId == tour.TourId).ToArray(); Assert.AreEqual(availabilities.Length, tour.Availabilities.Count); for (var i = 0; i < availabilities.Length; i++) { var availability = availabilities[i]; var tourAvailability = tour.Availabilities[i]; Assert.AreEqual(availability.AdultPrice, tourAvailability.AdultPrice); Assert.AreEqual(availability.AvailabilityCount, tourAvailability.AvailabilityCount); Assert.AreEqual(availability.StartDate, tourAvailability.StartDate); Assert.AreEqual(availability.TourDuration, tourAvailability.TourDuration); Assert.AreEqual(availability.TourId, tourAvailability.TourId); } } }); }
public IEnumerable <Tour> GetTours() { return(repository.Get()); }