예제 #1
0
        public async Task GetAllRates_InvokeProxyForEveryCurrency_Simultaneously()
        {
            var case1 = MakeCase(TimeSpan.FromSeconds(1));
            var case2 = MakeCase(TimeSpan.FromSeconds(1));
            var case3 = MakeCase(TimeSpan.FromSeconds(1));

            var currencies = new[] { case1.From, case2.From, case3.From };

            opts.Currencies = currencies;

            var expectedResult = new[] { case1.Response, case2.Response, case3.Response }
            .Select(r => r.ToDomain(opts.Name, currentTime))
            .SelectMany(r => r)
            .ToArray();

            var proxy = new OpenExchangeProxyTest(new [] { case1, case2, case3 });

            var provider = new OpenExchangeRatesProvider(proxy, clock.Object, Options.Create(opts), logger);

            var watch = new Stopwatch();

            watch.Start();
            var result = await provider.GetAllRates();

            watch.Stop();

            // it means that proxy was invoked simultaneously for every currency
            Assert.True(watch.Elapsed < TimeSpan.FromSeconds(3));

            result.Should().BeEquivalentTo(expectedResult);
        }
예제 #2
0
        public async Task GetAllRates_IfSomeRequestsThrowException_TheyWillBeSuppressed()
        {
            var case1 = MakeCase(TimeSpan.FromSeconds(1));
            var case2 = MakeCase(TimeSpan.FromSeconds(1), true);
            var case3 = MakeCase(TimeSpan.FromSeconds(1));

            var currencies = new[] { case1.From, case2.From, case3.From };

            opts.Currencies = currencies;

            var expectedResult = new[] { case1.Response, case3.Response }
            .Select(r => r.ToDomain(opts.Name, currentTime))
            .SelectMany(r => r)
            .ToArray();

            var proxy = new OpenExchangeProxyTest(new [] { case1, case2, case3 });

            var provider = new OpenExchangeRatesProvider(proxy, clock.Object, Options.Create(opts), logger);

            var result = await provider.GetAllRates();

            result.Should().BeEquivalentTo(expectedResult);
        }