Exemple #1
0
        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();
        }
Exemple #2
0
        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();
        }