示例#1
0
        public void TestCreateConfig__Url__FileAlreadyExists()
        {
            UrlDir root = UrlBuilder.CreateRoot();

            ConfigNode node1 = new TestConfigNode("SOME_NODE")
            {
                { "name", "blah" },
                { "foo", "bar" },
            };

            ConfigNode node2 = new TestConfigNode("SOME_OTHER_NODE")
            {
                { "name", "bleh" },
                { "jazz", "hands" },
            };

            UrlDir.UrlConfig config1 = UrlBuilder.CreateConfig("abc/def", node1, root);
            UrlDir.UrlConfig config2 = UrlBuilder.CreateConfig("abc/def", node2, root);

            UrlDir.UrlFile file = config1.parent;
            Assert.NotNull(file);

            Assert.Same(file, config2.parent);

            Assert.Equal("def", file.name);
            Assert.Equal("cfg", file.fileExtension);
            Assert.Equal(UrlDir.FileType.Config, file.fileType);
            Assert.Contains(config1, file.configs);
            Assert.Contains(config2, file.configs);

            UrlDir parent = file.parent;

            Assert.NotNull(parent);
            Assert.Equal("abc", parent.name);
            Assert.Contains(file, parent.files);

            Assert.Contains(parent, root.children);

            Assert.Same(root, file.root);
            Assert.Same(root, parent.root);
            Assert.Same(root, root.root);

            Assert.Contains(config1, root.AllConfigs);
            Assert.Contains(config1, root.GetConfigs("SOME_NODE"));

            Assert.Contains(config2, root.AllConfigs);
            Assert.Contains(config2, root.GetConfigs("SOME_OTHER_NODE"));
        }
        private static List <ConfigNode> GetNodes(UrlDir urlDir, string TypeName)
        {
            List <ConfigNode> l = new List <ConfigNode>();

            using (IEnumerator <UrlDir.UrlConfig> enu = urlDir.GetConfigs(TypeName).GetEnumerator())
            {
                if (enu != null)
                {
                    while (enu.MoveNext())
                    {
                        UrlDir.UrlConfig current = enu.Current;
                        l.Add(current.config);
                    }
                }
            };
            return(l);
        }
示例#3
0
        public void TestCreateConfig__Url()
        {
            ConfigNode node = new TestConfigNode("SOME_NODE")
            {
                { "name", "blah" },
                { "foo", "bar" },
            };

            UrlDir.UrlConfig config = UrlBuilder.CreateConfig("abc/def", node);

            Assert.Equal("SOME_NODE", config.type);
            Assert.Equal("blah", config.name);
            Assert.Same(node, config.config);
            Assert.Equal("abc/def/blah", config.url);

            UrlDir.UrlFile file = config.parent;
            Assert.NotNull(file);
            Assert.Equal("def", file.name);
            Assert.Equal("cfg", file.fileExtension);
            Assert.Equal(UrlDir.FileType.Config, file.fileType);
            Assert.Contains(config, file.configs);

            UrlDir parent = file.parent;

            Assert.NotNull(parent);
            Assert.Equal("abc", parent.name);
            Assert.Contains(file, parent.files);

            UrlDir root = parent.parent;

            Assert.NotNull(root);
            Assert.Equal("root", root.name);
            Assert.Contains(parent, root.children);
            Assert.Null(root.parent);

            Assert.Same(root, file.root);
            Assert.Same(root, parent.root);
            Assert.Same(root, root.root);

            Assert.Contains(config, root.AllConfigs);
            Assert.Contains(config, root.GetConfigs("SOME_NODE"));
        }
示例#4
0
        public void RunTestCases(UrlDir gameDatabaseRoot)
        {
            if (gameDatabaseRoot == null)
            {
                throw new ArgumentNullException(nameof(gameDatabaseRoot));
            }
            logger.Info("Running tests...");

            foreach (UrlDir.UrlConfig expect in gameDatabaseRoot.GetConfigs("MMTEST_EXPECT"))
            {
                // So for each of the expects, we expect all the configs before that node to match exactly.
                UrlDir.UrlFile parent = expect.parent;
                if (parent.configs.Count != expect.config.CountNodes + 1)
                {
                    logger.Error("Test " + parent.name + " failed as expected number of nodes differs expected: " +
                                 expect.config.CountNodes + " found: " + (parent.configs.Count - 1));
                    for (int i = 0; i < parent.configs.Count; ++i)
                    {
                        logger.Info(parent.configs[i].config.ToString());
                    }
                    continue;
                }
                for (int i = 0; i < expect.config.CountNodes; ++i)
                {
                    ConfigNode gotNode    = parent.configs[i].config;
                    ConfigNode expectNode = expect.config.nodes[i];
                    if (!CompareRecursive(expectNode, gotNode))
                    {
                        logger.Error("Test " + parent.name + "[" + i +
                                     "] failed as expected output and actual output differ.\nexpected:\n" + expectNode +
                                     "\nActually got:\n" + gotNode);
                    }
                }

                // Purge the tests
                parent.configs.Clear();
            }
            logger.Info("tests complete.");
        }