Exemplo n.º 1
0
        public async Task FetchAllChampions_LoLChampionViewModel_ReturnsAllChampions()
        {
            LoLMetadataViewModel metadata = await LoLAPIUtil.FetchAPIMetadataAsync();

            List <ChampionViewModel> champions = await LoLAPIUtil.FetchAllChampionsAsync(metadata.BaseUrlAPI, metadata.Version);

            Assert.True(champions.Count > 0);
        }
Exemplo n.º 2
0
        public async Task FetchAPIMetadata_BaseUrlAPI_NotEmpty()
        {
            LoLMetadataViewModel metadata = await LoLAPIUtil.FetchAPIMetadataAsync();

            string url = metadata.BaseUrlAPI;

            Assert.NotNull(url);
        }
Exemplo n.º 3
0
        public async Task FetchAPIMetadata_Version_NotEmpty()
        {
            LoLMetadataViewModel metadata = await LoLAPIUtil.FetchAPIMetadataAsync();

            string version = metadata.Version;

            Assert.NotNull(version);
            Assert.Matches(@"\d+.\d+.\d+", version);
        }
Exemplo n.º 4
0
        public async Task FetchAllChampions_LoLChampionViewModel_DoesNotContainMonkeyKing()
        {
            LoLMetadataViewModel metadata = await LoLAPIUtil.FetchAPIMetadataAsync();

            List <ChampionViewModel> champions = await LoLAPIUtil.FetchAllChampionsAsync(metadata.BaseUrlAPI, metadata.Version);

            // Test case where Wukong is named MonkeyKing (shouldn't pass)
            Assert.DoesNotContain(champions, champion => champion.Name == "MonkeyKing");
            Assert.Contains(champions, champion => champion.Name == "Wukong");
        }
Exemplo n.º 5
0
        public async Task FetchAllItemsIds_ItemId_ReturnsAllItemsWithValidIds()
        {
            LoLMetadataViewModel metadata = await LoLAPIUtil.FetchAPIMetadataAsync();

            List <ItemViewModel> items = await LoLAPIUtil.FetchAllItemAsync(metadata.BaseUrlAPI, metadata.Version);

            Assert.True(items.Count > 0);

            // Ensure that we have ID > 0, test with the first element
            Assert.True(items[0].Id > 0);
        }
Exemplo n.º 6
0
        public async Task GetFormattedAPIUrl_Url_IsAPIUrlValid()
        {
            LoLMetadataViewModel metadata = await LoLAPIUtil.FetchAPIMetadataAsync();

            // Test with "champion" as datatype but any other datatype would be same
            string formattedAPIUrl = LoLAPIUtil.GetFormattedAPIUrl(metadata.BaseUrlAPI, metadata.Version, "champion");

            using HttpClient client = new HttpClient();
            var response = await client.GetAsync(formattedAPIUrl);

            Assert.True(response.IsSuccessStatusCode);
            Assert.True(response.Content.Headers.ContentType.MediaType == "application/json");
        }
Exemplo n.º 7
0
        public async Task InitAsync()
        {
            // 1- Fetch metadata
            LoLMetadataViewModel metadata = await LoLAPIUtil.FetchAPIMetadataAsync();

            BaseUrlAPI = metadata.BaseUrlAPI;
            Version    = metadata.Version;

            // 2- Fetch champions and items
            var fetchChampionsTask = LoLAPIUtil.FetchAllChampionsAsync(BaseUrlAPI, Version);
            var fetchItemsTask     = LoLAPIUtil.FetchAllItemAsync(BaseUrlAPI, Version);
            await Task.WhenAll(fetchChampionsTask, fetchItemsTask);

            Champions = fetchChampionsTask.Result;
            Items     = fetchItemsTask.Result;
        }
Exemplo n.º 8
0
        /// <summary>
        /// Returns League of Legends metadata such as version, CDN url, etc.
        /// </summary>
        public static async Task <LoLMetadataViewModel> FetchAPIMetadataAsync()
        {
            using HttpClient client = new HttpClient();

            HttpResponseMessage response = await client.GetAsync("https://ddragon.leagueoflegends.com/realms/na.json");

            response.EnsureSuccessStatusCode();
            string responseBody = await response.Content.ReadAsStringAsync();

            LoLMetadataViewModel metadata = JsonConvert.DeserializeObject <LoLMetadataViewModel>(responseBody);

            if (metadata == null)
            {
                throw new NullReferenceException("Cannot find version from League of Legends API");
            }

            return(metadata);
        }