예제 #1
0
        public async Task ReloadSmash4CharacterAttributeValues()
        {
            //get all attributeTypes in db
            var attributeTypes = LoggedInAdminClient.GetAsync(Baseuri + "/smashattributetypes")
                .Result.Content.ReadAsAsync<List<SmashAttributeType>>().Result;

            var baseUrl = "http://kuroganehammer.com/Smash4/";

            foreach (var attributeType in attributeTypes)
            {
                if (attributeType.Name.Contains("ITEMTOSS") ||
                    attributeType.Name.Equals("LEDGEJUMP") ||
                    attributeType.Name.Equals("TECH") ||
                    attributeType.Name.Equals("AIRDECELERATION") ||
                    attributeType.Name.Equals("AIRFRICTION") ||
                    attributeType.Name.Equals("DASHLENGTH") ||
                    attributeType.Name.Equals("COUNTERS") ||
                    attributeType.Name.Equals("ELEMENTS") ||
                    attributeType.Name.Equals("GETUPOPTIONS") ||
                    attributeType.Name.Equals("REFLECTORS") ||
                    attributeType.Name.Equals("SHIELDS") ||
                    attributeType.Name.Equals("SMASHCHARGERELEASE") ||
                    attributeType.Name.Equals("RUNSPEED"))
                { continue; } //skip these for now since the tables are problematic

                var page = new Page(baseUrl + attributeType.Name);
                Console.WriteLine(attributeType.Name);
                var attributesFromPage = page.GetAttributes();

                var fullAtts = new List<CharacterAttribute>();
                var existingCharacters = LoggedInBasicClient.GetAsync(Baseuri + "/Characters")
                 .Result.Content.ReadAsAsync<List<FrannHammer.Models.Character>>().Result;

                foreach (var attributeRow in attributesFromPage.AttributeValues)
                {
                    var rank = attributeRow.Values.First(a => a.Name.ToLower() == "rank").Value;
                    var characterName = MapCharacterName(attributeRow.Values.First(a => a.Name.ToLower() == "character").Value).Trim();

                    if (string.IsNullOrEmpty(characterName))
                    { continue; } //if no characterName was found there is a high probability this table row was a decorator rather than a real value

                    var specificValues = (from attr in attributeRow.Values.Where(a => a.Name.ToLower() != "rank" &&
                                                                                     a.Name.ToLower() != "character")
                                          select attr).ToList();

                    for (var i = 0; i < specificValues.Count(); i++)
                    {
                        var attributeName = specificValues[i].Name;
                        var dbAttributeType = attributeTypes.Find(a => a.Name.Equals(specificValues[i].AttributeFlag)); //   (CharacterAttributes)Enum.Parse(typeof(CharacterAttributes), specificValues[i].AttributeFlag, true);
                        var value = specificValues[i].Value;
                        Console.WriteLine("characterName: " + characterName);
                        var characterAttribute = new CharacterAttribute
                        {
                            Rank = rank,
                            LastModified = DateTime.Now,
                            Name = attributeName,
                            OwnerId = existingCharacters.First(c => c.Name.Equals(characterName, StringComparison.OrdinalIgnoreCase)).Id,
                            SmashAttributeTypeId = dbAttributeType.Id,
                            Value = value
                        };
                        fullAtts.Add(characterAttribute);

                        var postResult = await LoggedInAdminClient.PostAsJsonAsync(Baseuri + "/characterattributes", characterAttribute);
                        Assert.AreEqual(HttpStatusCode.Created, postResult.StatusCode);
                    }
                    Assert.That(fullAtts.Count > 0);
                }
            }
        }