コード例 #1
0
ファイル: UrlProcessingTests.cs プロジェクト: ManuelOTuga/PoE
        public static void ClassInitialize(TestContext testContext)
        {
            if (ItemDB.IsEmpty())
            {
                ItemDB.Load("Data/ItemDB/GemList.xml", true);
            }
            _persistentData = new BarePersistentData {
                CurrentBuild = new PoEBuild()
            };
            _persistentData.EquipmentData = EquipmentData.CreateAsync(_persistentData.Options).Result;

            _builds = TestBuildUrlLoader.LoadFromXmlFile("../../TestBuilds/BuildUrls.xml");
            _builds.AddRange(TestBuildUrlLoader.LoadFromXmlFile("../../TestBuilds/EmptyBuildUrls.xml"));

            // This initialization requires a lot of time, so it is reasonable to reuse one instance if possible.
            // However, as some tests may change tree state this field should be used only for methods,
            // that does not depend on a tree instance.
            _tree = SkillTree.CreateAsync(_persistentData).Result;
        }
コード例 #2
0
 private Task <EquipmentData> DeserializeEquipmentDataAsync()
 => EquipmentData.CreateAsync(PersistentData.Options);
コード例 #3
0
 private Task <EquipmentData> DeserializeEquipmentData()
 {
     return(EquipmentData.CreateAsync(PersistentData.Options));
 }
コード例 #4
0
ファイル: TestCharacterSheet.cs プロジェクト: ManuelOTuga/PoE
        public async Task TestBuild()
        {
            // Read build entry.
            string        treeURL       = TestContext.DataRow["TreeURL"].ToString();
            int           level         = Convert.ToInt32(TestContext.DataRow["Level"]);
            string        buildFile     = @"..\..\TestBuilds\" + TestContext.DataRow["BuildFile"].ToString();
            List <string> expectDefense = new List <string>();
            List <string> expectOffense = new List <string>();

            if (TestContext.DataRow.Table.Columns.Contains("ExpectDefence"))
            {
                using (StringReader reader = new StringReader(TestContext.DataRow["ExpectDefence"].ToString()))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        line = line.Trim();
                        if (line.Length > 0 && !line.StartsWith("#"))
                        {
                            expectDefense.Add(line.Trim());
                        }
                    }
                }
            }
            if (TestContext.DataRow.Table.Columns.Contains("ExpectOffence"))
            {
                using (StringReader reader = new StringReader(TestContext.DataRow["ExpectOffence"].ToString()))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        line = line.Trim();
                        if (line.Length > 0 && !line.StartsWith("#"))
                        {
                            expectOffense.Add(line.Trim());
                        }
                    }
                }
            }

            _persistentData.EquipmentData = await EquipmentData.CreateAsync(_persistentData.Options);

            var tree = await SkillTree.CreateAsync(_persistentData, null);

            // Initialize structures.
            tree.LoadFromUrl(treeURL);
            tree.Level = level;

            string         itemData       = File.ReadAllText(buildFile);
            ItemAttributes itemAttributes = new ItemAttributes(_persistentData, itemData);

            Compute.Initialize(tree, itemAttributes);

            // Compare defense properties.
            Dictionary <string, List <string> > defense = new Dictionary <string, List <string> >();

            if (expectDefense.Count > 0)
            {
                foreach (ListGroup grp in Compute.Defense())
                {
                    List <string> props = new List <string>();
                    foreach (string item in grp.Properties.Select(InsertNumbersInAttributes))
                    {
                        props.Add(item);
                    }
                    defense.Add(grp.Name, props);
                }

                List <string> group = null;
                foreach (string entry in expectDefense)
                {
                    if (entry.Contains(':')) // Property: Value
                    {
                        Assert.IsNotNull(group, "Missing defence group [" + TestContext.DataRow["BuildFile"].ToString() + "]");
                        Assert.IsTrue(group.Contains(entry), "Wrong " + entry + " [" + TestContext.DataRow["BuildFile"].ToString() + "]");
                    }
                    else // Group
                    {
                        Assert.IsTrue(defense.ContainsKey(entry), "No such defence group: " + entry + " [" + TestContext.DataRow["BuildFile"].ToString() + "]");
                        group = defense[entry];
                    }
                }
            }

            // Compare offense properties.
            Dictionary <string, List <string> > offense = new Dictionary <string, List <string> >();

            if (expectOffense.Count > 0)
            {
                foreach (ListGroup grp in Compute.Offense())
                {
                    List <string> props = new List <string>();
                    foreach (string item in grp.Properties.Select(InsertNumbersInAttributes))
                    {
                        props.Add(item);
                    }
                    offense.Add(grp.Name, props);
                }

                List <string> group = null;
                foreach (string entry in expectOffense)
                {
                    if (entry.Contains(':')) // Property: Value
                    {
                        Assert.IsNotNull(group, "Missing offence group [" + TestContext.DataRow["BuildFile"].ToString() + "]");
                        Assert.IsTrue(group.Contains(entry), "Wrong " + entry + " [" + TestContext.DataRow["BuildFile"].ToString() + "]");
                    }
                    else // Group
                    {
                        Assert.IsTrue(offense.ContainsKey(entry), "No such offence group: " + entry + " [" + TestContext.DataRow["BuildFile"].ToString() + "]");
                        group = offense[entry];
                    }
                }
            }
        }
コード例 #5
0
        public async Task Build_Test()
        {
            // Read build entry.
            var resultTree = FileEx.GetResource <TestCharacterSheet>("UnitTests.TestBuilds/Builds.xml");
            var xmlFile    = XDocument.Parse(resultTree);
            var build      = XmlHelpers.DeserializeXml <TestBuild>(xmlFile.Root.Element("TestBuild").ToString());

            AbstractPersistentData _persistentData;

            var db = GemDB.LoadFromText(FileEx.GetResource <GemDB>(@"POESKillTree.Data.ItemDB.GemList.xml"));

            _persistentData = new BarePersistentData {
                CurrentBuild = new PoEBuild()
            };


            int           level         = Convert.ToInt32(build.Level);
            List <string> expectDefense = new List <string>();
            List <string> expectOffense = new List <string>();

            using (StringReader reader = new StringReader(build.ExpectDefence))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    line = line.Trim();
                    if (line.Length > 0 && !line.StartsWith("#"))
                    {
                        expectDefense.Add(line.Trim());
                    }
                }
            }

            using (StringReader reader = new StringReader(build.ExpectOffence))
            {
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    line = line.Trim();
                    if (line.Length > 0 && !line.StartsWith("#"))
                    {
                        expectOffense.Add(line.Trim());
                    }
                }
            }

            _persistentData.EquipmentData = await EquipmentData.CreateAsync(_persistentData.Options);

            var tree = await SkillTree.CreateAsync(_persistentData, null);

            // Initialize structures.
            tree.LoadFromUrl(build.TreeUrl);
            tree.Level = level;

            string         itemData       = FileEx.GetResource <TestCharacterSheet>("UnitTests.TestBuilds." + build.BuildFile);
            ItemAttributes itemAttributes = new ItemAttributes(_persistentData, itemData);
            var            Compute        = new Computation(tree, itemAttributes); //failing here because "Staff" isn't recognized.

            // Compare defense properties.
            Dictionary <string, List <string> > defense = new Dictionary <string, List <string> >();

            if (expectDefense.Count > 0)
            {
                foreach (ListGroup grp in Compute.GetDefensiveAttributes())
                {
                    List <string> props = new List <string>();
                    foreach (string item in grp.Properties.Select(InsertNumbersInAttributes))
                    {
                        props.Add(item);
                    }
                    defense.Add(grp.Name, props);
                }

                List <string> group = null;
                foreach (string entry in expectDefense)
                {
                    if (entry.Contains(':')) // Property: Value
                    {
                        Assert.IsNotNull(group, "Missing defence group [" + build.BuildFile + "]");
                        Assert.IsTrue(group.Contains(entry), "Wrong " + entry + " [" + build.BuildFile + "]");
                    }
                    else // Group
                    {
                        Assert.IsTrue(defense.ContainsKey(entry), "No such defence group: " + entry + " [" + build.BuildFile + "]");
                        group = defense[entry];
                    }
                }
            }

            // Compare offense properties.
            Dictionary <string, List <string> > offense = new Dictionary <string, List <string> >();

            if (expectOffense.Count > 0)
            {
                foreach (ListGroup grp in Compute.Offense())
                {
                    List <string> props = new List <string>();
                    foreach (string item in grp.Properties.Select(InsertNumbersInAttributes))
                    {
                        props.Add(item);
                    }
                    offense.Add(grp.Name, props);
                }

                List <string> group = null;
                foreach (string entry in expectOffense)
                {
                    if (entry.Contains(':')) // Property: Value
                    {
                        Assert.IsNotNull(group, "Missing offence group [" + build.BuildFile + "]");
                        Assert.IsTrue(group.Contains(entry), "Wrong " + entry + " [" + build.BuildFile + "]");
                    }
                    else // Group
                    {
                        Assert.IsTrue(offense.ContainsKey(entry), "No such offence group: " + entry + " [" + build.BuildFile + "]");
                        group = offense[entry];
                    }
                }
            }
        }