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_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_ShouldRetry_ForTimeout_IfCancelled()
        {
            RiotClientSettings settings = RiotClient.DefaultSettings();

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

            var         eventCount = 0;
            IRiotClient client     = new RiotClient(settings, PlatformId.NA1);

            client.ConnectionFailed += (s, e) => { Assert.Fail("Connection failed"); };
            client.RequestTimedOut  += (s, e) => { ++eventCount; };
            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"); };

            var cts = new CancellationTokenSource();
            Task <ShardStatus> task = client.GetShardDataAsync(token: cts.Token);

            cts.Cancel();

            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_ShouldReturnNull_ForTimeout()
        {
            RiotClientSettings settings = RiotClient.DefaultSettings();

            settings.RetryOnTimeout = false;
            settings.ThrowOnError   = false;

            var         eventCount = 0;
            IRiotClient client     = new RiotClient(settings, PlatformId.NA1);

            client.ConnectionFailed += (s, e) => { Assert.Fail("Connection failed"); };
            client.RequestTimedOut  += (s, e) => { ++eventCount; };
            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"); };

            var cts = new CancellationTokenSource();
            Task <ShardStatus> task = client.GetShardDataAsync(token: cts.Token);

            cts.Cancel();

            ShardStatus result = await task;

            Assert.That(result, Is.Null);
            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.");
        }
示例#6
0
        public async Task Return_Correct_Region_Status(Region region)
        {
            ShardStatus status = await RiotAPI.Status.GetRegionStatus(region);

            Check.That(status).IsNotNull();
            Check.That(status.Services).IsNotEmpty();
            Check.That(status.Locales).IsNotEmpty();
        }
示例#7
0
 public void Parse(System.Xml.XmlElement element)
 {
     this.Name   = element.ReadTextNode("Name");
     this.Rank   = int.Parse(element.ReadTextNode("Rank"));
     this.Map    = element.ReadTextNode("Map");
     this.Status = (ShardStatus)Enum.Parse(typeof(ShardStatus), element.ReadTextNode("Status"));
     this.Id     = int.Parse(element.ReadTextNode("Id"));
 }
示例#8
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            List <object> parameters = ((List <object>)e.Parameter);

            shardStatus = (ShardStatus)parameters[0];
            LoadStatus();
            justLoaded = false;
        }
示例#9
0
        public void DeserializeShardStatusTest()
        {
            ShardStatus shard = JsonConvert.DeserializeObject <ShardStatus>(Resources.SampleShardStatus, RiotClient.JsonSettings);

            AssertNonDefaultValuesRecursive(shard);
            Incident incident = shard.Services.First().Incidents.First();

            Assert.That(incident.CreatedAt, Is.EqualTo(new DateTime(2015, 7, 19, 2, 23, 10, DateTimeKind.Utc)));
        }
示例#10
0
        private async void statusButton_Click(object sender, RoutedEventArgs e)
        {
            ShardStatus shardStatus = await AppConstants.creepScore.RetrieveShardStatus(AppConstants.preferredRegion);

            List <object> parameters = new List <object>();

            parameters.Add(shardStatus);
            Frame.Navigate(typeof(StatusPage), parameters);
        }
示例#11
0
        public async Task GetShardDataAsyncTest_WithClientPlatformId()
        {
            IRiotClient client = RiotClient.ForPlatform(PlatformId.LA2);
            ShardStatus shard  = await client.GetShardDataAsync();

            Assert.That(shard, Is.Not.Null);
            Assert.That(shard.Name, Is.EqualTo("Latin America South"));
            Assert.That(shard.Slug, Is.EqualTo("las"));
            Assert.That(shard.RegionTag, Is.EqualTo("la2"));
        }
示例#12
0
        public async Task GetShardDataAsyncTest_WithPlatformIdParameter()
        {
            IRiotClient client = new RiotClient();
            ShardStatus shard  = await client.GetShardDataAsync(PlatformId.KR);

            Assert.That(shard, Is.Not.Null);
            Assert.That(shard.Name, Is.EqualTo("Republic of Korea"));
            Assert.That(shard.Slug, Is.EqualTo("kr"));
            Assert.That(shard.RegionTag, Is.EqualTo("kr1"));
        }
示例#13
0
        public async Task GetShardStatusAsyncTest()
        {
            RiotClient.DefaultPlatformId = PlatformId.EUN1;
            IRiotClient client = new RiotClient();
            ShardStatus shard  = await client.GetShardStatusAsync();

            Assert.That(shard, Is.Not.Null);
            Assert.That(shard.Name, Is.EqualTo("EU Nordic & East"));
            Assert.That(shard.Slug, Is.EqualTo("eune"));
            Assert.That(shard.RegionTag, Is.EqualTo("eun1"));
            Assert.That(shard.Hostname, Is.Not.Null.And.Not.Empty);
            Assert.That(shard.Services, Is.Not.Null.And.Not.Empty);
            Assert.That(shard.Locales, Is.Not.Null.And.Not.Empty);
        }
        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.");
        }
示例#15
0
 /// <summary>
 /// Arguments used to create a <see cref="Shard"/>.
 /// </summary>
 /// <param name="location">Location of the shard.</param>
 /// <param name="status">Status of the shard.</param>
 internal ShardCreationInfo(ShardLocation location, ShardStatus status)
 {
     ExceptionUtils.DisallowNullArgument(location, "location");
     this.Location = location;
     this.Status   = status;
 }
示例#16
0
        async void RefreshStatus(CreepScore.Region region)
        {
            shardStatus = await AppConstants.creepScore.RetrieveShardStatus(region);

            LoadStatus();
        }
示例#17
0
        public async void RetrieveShardStatusTest()
        {
            ShardStatus shardStatus = await creepScore.RetrieveShardStatus(CreepScore.Region.NA);

            Assert.Equal("North America", shardStatus.name);
        }