private void EnsureNoErrors()
        {
            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.DidNotReceive().Log(LogType.Exception, Arg.Any <string>());
        }
 public static void AssertNoException(this IBasicLogger logger)
 {
     if (logger == null)
     {
         throw new ArgumentNullException(nameof(logger));
     }
     logger.DidNotReceive().Log(Arg.Is <ILogMessage>(msg => msg.LogType == LogType.Exception));
 }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void TestRunTestCases__AllPassing()
        {
            UrlDir.UrlFile file1 = UrlBuilder.CreateFile("abc/blah1.cfg", databaseRoot);
            UrlDir.UrlFile file2 = UrlBuilder.CreateFile("abc/blah2.cfg", databaseRoot);

            ConfigNode testNode1 = new TestConfigNode("NODE1")
            {
                { "key1", "value1" },
                { "key2", "value2" },
                new TestConfigNode("NODE2")
                {
                    { "key3", "value3" },
                },
            };

            ConfigNode testNode2 = new TestConfigNode("NODE3")
            {
                { "key4", "value4" },
            };

            ConfigNode testNode3 = new TestConfigNode("NODE4")
            {
                { "key5", "value5" },
            };

            UrlBuilder.CreateConfig(testNode1, file1);
            UrlBuilder.CreateConfig(testNode2, file1);
            UrlBuilder.CreateConfig(new TestConfigNode("MMTEST_EXPECT")
            {
                testNode1.CreateCopy(),
                testNode2.CreateCopy(),
            }, file1);

            UrlBuilder.CreateConfig(testNode3, file2);
            UrlBuilder.CreateConfig(new TestConfigNode("MMTEST_EXPECT")
            {
                testNode3.CreateCopy(),
            }, file2);

            testRunner.RunTestCases(databaseRoot);

            Received.InOrder(delegate
            {
                logger.Log(LogType.Log, "Running tests...");
                logger.Log(LogType.Log, "tests complete.");
            });

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

            Assert.Empty(file1.configs);
            Assert.Empty(file2.configs);
        }
Ejemplo n.º 5
0
        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();
            });
        }
Ejemplo n.º 6
0
        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();
            });
        }