Exemplo n.º 1
0
        public void GenerateRaiderIOApiRequestLink_WhenGenerateLink_ShouldGenerateValidLinkForRadierIO()
        {
            //Arrange
            string expectedLink = "https://raider.io/api/v1/characters/profile?region=eu&realm=burning-legion&name=wykminiacz&fields=mythic_plus_best_runs%2Cmythic_plus_ranks";

            RequestLocalization requestLocalization = new RequestLocalization()
            {
                CoreRegionUrlAddress = APIConf.RaiderIOAdress,
                Realm = new Realm()
                {
                    Slug = "burning-legion", Locale = "en_GB", Timezone = "Europe/Paris"
                }
            };

            List <RaiderIOCharacterFields> characterFields = new List <RaiderIOCharacterFields>()
            {
                RaiderIOCharacterFields.MythicPlusBestRuns,
                RaiderIOCharacterFields.MythicPlusRanks
            };

            string region = requestLocalization.Realm.Timezone == "Europe/Paris" ? "eu" : throw new Exception("Chosen realm is not European");


            string localFields = string.Empty;

            foreach (RaiderIOCharacterFields field in characterFields)
            {
                string wrappedField = EnumDictionaryWrapper.rioCharacterFieldWrapper[field];
                localFields = localFields.AddFieldToUrl(wrappedField);

                localFields = localFields.EndsWith("+") ? localFields.Remove(localFields.Length - 1, 1)
                                       : localFields;
            }

            localFields = localFields.EndsWith("%2C") ? localFields.Remove(localFields.Length - 3, 3) // remove join parameters symbol at ending field
                                                       : localFields;

            List <KeyValuePair <string, string> > fields = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("fields", localFields)
            };

            List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>(RaiderIOCharacterParams.Region.ToString(), region),
                new KeyValuePair <string, string>(RaiderIOCharacterParams.Realm.ToString(), requestLocalization.Realm.Slug),
                new KeyValuePair <string, string>(RaiderIOCharacterParams.Name.ToString(), "Wykminiacz")
            };

            //Act
            Uri actualLink = RequestLinkFormater.GenerateRaiderIOApiRequestLink(fields, parameters);

            //Assert
            Assert.Equal(expectedLink, actualLink.AbsoluteUri);
        }
        internal async Task <RaiderIOAPIResponse> GetRaiderIODataAsync(string characterName, RequestLocalization requestLocalization, List <RaiderIOCharacterFields> characterFields)
        {
            string region = requestLocalization.Realm.Timezone == "Europe/Paris" ? "eu" : throw new Exception("Choosed realm is not European");

            List <KeyValuePair <string, string> > fields = new List <KeyValuePair <string, string> >();

            List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>(RaiderIOCharacterParams.Region.ToString(), region),
                new KeyValuePair <string, string>(RaiderIOCharacterParams.Realm.ToString(), requestLocalization.Realm.Slug),
                new KeyValuePair <string, string>(RaiderIOCharacterParams.Name.ToString(), characterName)
            };

            // check if there is any additional parameters to get. If not - just return basic informations
            if (characterFields.Any())
            {
                string localFields = string.Empty;

                foreach (RaiderIOCharacterFields field in characterFields)
                {
                    string wrappedField = EnumDictionaryWrapper.rioCharacterFieldWrapper[field];
                    localFields = localFields.AddFieldToUrl(wrappedField);

                    localFields = localFields.EndsWith("+") ? localFields.Remove(localFields.Length - 1, 1)
                                           : localFields;
                }

                localFields = localFields.EndsWith("%2C") ? localFields.Remove(localFields.Length - 3, 3) // remove join parameters symbol at ending field
                                                           : localFields;

                fields.Add(new KeyValuePair <string, string>("fields", localFields));
            }

            Uri uriAddress = RequestLinkFormater.GenerateRaiderIOApiRequestLink(fields, parameters);

            return(await new APIDataRequestManager(_comparerDatabaseContext).GetDataByHttpRequest <RaiderIOAPIResponse>(uriAddress));
        }