public void TestUrlConfig() { UrlDir.UrlConfig urlConfig = UrlBuilder.CreateConfig("abc/def", new ConfigNode()); DeletePatch patch = new DeletePatch(urlConfig, Substitute.For <INodeMatcher>(), Substitute.For <IPassSpecifier>()); Assert.Same(urlConfig, patch.UrlConfig); }
public void TestPassSpecifier() { IPassSpecifier passSpecifier = Substitute.For <IPassSpecifier>(); DeletePatch patch = new DeletePatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), Substitute.For <INodeMatcher>(), passSpecifier); Assert.Same(passSpecifier, patch.PassSpecifier); }
public void TestCompilePatch__Delete() { ProtoPatch protoPatch = new ProtoPatch( UrlBuilder.CreateConfig("ghi/jkl", new ConfigNode("-NODE")), Command.Delete, "NODE", "foo", null, "#bar", Substitute.For <IPassSpecifier>() ); DeletePatch patch = Assert.IsType <DeletePatch>(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().ApplyingDelete(urlConfig, protoPatch.urlConfig); Assert.Equal(0, file.configs.Count); }
public void TestApply__LoggerNull() { DeletePatch patch = new DeletePatch(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); }
public void TestApply__ProgressNull() { DeletePatch patch = new DeletePatch(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); }
public void TestApply() { ConfigNode config1 = new ConfigNode("NODE"); ConfigNode config2 = new ConfigNode("NODE"); 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); DeletePatch patch = new DeletePatch(UrlBuilder.CreateConfig("ghi/jkl", new ConfigNode("!NODE")), 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); 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); Assert.Equal(new[] { urlConfig1, urlConfig3 }, configs); Received.InOrder(delegate { progress.ApplyingDelete(urlConfig2, patch.UrlConfig); progress.ApplyingDelete(urlConfig4, patch.UrlConfig); }); progress.DidNotReceiveWithAnyArgs().ApplyingUpdate(null, null); progress.DidNotReceiveWithAnyArgs().ApplyingCopy(null, null); progress.DidNotReceiveWithAnyArgs().Error(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null, null); }
public void TestApply() { UrlDir.UrlFile file = UrlBuilder.CreateFile("abc/def.cfg"); UrlDir.UrlConfig urlConfig1 = UrlBuilder.CreateConfig(new ConfigNode("NODE"), file); UrlDir.UrlConfig urlConfig2 = UrlBuilder.CreateConfig(new ConfigNode("NODE"), 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); DeletePatch patch = new DeletePatch(UrlBuilder.CreateConfig("ghi/jkl", new ConfigNode("!NODE")), nodeMatcher, Substitute.For <IPassSpecifier>()); IPatchProgress progress = Substitute.For <IPatchProgress>(); IBasicLogger logger = Substitute.For <IBasicLogger>(); patch.Apply(file, progress, logger); Assert.Equal(new[] { urlConfig1, urlConfig3 }, file.configs); Received.InOrder(delegate { progress.ApplyingDelete(urlConfig2, patch.UrlConfig); progress.ApplyingDelete(urlConfig4, patch.UrlConfig); }); progress.DidNotReceiveWithAnyArgs().ApplyingUpdate(null, null); progress.DidNotReceiveWithAnyArgs().ApplyingCopy(null, null); progress.DidNotReceiveWithAnyArgs().Error(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null); progress.DidNotReceiveWithAnyArgs().Exception(null, null, null); }
public void TestCompilePatch__Delete() { ProtoPatch protoPatch = new ProtoPatch( UrlBuilder.CreateConfig("ghi/jkl", new ConfigNode("-NODE")), Command.Delete, "NODE", "foo", null, "#bar", Substitute.For <IPassSpecifier>() ); DeletePatch patch = Assert.IsType <DeletePatch>(patchCompiler.CompilePatch(protoPatch)); Assert.Same(protoPatch.urlConfig, patch.UrlConfig); AssertNodeMatcher(patch.NodeMatcher); IProtoUrlConfig urlConfig = Substitute.For <IProtoUrlConfig>(); urlConfig.Node.Returns(new TestConfigNode("NODE") { { "name", "foo" }, { "bar", "baz" }, }); LinkedList <IProtoUrlConfig> configs = new LinkedList <IProtoUrlConfig>(); configs.AddLast(urlConfig); patch.Apply(configs, progress, logger); AssertNoErrors(); progress.Received().ApplyingDelete(urlConfig, protoPatch.urlConfig); Assert.Empty(configs); }
public void TestCountsAsPatch() { DeletePatch patch = new DeletePatch(UrlBuilder.CreateConfig("abc/def", new ConfigNode()), Substitute.For <INodeMatcher>(), Substitute.For <IPassSpecifier>()); Assert.True(patch.CountsAsPatch); }