public static void Main(string[] args) { IHost host = CreateHostBuilder(args).Build(); ITopSellerOperations operations = host.Services.GetRequiredService <ITopSellerOperations>(); CancellationToken token = new CancellationToken(); Parser.Default.ParseArguments <Options>(args). WithParsed(o => { var observable = operations.FetchTopSellers(token, o.WithGarden, o.ForceFetching); observable.Subscribe((result) => { Console.Clear(); if (result.Status != FetchStatus.Skipped) { ConsoleHelper.WriteProgress(result.FetchingProgress); } }, async() => { Console.Clear(); IEnumerable <TopSellers> topSellers = await operations.GetTopSellers(o.WithGarden); ConsoleHelper.WriteTable(topSellers); }); }); host.WaitForShutdown(); }
public async Task TopSellerOperations_FetchTopSellers_OnSuccess_ShouldStore_AndCache( int pages, int resultsPerPage, bool withGarden) { ITopSellerOperations operations = _topSellerOperations(pages, resultsPerPage, false); bool completed = false; List <FetchResponse> responses = new List <FetchResponse>(); Action <FetchResponse> onNext = result => responses.Add(result); Action onComplete = () => completed = true; operations.FetchTopSellers(new CancellationToken(), withGarden).Subscribe(onNext, onComplete); while (!completed) { ; } IEnumerable <TopSellers> topSellers = await operations.GetTopSellers(withGarden); responses.Last().FetchingProgress.Should().Be(100); responses.Last().Status.Should().Be(FetchStatus.APIRetrieve); topSellers.Count().Should().Be(pages); _repository.HasCacheEntry(withGarden, 10).Should().BeTrue(); }
public void TopSellerOperations_FetchTopSellers_OnError_ShouldContainSkippedInFetchResponseList() { int pages = 3; ITopSellerOperations sellerOperations = _topSellerOperations(pages, 1, true); bool completed = false; List <FetchResponse> responses = new List <FetchResponse>(); Action <FetchResponse> onNext = result => responses.Add(result); Action onComplete = () => completed = true; sellerOperations.FetchTopSellers(new CancellationToken(), true) .Subscribe(onNext, onComplete); while (!completed) { ; } responses.Count(x => x.Status == FetchStatus.Skipped).Should().Be(pages - 1); }
public async Task TopSellerOperations_FetchTopSellers_OnSuccess_WhenHasCacheEntry_StatusShouldBeHitCache( bool withGarden) { ITopSellerOperations operations = _topSellerOperations(2, 2, false); List <TopSellers> topSellers = new List <TopSellers>(); topSellers.Add(new TopSellers() { AdsCount = 2, SellerName = "Seller" }); _repository.InsertOrUpdateCacheEntry(withGarden, topSellers); bool completed = false; List <FetchResponse> responses = new List <FetchResponse>(); Action <FetchResponse> onNext = result => responses.Add(result); Action onComplete = () => completed = true; operations.FetchTopSellers(new CancellationToken(), withGarden).Subscribe(onNext, onComplete); while (!completed) { ; } IEnumerable <TopSellers> topSellersFromRepository = await _repository.GetOrCreate(withGarden, 10); responses.First().FetchingProgress.Should().Be(100); responses.First().Status.Should().Be(FetchStatus.HitCache); _repository.HasCacheEntry(withGarden, 10).Should().BeTrue(); topSellersFromRepository.Should().BeEquivalentTo(topSellers); }