public static void AssertNoLog(this IBasicLogger logger)
 {
     if (logger == null)
     {
         throw new ArgumentNullException(nameof(logger));
     }
     logger.DidNotReceiveWithAnyArgs().Log(null);
 }
Beispiel #2
0
        public void TestApplyPatches__InvalidOperator()
        {
            UrlDir.UrlConfig config1 = UrlBuilder.CreateConfig(new TestConfigNode("PART")
            {
                { "name", "000" },
                { "aaa", "1" },
            }, file);

            UrlDir.UrlConfig patch1 = new UrlDir.UrlConfig(file, new ConfigNode("%PART"));
            UrlDir.UrlConfig patch2 = new UrlDir.UrlConfig(file, new ConfigNode("|PART"));
            UrlDir.UrlConfig patch3 = new UrlDir.UrlConfig(file, new ConfigNode("#PART"));
            UrlDir.UrlConfig patch4 = new UrlDir.UrlConfig(file, new ConfigNode("*PART"));
            UrlDir.UrlConfig patch5 = new UrlDir.UrlConfig(file, new ConfigNode("&PART"));

            patchList.firstPatches.Add(patch1);
            patchList.firstPatches.Add(patch2);
            patchList.firstPatches.Add(patch3);
            patchList.firstPatches.Add(patch4);
            patchList.firstPatches.Add(patch5);

            patchApplier.ApplyPatches();

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

            logger.DidNotReceive().Log(LogType.Error, Arg.Any <string>());
            logger.DidNotReceiveWithAnyArgs().Exception(null, null);

            logger.Received().Log(LogType.Warning, "Invalid command encountered on a patch: abc/def/%PART");
            logger.Received().Log(LogType.Warning, "Invalid command encountered on a patch: abc/def/|PART");
            logger.Received().Log(LogType.Warning, "Invalid command encountered on a patch: abc/def/#PART");
            logger.Received().Log(LogType.Warning, "Invalid command encountered on a patch: abc/def/*PART");
            logger.Received().Log(LogType.Warning, "Invalid command encountered on a patch: abc/def/&PART");

            UrlDir.UrlConfig[] allConfigs = databaseRoot.AllConfigs.ToArray();
            Assert.Equal(1, allConfigs.Length);

            AssertNodesEqual(new TestConfigNode("PART")
            {
                { "name", "000" },
                { "aaa", "1" },
            }, allConfigs[0].config);
        }
Beispiel #3
0
        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.DidNotReceiveWithAnyArgs().Log(LogType.Log, null);
            logger2.Received().Log(LogType.Log, "Applying update ghi/jkl/@SOME_NODE to abc/def.cfg/SOME_NODE");
        }
        public void TestApplyPatches()
        {
            IBasicLogger   logger       = Substitute.For <IBasicLogger>();
            IPatchProgress progress     = Substitute.For <IPatchProgress>();
            PatchApplier   patchApplier = new PatchApplier(progress, logger);

            UrlDir.UrlFile file1 = UrlBuilder.CreateFile("abc/def.cfg");
            UrlDir.UrlFile file2 = UrlBuilder.CreateFile("ghi/jkl.cfg");
            IPass          pass1 = Substitute.For <IPass>();
            IPass          pass2 = Substitute.For <IPass>();
            IPass          pass3 = Substitute.For <IPass>();

            pass1.Name.Returns(":PASS1");
            pass2.Name.Returns(":PASS2");
            pass3.Name.Returns(":PASS3");

            UrlDir.UrlConfig[] patchUrlConfigs = new UrlDir.UrlConfig[9];
            IPatch[]           patches         = new IPatch[9];
            for (int i = 0; i < patches.Length; i++)
            {
                patches[i] = Substitute.For <IPatch>();
            }

            pass1.GetEnumerator().Returns(new ArrayEnumerator <IPatch>(patches[0], patches[1], patches[2]));
            pass2.GetEnumerator().Returns(new ArrayEnumerator <IPatch>(patches[3], patches[4], patches[5]));
            pass3.GetEnumerator().Returns(new ArrayEnumerator <IPatch>(patches[6], patches[7], patches[8]));

            IPass[] patchList = new IPass[] { pass1, pass2, pass3 };

            patchApplier.ApplyPatches(new[] { file1, file2 }, new[] { pass1, pass2, pass3 });

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

            logger.DidNotReceive().Log(LogType.Warning, Arg.Any <string>());
            logger.DidNotReceive().Log(LogType.Error, Arg.Any <string>());
            logger.DidNotReceiveWithAnyArgs().Exception(null, null);

            Received.InOrder(delegate
            {
                logger.Log(LogType.Log, ":PASS1 pass");
                patches[0].Apply(file1, progress, logger);
                patches[0].Apply(file2, progress, logger);
                progress.PatchApplied();
                patches[1].Apply(file1, progress, logger);
                patches[1].Apply(file2, progress, logger);
                progress.PatchApplied();
                patches[2].Apply(file1, progress, logger);
                patches[2].Apply(file2, progress, logger);
                progress.PatchApplied();
                logger.Log(LogType.Log, ":PASS2 pass");
                patches[3].Apply(file1, progress, logger);
                patches[3].Apply(file2, progress, logger);
                progress.PatchApplied();
                patches[4].Apply(file1, progress, logger);
                patches[4].Apply(file2, progress, logger);
                progress.PatchApplied();
                patches[5].Apply(file1, progress, logger);
                patches[5].Apply(file2, progress, logger);
                progress.PatchApplied();
                logger.Log(LogType.Log, ":PASS3 pass");
                patches[6].Apply(file1, progress, logger);
                patches[6].Apply(file2, progress, logger);
                progress.PatchApplied();
                patches[7].Apply(file1, progress, logger);
                patches[7].Apply(file2, progress, logger);
                progress.PatchApplied();
                patches[8].Apply(file1, progress, logger);
                patches[8].Apply(file2, progress, logger);
                progress.PatchApplied();
            });
        }
        public void TestApplyPatches()
        {
            IBasicLogger   logger       = Substitute.For <IBasicLogger>();
            IPatchProgress progress     = Substitute.For <IPatchProgress>();
            PatchApplier   patchApplier = new PatchApplier(progress, logger);
            IPass          pass1        = Substitute.For <IPass>();
            IPass          pass2        = Substitute.For <IPass>();
            IPass          pass3        = Substitute.For <IPass>();

            pass1.Name.Returns(":PASS1");
            pass2.Name.Returns(":PASS2");
            pass3.Name.Returns(":PASS3");

            UrlDir.UrlConfig[] patchUrlConfigs = new UrlDir.UrlConfig[9];
            IPatch[]           patches         = new IPatch[9];
            for (int i = 0; i < patches.Length; i++)
            {
                patches[i] = Substitute.For <IPatch>();
            }

            patches[0].CountsAsPatch.Returns(false);
            patches[1].CountsAsPatch.Returns(false);
            patches[2].CountsAsPatch.Returns(false);
            patches[3].CountsAsPatch.Returns(true);
            patches[4].CountsAsPatch.Returns(true);
            patches[5].CountsAsPatch.Returns(true);
            patches[6].CountsAsPatch.Returns(true);
            patches[7].CountsAsPatch.Returns(true);
            patches[8].CountsAsPatch.Returns(true);

            pass1.GetEnumerator().Returns(new ArrayEnumerator <IPatch>(patches[0], patches[1], patches[2]));
            pass2.GetEnumerator().Returns(new ArrayEnumerator <IPatch>(patches[3], patches[4], patches[5]));
            pass3.GetEnumerator().Returns(new ArrayEnumerator <IPatch>(patches[6], patches[7], patches[8]));

            IPass[] patchList = new IPass[] { pass1, pass2, pass3 };

            LinkedList <IProtoUrlConfig> databaseConfigs = Assert.IsType <LinkedList <IProtoUrlConfig> >(patchApplier.ApplyPatches(new[] { pass1, pass2, pass3 }));

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

            logger.DidNotReceive().Log(LogType.Warning, Arg.Any <string>());
            logger.DidNotReceive().Log(LogType.Error, Arg.Any <string>());
            logger.DidNotReceiveWithAnyArgs().Exception(null, null);

            Received.InOrder(delegate
            {
                progress.PassStarted(pass1);
                patches[0].Apply(databaseConfigs, progress, logger);
                patches[1].Apply(databaseConfigs, progress, logger);
                patches[2].Apply(databaseConfigs, progress, logger);
                progress.PassStarted(pass2);
                patches[3].Apply(databaseConfigs, progress, logger);
                progress.PatchApplied();
                patches[4].Apply(databaseConfigs, progress, logger);
                progress.PatchApplied();
                patches[5].Apply(databaseConfigs, progress, logger);
                progress.PatchApplied();
                progress.PassStarted(pass3);
                patches[6].Apply(databaseConfigs, progress, logger);
                progress.PatchApplied();
                patches[7].Apply(databaseConfigs, progress, logger);
                progress.PatchApplied();
                patches[8].Apply(databaseConfigs, progress, logger);
                progress.PatchApplied();
            });
        }