Exemple #1
0
        public void TestRunTestCases__WrongNumberOfNodes()
        {
            UrlDir.UrlFile file1 = UrlBuilder.CreateFile("abc/blah1.cfg", databaseRoot);

            // Call CreateCopy otherwise XUnit sees that it's an IEnumerable and attempts to compare by enumeration
            ConfigNode testNode1 = new TestConfigNode("NODE1")
            {
                { "key1", "value1" },
            }.CreateCopy();

            ConfigNode testNode2 = new ConfigNode("NODE2");

            ConfigNode expectNode = new TestConfigNode("MMTEST_EXPECT")
            {
                new TestConfigNode("NODE1")
                {
                    { "key1", "value1" },
                },
            }.CreateCopy();

            UrlBuilder.CreateConfig(testNode1, file1);
            UrlBuilder.CreateConfig(testNode2, file1);
            UrlBuilder.CreateConfig(expectNode, file1);

            testRunner.RunTestCases(databaseRoot);

            Received.InOrder(delegate
            {
                logger.AssertInfo("Running tests...");
                logger.AssertError($"Test blah1 failed as expected number of nodes differs expected: 1 found: 2");
                logger.AssertInfo(testNode1.ToString());
                logger.AssertInfo(testNode2.ToString());
                logger.AssertInfo(expectNode.ToString());
                logger.AssertInfo("tests complete.");
            });

            Assert.Equal(3, file1.configs.Count);
            Assert.Equal(testNode1, file1.configs[0].config);
            Assert.Equal(testNode2, file1.configs[1].config);
            Assert.Equal(expectNode, file1.configs[2].config);
        }
        public void Test__Constructor__Nested()
        {
            IBasicLogger  logger2   = Substitute.For <IBasicLogger>();
            PatchProgress progress2 = new PatchProgress(progress, logger2);

            Assert.Same(progress.Counter, progress2.Counter);

            Assert.Equal(0, progress.Counter.patchedNodes);

            IProtoUrlConfig original = Substitute.For <IProtoUrlConfig>();

            original.FullUrl.Returns("abc/def.cfg/SOME_NODE");
            UrlDir.UrlConfig patch1 = UrlBuilder.CreateConfig("ghi/jkl", new ConfigNode("@SOME_NODE"));

            progress2.ApplyingUpdate(original, patch1);
            Assert.Equal(1, progress.Counter.patchedNodes);
            logger.AssertNoLog();
            logger2.AssertInfo("Applying update ghi/jkl/@SOME_NODE to abc/def.cfg/SOME_NODE");
        }
        public void TestApplyingUpdate()
        {
            IProtoUrlConfig original = Substitute.For <IProtoUrlConfig>();

            original.FullUrl.Returns("abc/def.cfg/SOME_NODE");
            UrlDir.UrlConfig patch1 = UrlBuilder.CreateConfig("ghi/jkl", new ConfigNode("@SOME_NODE"));
            UrlDir.UrlConfig patch2 = UrlBuilder.CreateConfig("pqr/stu", new ConfigNode("@SOME_NODE"));

            Assert.Equal(0, progress.Counter.patchedNodes);

            progress.ApplyingUpdate(original, patch1);
            Assert.Equal(1, progress.Counter.patchedNodes);
            logger.AssertInfo("Applying update ghi/jkl/@SOME_NODE to abc/def.cfg/SOME_NODE");

            progress.ApplyingUpdate(original, patch2);
            Assert.Equal(2, progress.Counter.patchedNodes);
            logger.AssertInfo("Applying update pqr/stu/@SOME_NODE to abc/def.cfg/SOME_NODE");
        }
 public void TestInfo()
 {
     logger.Info("well hi there");
     logger.AssertInfo("well hi there");
 }
Exemple #5
0
        public void TestApply__Loop()
        {
            UrlDir.UrlFile file = UrlBuilder.CreateFile("abc/def.cfg");

            ConfigNode config = new TestConfigNode("NODE")
            {
                { "name", "000" },
                { "aaa", "1" },
            };

            INodeMatcher nodeMatcher = Substitute.For <INodeMatcher>();

            nodeMatcher.IsMatch(Arg.Is <ConfigNode>(node => int.Parse(node.GetValue("aaa")) < 10)).Returns(true);

            EditPatch patch = new EditPatch(UrlBuilder.CreateConfig("ghi/jkl", new TestConfigNode("@NODE")
            {
                { "@aaa *", "2" },
                { "bbb", "002" },
                new ConfigNode("MM_PATCH_LOOP"),
            }), nodeMatcher, Substitute.For <IPassSpecifier>());

            IProtoUrlConfig urlConfig = Substitute.For <IProtoUrlConfig>();

            urlConfig.Node.Returns(config);
            urlConfig.UrlFile.Returns(file);
            urlConfig.FullUrl.Returns("abc/def.cfg/NODE");

            LinkedList <IProtoUrlConfig> configs = new LinkedList <IProtoUrlConfig>();

            configs.AddLast(urlConfig);

            IPatchProgress progress = Substitute.For <IPatchProgress>();
            IBasicLogger   logger   = Substitute.For <IBasicLogger>();

            List <IProtoUrlConfig> modifiedUrlConfigs = new List <IProtoUrlConfig>();

            progress.ApplyingUpdate(Arg.Do <IProtoUrlConfig>(url => modifiedUrlConfigs.Add(url)), patch.UrlConfig);

            patch.Apply(configs, progress, logger);

            Assert.Single(configs);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "name", "000" },
                { "aaa", "16" },
                { "bbb", "002" },
                { "bbb", "002" },
                { "bbb", "002" },
                { "bbb", "002" },
            }, configs.First.Value.Node);
            Assert.Same(file, configs.First.Value.UrlFile);

            Assert.Same(urlConfig, modifiedUrlConfigs[0]);
            Assert.NotSame(urlConfig, modifiedUrlConfigs[1]);
            Assert.NotSame(urlConfig, modifiedUrlConfigs[2]);
            Assert.NotSame(urlConfig, modifiedUrlConfigs[3]);

            Received.InOrder(delegate
            {
                logger.AssertInfo("Looping on ghi/jkl/@NODE to abc/def.cfg/NODE");
                progress.ApplyingUpdate(urlConfig, patch.UrlConfig);
                progress.ApplyingUpdate(modifiedUrlConfigs[1], patch.UrlConfig);
                progress.ApplyingUpdate(modifiedUrlConfigs[2], patch.UrlConfig);
                progress.ApplyingUpdate(modifiedUrlConfigs[3], patch.UrlConfig);
            });

            progress.DidNotReceiveWithAnyArgs().ApplyingCopy(null, null);
            progress.DidNotReceiveWithAnyArgs().ApplyingDelete(null, null);

            progress.DidNotReceiveWithAnyArgs().Error(null, null);
            progress.DidNotReceiveWithAnyArgs().Exception(null, null);
            progress.DidNotReceiveWithAnyArgs().Exception(null, null, null);
        }