public void UseCase3_TFSBuildToolSampleArguments()
        {
            b.Info.Log("Starting UseCase3 - TBuildtool Sample UseCase");

            var argsupport = new CommandArgumentSupport();

            argsupport.ArgumentPrefix  = "-";
            argsupport.ArgumentPostfix = "=";
            TFSBuildToolArgs parsedArgs = new TFSBuildToolArgs();

            string[] expectedArguments = new string[] { "-tfs=http://appsd1011:8080", "-teamproject=Acme", "-builddefinition=BuildTasks_CERTIFIED", "-agenturi=wks3090852" };
            argsupport.ProcessArguments(parsedArgs, expectedArguments);

            Assert.Equal("wks3090852", parsedArgs.agentUri);
            Assert.Equal("BuildTasks_CERTIFIED", parsedArgs.buildDefinition);
            Assert.Equal("http://appsd1011:8080", parsedArgs.tfs);
            Assert.Equal("Acme", parsedArgs.teamProject);

            expectedArguments[3] = "-agent=wks3090852";  // Test alternative parameter naming.
            parsedArgs           = new TFSBuildToolArgs();

            argsupport.ProcessArguments(parsedArgs, expectedArguments);

            Assert.Equal("wks3090852", parsedArgs.agentUri);
            Assert.Equal("BuildTasks_CERTIFIED", parsedArgs.buildDefinition);
            Assert.Equal("http://appsd1011:8080", parsedArgs.tfs);
            Assert.Equal("Acme", parsedArgs.teamProject);
        }
        public void TFSUseCaseOptionalPrefix()
        {
            var tcc1 = new Kev_TFS_UseCase();
            var tcc2 = new Kev_TFS_UseCase();
            var clas = new CommandArgumentSupport();

            string[] expectedArgs = new string[] {
                "/BUILDNAME:TFSSupport_DevDesktopPack_Main_Certified_20090423.8",
                "/ATTACHMENT:\"c:\\temp\\list.txt\""
            };

            string[] expectedArgs2 = new string[] {
                "BUILDNAME:TFSSupport_DevDesktopPack_Main_Certified_20090423.8",
                "ATTACHMENT:\"c:\\temp\\list.txt\""
            };

            clas.ArgumentPrefix         = "/";
            clas.ArgumentPostfix        = ":";
            clas.ArgumentPrefixOptional = true;

            clas.ProcessArguments(tcc1, expectedArgs);
            clas.ProcessArguments(tcc2, expectedArgs2);

            Assert.Equal("TFSSupport_DevDesktopPack_Main_Certified_20090423.8", tcc1.BuildName);
            Assert.Equal("\"c:\\temp\\list.txt\"", tcc1.Attachment);

            Assert.Equal(tcc1.BuildName, tcc2.BuildName);
            Assert.Equal(tcc1.Attachment, tcc2.Attachment);
        }
        [Trait(Traits.Style, Traits.Regression)] // Legacy Tests, replace when working on them.
        public void BasicTest_BooleanParameters()
        {
            b.Info.Log("Starting  Testing boolean behaviour");

            var sc1 = new SampleCommandLine_C1();
            var sc2 = new SampleCommandLine_C1();
            var sc3 = new SampleCommandLine_C1();

            VerifySampleCommandLine1_InitialState(sc1);
            VerifySampleCommandLine1_InitialState(sc2);
            VerifySampleCommandLine1_InitialState(sc3);

            string[] argsBothTrue  = new string[] { "/OP1", "/OP2" };
            string[] argsBothTrue2 = new string[] { "/OP1true", "/OP2TRUE" };
            string[] argsBothTrue3 = new string[] { "/OP1YES", "/OP2y" };

            CommandArgumentSupport clas = new CommandArgumentSupport();

            clas.ArgumentPrefix = "/";
            clas.ProcessArguments(sc1, argsBothTrue);

            Assert.True(sc1.OptionParameterOne);
            Assert.True(sc1.OptionParameterTwo);

            clas.ProcessArguments(sc2, argsBothTrue2);
            clas.ProcessArguments(sc3, argsBothTrue3);

            Assert.Equal(sc1.OptionParameterOne, sc2.OptionParameterOne);
            Assert.Equal(sc1.OptionParameterTwo, sc2.OptionParameterTwo);
            Assert.Equal(sc1.OptionParameterOne, sc3.OptionParameterOne);
            Assert.Equal(sc1.OptionParameterTwo, sc3.OptionParameterTwo);

            string[] argsBothFalse  = new string[] { "/OP1false", "/OP2no" };
            string[] argsBothFalse2 = new string[] { "/OP1N", "/OP2False" };

            sc1.OptionParameterOne = true;
            sc1.OptionParameterTwo = true;
            clas.ProcessArguments(sc1, argsBothFalse);

            Assert.False(sc1.OptionParameterOne);
            Assert.False(sc1.OptionParameterTwo);

            sc1.OptionParameterOne = true;
            sc1.OptionParameterTwo = true;
            clas.ProcessArguments(sc1, argsBothFalse2);

            Assert.False(sc1.OptionParameterOne);
            Assert.False(sc1.OptionParameterTwo);
        }
        [Trait(Traits.Style, Traits.Regression)] // Legacy Tests, replace when working on them.
        public void BasicTest_NumberStringAndBoolParams()
        {
            b.Info.Log("Starting test for SimpleArguments");

            const string STRINGPAR1 = "StringParameter1";
            const string STRINGPAR2 = "StrnigParameter2";
            const int    NUMVALUE   = 12;
            var          sc1        = new SampleCommandLine_C1();

            VerifySampleCommandLine1_InitialState(sc1);

            string[] args = new string[] { "/N:" + STRINGPAR1, "/A:" + STRINGPAR2, "/C:" + NUMVALUE.ToString(), "/OP1" };

            var clas = new CommandArgumentSupport();

            clas.ArgumentPrefix = "/";

            clas.ProcessArguments(sc1, args);

            Assert.Equal(STRINGPAR1, sc1.NameParameterOne);
            Assert.Equal(STRINGPAR2, sc1.NameParameterTwo);

            Assert.True(sc1.OptionParameterOne, "Boolean parameter one failed");
            Assert.False(sc1.OptionParameterTwo, "Boolean argument two failed");

            Assert.Equal(12, sc1.NumberParameterOne);
            Assert.Equal(0, sc1.NumberParameterTwo);
        }
        [Trait(Traits.Style, "exploratory")] // Legacy Tests, replace when working on them.
        public void Basic_ArrayOfStrs_Works()
        {
            var clas = new CommandArgumentSupport {
                ArgumentPostfix        = ":",
                ArgumentPrefix         = "",
                ArgumentPrefixOptional = true
            };

            string[] parms = new string[] { "one", "two", "three", "four", "five" };

            string strArrayConcat = "";

            foreach (var f in parms)
            {
                strArrayConcat += f + ",";
            }


            var argsClass = new SampleCommandLine_C3();

            string[] args = new string[] {
                $"StrArray:{strArrayConcat}",
            };
            clas.ProcessArguments(argsClass, args);

            Assert.Equal(parms.Length, argsClass.StrArray.Length);
            for (int i = 0; i < parms.Length; i++)
            {
                Assert.Equal(parms[i], argsClass.StrArray[i]);
            }
        }
        [Trait(Traits.Style, "exploratory")] // Legacy Tests, replace when working on them.
        public void Basic_ArrayOfInts_Works()
        {
            var clas = new CommandArgumentSupport {
                ArgumentPostfix        = ":",
                ArgumentPrefix         = "",
                ArgumentPrefixOptional = true
            };

            int[]  nums        = new int[] { 1, 2, 3, 4, 5 };
            string numsAsParam = "";

            foreach (var f in nums)
            {
                numsAsParam += f + ",";
            }

            var argsClass = new SampleCommandLine_C3();

            string[] args = new string[] {
                $"IntArray:{numsAsParam}",
            };

            clas.ProcessArguments(argsClass, args);

            Assert.Equal(nums.Length, argsClass.NumArray.Length);
            for (int i = 0; i < nums.Length; i++)
            {
                Assert.Equal(nums[i], argsClass.NumArray[i]);
            }
        }
        public void Required_ThrowsIfNotPresent()
        {
            b.Info.Flow();

            var clas = new CommandArgumentSupport();

            clas.ArgumentPostfix        = ":";
            clas.ArgumentPrefix         = "";
            clas.ArgumentPrefixOptional = true;


            var argsClass = new SampleCommandLine_C5();

            string[] args = new string[] {
                "firstx:hello",
                "second:1"
            };


            Assert.Throws <ArgumentNullException>(() => {
                clas.ProcessArguments(argsClass, args);

                if (argsClass.first != null)
                {
                    throw new InvalidOperationException("This cant be right, the value should not be set");
                }
            });
        }
Example #8
0
        static async Task <int> Main(string[] args)
        {
            Console.WriteLine("online");
            ConfigHubTests();
            // Test
            var f = new FeatureHardCodedProvider();

            f.AddFeature(new Feature("TEST", true));



            if (Feature.GetFeatureByName("TEST").Active)
            {
            }

            CommandLineArgs        cla  = new CommandLineArgs();
            CommandArgumentSupport clas = new CommandArgumentSupport();

            clas.ProcessArguments(cla, args);
            clas.AddExample("TestConsoleApp.exe -x", "Runs it with an x parameter");
            string sa = clas.GenerateShortHelp(cla, "TestConsoleApp");

            Console.WriteLine("sec");
            Console.WriteLine(sa);

            await HHTestExecute();

            Console.ReadLine();

            return(0);
        }
        [Trait(Traits.Style, Traits.Regression)] // Legacy Tests, replace when working on them.
        public void BasicTest_MultipleArgumentsSameValue()
        {
            var clas = new CommandArgumentSupport();

            clas.ArgumentPrefix  = "/";
            clas.ArgumentPostfix = "=";

            var tbta1 = new TFSBuildToolArgs();
            var tbta2 = new TFSBuildToolArgs();

            string[] args  = new string[] { "/tfs=first", "/agent=second", "/teamproject=acme" };
            string[] args2 = new string[] { "/tfs=first", "/agenturi=second", "/teamproject=acme" };

            clas.ProcessArguments(tbta1, args);
            clas.ProcessArguments(tbta2, args2);

            Assert.Equal(tbta1.agentUri, tbta2.agentUri);
        }
        [Trait(Traits.Style, Traits.Regression)] // Legacy Tests, replace when working on them.
        public void BasicTest_DefaultArguments()
        {
            var c2 = new SampleCommandLine_C2();

            VerifySampleCommandLine2_InitialSate(c2);
            string[] args = new string[] { "filename.txt" };

            CommandArgumentSupport clas = new CommandArgumentSupport();

            clas.ArgumentPrefix  = "-";
            clas.ArgumentPostfix = "=";
            clas.ProcessArguments(c2, args);

            Assert.Equal("filename.txt", c2.Filename);

            args[0] = "-filename=filename.txt";
            c2      = new SampleCommandLine_C2();
            VerifySampleCommandLine2_InitialSate(c2);
            clas.ProcessArguments(c2, args);

            Assert.Equal("filename.txt", c2.Filename);
        }
        [Trait(Traits.Style, Traits.Regression)] // Legacy Tests, replace when working on them.
        public void BasicTest_ArgumentPrefix()
        {
            b.Info.Log("Starting  Testing Argument prefix behaviour");

            SampleCommandLine_C1 sc1 = new SampleCommandLine_C1();

            VerifySampleCommandLine1_InitialState(sc1);

            // Should be identical with differing prefixes.
            string[] argsBothTrue  = new string[] { "-OP1", "-OP2" };
            string[] argsBothTrue2 = new string[] { "XOP1", "XOP2" };
            string[] argsBothTrue3 = new string[] { "OP1", "OP2" };

            CommandArgumentSupport clas = new CommandArgumentSupport();

            clas.ArgumentPrefix    = "-";
            sc1.OptionParameterOne = sc1.OptionParameterTwo = false;
            clas.ProcessArguments(sc1, argsBothTrue);

            Assert.True(sc1.OptionParameterOne);
            Assert.True(sc1.OptionParameterTwo);

            sc1.OptionParameterOne = sc1.OptionParameterTwo = false;
            clas.ArgumentPrefix    = "X";
            clas.ProcessArguments(sc1, argsBothTrue2);

            Assert.True(sc1.OptionParameterOne);
            Assert.True(sc1.OptionParameterTwo);

            sc1.OptionParameterOne = sc1.OptionParameterTwo = false;
            clas.ArgumentPrefix    = "";
            clas.ProcessArguments(sc1, argsBothTrue3);

            Assert.True(sc1.OptionParameterOne);
            Assert.True(sc1.OptionParameterTwo);

            b.Info.Log("TESTOK: Finished Testing ArgumentPrefix");
        }
        public void Bug_IfBilgePassed_NullRefException()
        {
            b.Info.Flow();
            var clas = new CommandArgumentSupport(b);

            clas.ArgumentPostfix = ":";
            string[] args = new string[] {
                "firstonethenanother:gloop",
            };

            var argsClass = new SampleCommandLine_C6();

            clas.ProcessArguments(argsClass, args);
        }
Example #13
0
        public void TFSUseCaseUsesProperties()
        {
            var tcc  = new Kev_TFS_UseCase();
            var clas = new CommandArgumentSupport();

            string[] expectedArgs = new string[] {
                "/BUILDNAME:TFSSupport_DevDesktopPack_Main_Certified_20090423.8",
                "/ATTACHMENT:\"c:\\temp\\list.txt\""
            };

            clas.ArgumentPrefix  = "/";
            clas.ArgumentPostfix = ":";

            clas.ProcessArguments(tcc, expectedArgs);

            Assert.Equal("TFSSupport_DevDesktopPack_Main_Certified_20090423.8", tcc.BuildName);
            Assert.Equal("\"c:\\temp\\list.txt\"", tcc.Attachment);
            b.Info.Log(tcc.Attachment);
        }
        [Trait(Traits.Style, Traits.Regression)] // Legacy Tests, replace when working on them.
        public void TestIntAndLogMaxValues()
        {
            CommandArgumentSupport clas = new CommandArgumentSupport();

            clas.ArgumentPostfix        = ":";
            clas.ArgumentPrefix         = "";
            clas.ArgumentPrefixOptional = true;

            SampleCommandLine_C2 argsClass = new SampleCommandLine_C2();

            string[] args = new string[] {
                "filename:this is the filename",
                "INTVALUE:2147483647",
                "LONGVALUE:9223372036854775807"
            };
            clas.ProcessArguments(argsClass, args);
            Assert.Equal(int.MaxValue, argsClass.NumberParam1);
            Assert.Equal(long.MaxValue, argsClass.NumberParam2);
        }
Example #15
0
        public void Sean_DateTime_UseCase()
        {
            b.Info.Flow();

            var suc  = new Sean_DateUseCase();
            var clas = new CommandArgumentSupport();

            clas.ArgumentPrefix = "/";

            DateTime first = new DateTime(2018, 11, 22);
            DateTime to    = new DateTime(2018, 12, 30);

            string[] expectedArgs = new string[] {
                "/f22-11-2018",
                "/t30-12-2018"
            };
            clas.ProcessArguments(suc, expectedArgs);

            Assert.Equal(first, suc.from);
            Assert.Equal(to, suc.to);
        }
Example #16
0
        public void TFSUseCaseRemainderCheck()
        {
            var tcc  = new Kev_TFS_UseCase();
            var clas = new CommandArgumentSupport();

            string[] expectedArgs = new string[] {
                "/BUILDNAME:TFSSupport_DevDesktopPack_Main_Certified_20090423.8",
                "/ATTACHMENT:\"c:\\temp\\list.txt\"",
                "/Remainder:True",
                "RemainderTwo"
            };

            clas.ArgumentPrefix  = "/";
            clas.ArgumentPostfix = ":";

            clas.ProcessArguments(tcc, expectedArgs);

            Assert.Equal(2, tcc.Remainder.Length);
            Assert.Equal("/Remainder:True", tcc.Remainder[0]);
            Assert.Equal("RemainderTwo", tcc.Remainder[1]);
        }
Example #17
0
        public void UseCase2_OptionalParameterDefaultFilenames()
        {
            b.Info.Log("Starting UseCase2 Testing");

            #region string constants used to avoid typos

            string[] FILENAMES = new string[] { "file1.xml", "file2arflebarfleglooopmakethestringmuchlongerifwecan.xml", "c:\\temp\\files\\file3.xml", "\\s816244\\c$\\afile\\file4.xml", "file://testingfile/file5.xml" };

            #endregion

            UC2_OptionPlusDefaultFilenames uc2Class = new UC2_OptionPlusDefaultFilenames();

            #region verify the initial state of the class

            b.Info.Log("About to verify the initial state of the UC2 Class");
            Assert.True(uc2Class.Filenames.Length == 0, "The initial state of the default array is wrong");
            Assert.True(uc2Class.Overwrite == false, "the initial state of the overwrite flag is false");

            #endregion

            string[] expectedArguments = new string[] { FILENAMES[0], FILENAMES[1], FILENAMES[2], FILENAMES[3], FILENAMES[4], "/O" };
            b.Info.Log("About to perform the actual test case");
            CommandArgumentSupport clas = new CommandArgumentSupport();
            clas.ArgumentPrefix  = "/";
            clas.ArgumentPostfix = ":";

            clas.ProcessArguments(uc2Class, expectedArguments);

            b.Info.Log("Verifying the findings of the test case");

            Assert.True(uc2Class.Filenames.Length == 5, "The filenames were not passed through to the default array correctly");

            for (int i = 0; i < FILENAMES.Length; i++)
            {
                Assert.Equal(FILENAMES[i], uc2Class.Filenames[i]);
            }

            Assert.True(uc2Class.Overwrite, "The overwrite paramteter was not passed correctly");
        }
        [Trait(Traits.Style, Traits.Regression)] // Legacy Tests, replace when working on them.
        public void IntegerParameter_TooLarge_ReturnsCorrectError()
        {
            var clas = new CommandArgumentSupport();

            clas.ArgumentPostfix        = ":";
            clas.ArgumentPrefix         = "";
            clas.ArgumentPrefixOptional = true;

            var argsClass = new SampleCommandLine_C2();

            string[] args = new string[] {
                "filename:this is the filename",
                "INTVALUE:2200000000",
            };
            clas.ProcessArguments(argsClass, args);

            string[] erroredArguments = clas.ListArgumentsWithErrors();

            Assert.True(erroredArguments.Length > 0, "there was an errored argument");
            Assert.True(erroredArguments[0].Contains("INTVALUE"), "The correct argument was not found");
            Assert.True(erroredArguments[0].Contains("too large"), "The incorrect reason was found");
        }
        public void DateTime_StringParse_Works(DateTime exp, string text)
        {
            b.Info.Flow();

            var clas = new CommandArgumentSupport();

            clas.DateTimeParseFormat    = "d-M-yyyy";
            clas.ArgumentPostfix        = ":";
            clas.ArgumentPrefix         = "";
            clas.ArgumentPrefixOptional = true;


            var argsClass = new SampleCommandLine_C4();

            string[] args = new string[] {
                $"dt1:{text}"
            };

            clas.ProcessArguments(argsClass, args);

            Assert.Equal(exp, argsClass.datey1);
        }
        public void DateTime_BasicParse_Works(int year, int month, int day)
        {
            b.Info.Flow();

            DateTime target = new DateTime(year, month, day);

            var clas = new CommandArgumentSupport();

            clas.ArgumentPostfix        = ":";
            clas.ArgumentPrefix         = "";
            clas.ArgumentPrefixOptional = true;


            var argsClass = new SampleCommandLine_C4();

            string[] args = new string[] {
                "dt1:" + target.ToString("dd-MM-yyyy")
            };

            clas.ProcessArguments(argsClass, args);

            Assert.Equal <DateTime>(target, argsClass.datey1);
        }
Example #21
0
        public void UseCase1_BasicFilenameParameter()
        {
            b.Info.Log("Starting Usecase1 Basic testing");

            #region string constants used to avoid types

            const string FILENAME1 = "Test1.Xslt";
            const string FILENAME2 = "Test2.xslt";
            const string FILENAME3 = "Test.xml";

            #endregion

            UC1_BasicFilenameParameters uc1Class = new UC1_BasicFilenameParameters();

            #region verify the initial state of the class

            Assert.True(uc1Class.TransformFilename1.Length == 0, "The initial state of filename 1 is wrong");
            Assert.True(uc1Class.TransformFilename2.Length == 0, "The initial state of filename 2 is wrong");
            Assert.True(uc1Class.OutputFilename.Length == 0, "The initial state of output filename is wrong");
            Assert.False(uc1Class.OverwriteOutput, "The initial state of overwrite is wrong");

            #endregion

            string[] expectedArguments = new string[] { "/X1:" + FILENAME1, "/x2:" + FILENAME2, "/o:" + FILENAME3, "/Y" };

            CommandArgumentSupport clas = new CommandArgumentSupport();
            clas.ArgumentPrefix  = "/";
            clas.ArgumentPostfix = ":";

            clas.ProcessArguments(uc1Class, expectedArguments);

            // Actual test case verification.
            Assert.Equal(uc1Class.TransformFilename1, FILENAME1);
            Assert.Equal(uc1Class.TransformFilename2, FILENAME2);
            Assert.Equal(uc1Class.OutputFilename, FILENAME3);
            Assert.True(uc1Class.OverwriteOutput, "The boolean overwrite flag did not get passed correctly");
        }
        public void Bug_IfPostfixSpecified_ItMustBeUsed()
        {
            b.Info.Flow();
            var clas = new CommandArgumentSupport();

            clas.ArgumentPostfix        = ":";
            clas.ArgumentPrefix         = "";
            clas.ArgumentPrefixOptional = true;


            var argsClass = new SampleCommandLine_C6();

            string[] args = new string[] {
                "firstonethenanother:gloop",
                "firstone:barfle",
                "first:arfle"
            };

            clas.ProcessArguments(argsClass, args);

            Assert.Equal("arfle", argsClass.first);
            Assert.Equal("barfle", argsClass.second);
            Assert.Equal("gloop", argsClass.third);
        }
Example #23
0
        private static void Main(string[] args)
        {
            Console.WriteLine("Plisky Tool - Online.");

            var clas = new CommandArgumentSupport();

            clas.ArgumentPostfix = "=";
            clas.ProcessArguments(options, args);

            if (!ValidateArgumentSettings(options))
            {
                // TODO : Merge this in with the same code below
                Console.WriteLine("Fatal:  Argument Validation Failed.");
                Console.WriteLine();
                string s = clas.GenerateShortHelp(options, "Plisky Tool");
                Console.WriteLine(s);
                return;
            }

            if ((options.Debug) || (!string.IsNullOrEmpty(options.Trace)))
            {
                Console.WriteLine("Debug Mode, Adding Trace Handler");

                Bilge.AddHandler(new ConsoleHandler(), HandlerAddOptions.SingleType);

                Bilge.SetConfigurationResolver((name, inLevel) => {
                    SourceLevels returnLvl = SourceLevels.Verbose;

                    if ((options.Trace != null) && (options.Trace.ToLowerInvariant() == "info"))
                    {
                        returnLvl = SourceLevels.Information;
                    }

                    if ((name.Contains("Plisky-Versioning")) || (name.Contains("Plisky-Tool")))
                    {
                        return(returnLvl);
                    }
                    return(inLevel);
                });
            }

            Bilge b = new Bilge("Plisky-Tool");

            Bilge.Alert.Online("Plisky-Tool");
            b.Verbose.Dump(options, "App Options");

            if (PerformActionsFromCommandline())
            {
                if (versionerUsed != null)
                {
                    VersioningOutputter vo = new VersioningOutputter(versionerUsed);
                    vo.DoOutput(options.OutputsActive);
                }

                b.Info.Log("All Actions - Complete - Exiting.");
            }
            else
            {
                // TODO : Merge this in with the same code Above
                string s = clas.GenerateShortHelp(options, "Plisky Tool");
                Console.WriteLine(s);
            }

            b.Verbose.Log("Plisky Tool - Exit.");
            b.Flush();
        }