public async Task GetJson_BreakLimit()
        {
            BlizzardApiConfiguration config = BlizzardApiReaderTests.DefaultConfig.Clone();

            config.Limiter = new List <Limiter>
            {
                new Limiter {
                    RatesPerTimespan = 10, TimeBetweenLimitReset = new TimeSpan(0, 0, 5)
                },
            };
            WebClientMocker webClient = new WebClientMocker();

            webClient.SetupAuth(true);
            webClient.SetupApiRequest(It.IsAny <string>(), HttpStatusCode.OK, JsonSerializer.Serialize(ExpectedJson));
            BlizzardApiReader api = new BlizzardApiReader(Options.Create(config), webClient.WebClient);

            List <Exception> exceptions = new List <Exception>();
            int count = config.Limiter.First().RatesPerTimespan;

            for (int i = 0; i < count + 1; i++)
            {
                Exception ex = await Record.ExceptionAsync(() => api.GetAsync <RealmJson>("test", Namespace.Static)).ConfigureAwait(false);

                if (ex != null)
                {
                    exceptions.Add(ex);
                }
            }
            Assert.Single(exceptions);
            Assert.IsType <RateLimitReachedException>(exceptions.First());
            webClient.VerifyAuth(Times.Once());
            webClient.VerifyApiRequest(It.IsAny <string>(), Times.Exactly(count));
        }
        public async Task GetJson_ApiFailed()
        {
            WebClientMocker webClient = new WebClientMocker();

            webClient.SetupAuth(true);
            webClient.SetupApiRequest(It.IsAny <string>(), HttpStatusCode.InternalServerError, JsonSerializer.Serialize(ExpectedJson));
            BlizzardApiReader api = new BlizzardApiReader(BlizzardApiReaderTests.DefaultConfiguration, webClient.WebClient);

            await Assert.ThrowsAsync <BadResponseException>(() => api.GetAsync <RealmJson>("test", Namespace.Static)).ConfigureAwait(false);

            webClient.VerifyAuth(Times.Once());
            webClient.VerifyApiRequest(It.IsAny <string>(), Times.Once());
        }
        public async Task GetJson_Valid()
        {
            WebClientMocker webClient = new WebClientMocker();

            webClient.SetupAuth(true);
            webClient.SetupApiRequest(It.IsAny <string>(), HttpStatusCode.OK, JsonSerializer.Serialize(ExpectedJson));
            BlizzardApiReader api = new BlizzardApiReader(BlizzardApiReaderTests.DefaultConfiguration, webClient.WebClient);

            RealmJson jsonResult = await api.GetAsync <RealmJson>("test", Namespace.Static).ConfigureAwait(false);

            Assert.True(ExpectedJson.IsClone(jsonResult));
            webClient.VerifyAuth(Times.Once());
            webClient.VerifyApiRequest(It.IsAny <string>(), Times.Once());
        }
示例#4
0
        public async Task GetJson_Valid()
        {
            WebClientMocker webClient = new WebClientMocker();

            webClient.SetupAuth(true);
            webClient.SetupApiRequest(It.IsAny <string>(), HttpStatusCode.OK, ExpectedJson);
            BlizzardApiReader api = new BlizzardApiReader(BlizzardApiReaderTests.DefaultConfiguration, webClient.WebClient);

            string jsonResult = await api.GetJsonAsync("test").ConfigureAwait(false);

            Assert.Equal(ExpectedJson, jsonResult);
            webClient.VerifyAuth(Times.Once());
            webClient.VerifyApiRequest(It.IsAny <string>(), Times.Once());
        }