コード例 #1
0
        public async Task Check_BrokenLimit()
        {
            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);
            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.Check()).ConfigureAwait(false);

                if (ex != null)
                {
                    exceptions.Add(ex);
                }
            }
            Assert.Single(exceptions);
            Assert.IsType <RateLimitReachedException>(exceptions.First());
            webClient.VerifyAuth(Times.Once());
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        public async Task Check_FailAuth()
        {
            WebClientMocker webClient = new WebClientMocker();

            webClient.SetupAuth(false);
            BlizzardApiReader api = new BlizzardApiReader(BlizzardApiReaderTests.DefaultConfiguration, webClient.WebClient);
            await Assert.ThrowsAsync <HttpRequestException>(() => api.Check());

            webClient.VerifyAuth(Times.Once());
        }
コード例 #4
0
        public async Task Check_SuccessAuth()
        {
            WebClientMocker webClient = new WebClientMocker();

            webClient.SetupAuth(true);
            BlizzardApiReader api = new BlizzardApiReader(BlizzardApiReaderTests.DefaultConfiguration, webClient.WebClient);
            Exception         ex  = await Record.ExceptionAsync(() => api.Check()).ConfigureAwait(false);

            Assert.Null(ex);
            webClient.VerifyAuth(Times.Once());
        }
コード例 #5
0
        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());
        }
コード例 #6
0
        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());
        }
コード例 #7
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());
        }