public async Task ErrorHandler_ShouldThrowError_For429()
        {
            RiotClientSettings settings = RiotClient.DefaultSettings();

            settings.ThrowOnError             = true;
            settings.RetryOnRateLimitExceeded = false;

            var            eventCount = 0;
            TestRiotClient client     = new TestRiotClient(settings);
            await client.WaitForRetryAfterDelay(); // in case a previous test maxed out the limit

            client.MessageHandler.RespondWithStatus((HttpStatusCode)429);
            client.ConnectionFailed  += (s, e) => { Assert.Fail("Connection failed"); };
            client.RateLimitExceeded += (s, e) => { ++eventCount; };
            client.RequestTimedOut   += (s, e) => { Assert.Fail("Request timed out"); };
            client.ResourceNotFound  += (s, e) => { Assert.Fail("Not found"); };
            client.ResponseError     += (s, e) => { Assert.Fail("Response contained an error"); };
            client.ServerError       += (s, e) => { Assert.Fail("Response contained a server error"); };

            Task <ShardStatus> task = client.GetShardDataAsync();

            Assert.That((AsyncTestDelegate)(() => task), Throws.InstanceOf <RateLimitExceededException>());
            try
            {
                ShardStatus result = await task;
            }
            catch (Exception ex) when(!(ex is AssertionException))
            {
            }
            Assert.That(eventCount, Is.EqualTo(1), "Event was raised wrong number of times.");
        }
        public async Task ErrorHandler_ShouldSuppressRetry_ForConnectionFailure()
        {
            RiotClientSettings settings = RiotClient.DefaultSettings();

            settings.ThrowOnError             = true;
            settings.RetryOnConnectionFailure = true;
            settings.MaxRequestAttempts       = 2;

            var            eventCount = 0;
            TestRiotClient client     = new TestRiotClient(settings);
            await client.WaitForRetryAfterDelay(); // in case a previous test maxed out the limit

            client.MessageHandler.FailConnection();
            client.ConnectionFailed += (s, e) =>
            {
                ++eventCount;
                e.Retry = false;
            };
            client.RequestTimedOut  += (s, e) => { Assert.Fail("Request timed out"); };
            client.ResourceNotFound += (s, e) => { Assert.Fail("Not found"); };
            client.ResponseError    += (s, e) => { Assert.Fail("Response contained an error"); };
            client.ServerError      += (s, e) => { Assert.Fail("Response contained a server error"); };

            try
            {
                ShardStatus result = await client.GetShardDataAsync();
            }
            catch (Exception ex) when(!(ex is AssertionException))
            {
            }
            Assert.That(eventCount, Is.EqualTo(1), "Event was raised wrong number of times.");
        }
        public async Task ErrorHandler_ShouldSuppressRetry_ForTimeout_WithEventHandler()
        {
            RiotClientSettings settings = RiotClient.DefaultSettings();

            settings.ThrowOnError       = true;
            settings.RetryOnTimeout     = true;
            settings.MaxRequestAttempts = 2;

            var            eventCount = 0;
            TestRiotClient client     = new TestRiotClient(settings);

            client.Client.Timeout = TimeSpan.FromMilliseconds(1);

            client.MessageHandler.Delay(500);
            client.ConnectionFailed += (s, e) => { Assert.Fail("Connection failed"); };
            client.RequestTimedOut  += (s, e) =>
            {
                ++eventCount;
                e.Retry = false;
            };
            client.ResourceNotFound += (s, e) => { Assert.Fail("Not found"); };
            client.ResponseError    += (s, e) => { Assert.Fail("Response contained an error"); };
            client.ServerError      += (s, e) => { Assert.Fail("Response contained a server error"); };

            try
            {
                ShardStatus result = await client.GetShardDataAsync();
            }
            catch (Exception ex) when(!(ex is AssertionException))
            {
            }
            Assert.That(eventCount, Is.EqualTo(1), "Event was raised wrong number of times.");
        }
        public async Task ErrorHandler_ShouldReturnNull_For400()
        {
            RiotClientSettings settings = RiotClient.DefaultSettings();

            settings.ThrowOnError = false;

            var            eventCount = 0;
            TestRiotClient client     = new TestRiotClient(settings);
            await client.WaitForRetryAfterDelay(); // in case a previous test maxed out the limit

            client.MessageHandler.RespondWithStatus(HttpStatusCode.BadRequest);
            client.ConnectionFailed += (s, e) => { Assert.Fail("Connection failed"); };
            client.RequestTimedOut  += (s, e) => { Assert.Fail("Request timed out"); };
            client.ResourceNotFound += (s, e) => { Assert.Fail("Not found"); };
            client.ResponseError    += (s, e) => { ++eventCount; };
            client.ServerError      += (s, e) => { Assert.Fail("Response contained a server error"); };

            ShardStatus result = await client.GetShardDataAsync();

            Assert.That(result, Is.Null);
            Assert.That(eventCount, Is.EqualTo(1), "Event was raised wrong number of times.");
        }