Esempio n. 1
0
        public void TestApply__LoggerNull()
        {
            EditPatch             patch = new EditPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), Substitute.For <INodeMatcher>(), Substitute.For <IPassSpecifier>());
            ArgumentNullException ex    = Assert.Throws <ArgumentNullException>(delegate
            {
                patch.Apply(UrlBuilder.CreateFile("abc/def.cfg"), Substitute.For <IPatchProgress>(), null);
            });

            Assert.Equal("logger", ex.ParamName);
        }
Esempio n. 2
0
        public void TestApply__ProgressNull()
        {
            EditPatch             patch = new EditPatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), Substitute.For <INodeMatcher>(), Substitute.For <IPassSpecifier>());
            ArgumentNullException ex    = Assert.Throws <ArgumentNullException>(delegate
            {
                patch.Apply(new LinkedList <IProtoUrlConfig>(), null, Substitute.For <IBasicLogger>());
            });

            Assert.Equal("progress", ex.ParamName);
        }
Esempio n. 3
0
        public void TestCompilePatch__Edit()
        {
            ProtoPatch protoPatch = new ProtoPatch(
                UrlBuilder.CreateConfig("ghi/jkl", new TestConfigNode("@NODE")
            {
                { "@bar", "bleh" },
            }),
                Command.Edit,
                "NODE",
                "foo",
                null,
                "#bar",
                Substitute.For <IPassSpecifier>()
                );

            EditPatch patch = Assert.IsType <EditPatch>(patchCompiler.CompilePatch(protoPatch));

            Assert.Same(protoPatch.urlConfig, patch.UrlConfig);
            AssertNodeMatcher(patch.NodeMatcher);

            ConfigNode config = new TestConfigNode("NODE")
            {
                { "name", "foo" },
                { "bar", "baz" },
            };

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

            urlConfig.Node.Returns(config);
            urlConfig.UrlFile.Returns(file);

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

            configs.AddLast(urlConfig);

            patch.Apply(configs, progress, logger);

            AssertNoErrors();

            progress.Received().ApplyingUpdate(urlConfig, protoPatch.urlConfig);

            Assert.Single(configs);
            Assert.NotSame(config, configs.First.Value.Node);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "name", "foo" },
                { "bar", "bleh" },
            }, configs.First.Value.Node);
            Assert.Same(file, configs.First.Value.UrlFile);
        }
Esempio n. 4
0
        public void TestCompilePatch__Edit()
        {
            ProtoPatch protoPatch = new ProtoPatch(
                UrlBuilder.CreateConfig("ghi/jkl", new TestConfigNode("@NODE")
            {
                { "@bar", "bleh" },
            }),
                Command.Edit,
                "NODE",
                "foo",
                null,
                "#bar",
                Substitute.For <IPassSpecifier>()
                );

            EditPatch patch = Assert.IsType <EditPatch>(patchCompiler.CompilePatch(protoPatch));

            Assert.Same(protoPatch.urlConfig, patch.UrlConfig);
            AssertNodeMatcher(patch.NodeMatcher);

            UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig(new TestConfigNode("NODE")
            {
                { "name", "foo" },
                { "bar", "baz" },
            }, file);

            patch.Apply(file, progress, logger);

            AssertNoErrors();

            progress.Received().ApplyingUpdate(urlConfig, protoPatch.urlConfig);

            Assert.Equal(1, file.configs.Count);
            Assert.NotSame(urlConfig, file.configs[0]);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "name", "foo" },
                { "bar", "bleh" },
            }, file.configs[0].config);
        }
Esempio n. 5
0
        public void TestApply()
        {
            UrlDir.UrlFile file = UrlBuilder.CreateFile("abc/def.cfg");

            UrlDir.UrlConfig urlConfig1 = UrlBuilder.CreateConfig(new TestConfigNode("NODE")
            {
                { "foo", "bar" },
            }, file);

            UrlDir.UrlConfig urlConfig2 = UrlBuilder.CreateConfig(new TestConfigNode("NODE")
            {
                { "foo", "bar" },
            }, file);

            UrlDir.UrlConfig urlConfig3 = UrlBuilder.CreateConfig(new ConfigNode("NODE"), file);
            UrlDir.UrlConfig urlConfig4 = UrlBuilder.CreateConfig(new ConfigNode("NODE"), file);

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

            nodeMatcher.IsMatch(urlConfig1.config).Returns(false);
            nodeMatcher.IsMatch(urlConfig2.config).Returns(true);
            nodeMatcher.IsMatch(urlConfig3.config).Returns(false);
            nodeMatcher.IsMatch(urlConfig4.config).Returns(true);

            EditPatch patch = new EditPatch(UrlBuilder.CreateConfig("ghi/jkl", new TestConfigNode("@NODE")
            {
                { "@foo", "baz" },
                { "pqr", "stw" },
            }), nodeMatcher, Substitute.For <IPassSpecifier>());

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

            patch.Apply(file, progress, logger);

            Assert.Equal(4, file.configs.Count);

            Assert.Same(urlConfig1, file.configs[0]);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "foo", "bar" },
            }, file.configs[0].config);

            Assert.NotSame(urlConfig2, file.configs[1]);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "foo", "baz" },
                { "pqr", "stw" },
            }, file.configs[1].config);

            Assert.Same(urlConfig3, file.configs[2]);
            AssertNodesEqual(new ConfigNode("NODE"), file.configs[2].config);

            Assert.NotSame(urlConfig4, file.configs[3]);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "pqr", "stw" },
            }, file.configs[3].config);

            Received.InOrder(delegate
            {
                progress.ApplyingUpdate(urlConfig2, patch.UrlConfig);
                progress.ApplyingUpdate(urlConfig4, 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);
        }
Esempio n. 6
0
        public void TestApply__Loop()
        {
            UrlDir.UrlFile file = UrlBuilder.CreateFile("abc/def.cfg");

            UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig(new TestConfigNode("NODE")
            {
                { "name", "000" },
                { "aaa", "1" },
            }, file);

            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>());

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

            List <UrlDir.UrlConfig> modifiedUrlConfigs = new List <UrlDir.UrlConfig>();

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

            patch.Apply(file, progress, logger);

            Assert.Equal(1, file.configs.Count);
            Assert.NotSame(urlConfig, file.configs[0]);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "name", "000" },
                { "aaa", "16" },
                { "bbb", "002" },
                { "bbb", "002" },
                { "bbb", "002" },
                { "bbb", "002" },
            }, file.configs[0].config);

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

            Received.InOrder(delegate
            {
                logger.Log(LogType.Log, "Looping on ghi/jkl/@NODE to abc/def/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);
        }
Esempio n. 7
0
        public void TestApply()
        {
            UrlDir.UrlFile file = UrlBuilder.CreateFile("abc/def.cfg");

            ConfigNode config1 = new TestConfigNode("NODE")
            {
                { "foo", "bar" },
            };

            ConfigNode config2 = new TestConfigNode("NODE")
            {
                { "foo", "bar" },
            };

            ConfigNode config3 = new ConfigNode("NODE");
            ConfigNode config4 = new ConfigNode("NODE");

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

            nodeMatcher.IsMatch(config1).Returns(false);
            nodeMatcher.IsMatch(config2).Returns(true);
            nodeMatcher.IsMatch(config3).Returns(false);
            nodeMatcher.IsMatch(config4).Returns(true);

            EditPatch patch = new EditPatch(UrlBuilder.CreateConfig("ghi/jkl", new TestConfigNode("@NODE")
            {
                { "@foo", "baz" },
                { "pqr", "stw" },
            }), nodeMatcher, Substitute.For <IPassSpecifier>());

            IProtoUrlConfig urlConfig1 = Substitute.For <IProtoUrlConfig>();
            IProtoUrlConfig urlConfig2 = Substitute.For <IProtoUrlConfig>();
            IProtoUrlConfig urlConfig3 = Substitute.For <IProtoUrlConfig>();
            IProtoUrlConfig urlConfig4 = Substitute.For <IProtoUrlConfig>();

            urlConfig1.Node.Returns(config1);
            urlConfig2.Node.Returns(config2);
            urlConfig3.Node.Returns(config3);
            urlConfig4.Node.Returns(config4);

            urlConfig1.UrlFile.Returns(file);
            urlConfig2.UrlFile.Returns(file);
            urlConfig3.UrlFile.Returns(file);
            urlConfig4.UrlFile.Returns(file);

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

            configs.AddLast(urlConfig1);
            configs.AddLast(urlConfig2);
            configs.AddLast(urlConfig3);
            configs.AddLast(urlConfig4);

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

            patch.Apply(configs, progress, logger);

            IProtoUrlConfig[] newConfigs = configs.ToArray();

            Assert.Equal(4, newConfigs.Length);

            Assert.Same(urlConfig1, newConfigs[0]);
            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "foo", "bar" },
            }, newConfigs[0].Node);

            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "foo", "baz" },
                { "pqr", "stw" },
            }, newConfigs[1].Node);
            Assert.Same(file, newConfigs[1].UrlFile);

            Assert.Same(urlConfig3, newConfigs[2]);
            AssertNodesEqual(new ConfigNode("NODE"), newConfigs[2].Node);

            AssertNodesEqual(new TestConfigNode("NODE")
            {
                { "pqr", "stw" },
            }, newConfigs[3].Node);
            Assert.Same(file, newConfigs[3].UrlFile);

            Received.InOrder(delegate
            {
                progress.ApplyingUpdate(urlConfig2, patch.UrlConfig);
                progress.ApplyingUpdate(urlConfig4, 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);
        }