Exemplo n.º 1
0
        protected bool PublishTarget()
        {
            ProcessExecute processExecute = new ProcessExecute();

            if (IsWindows)
            {
                processExecute.Start(testCommandProjectDir, "cmd", new string[] { "/C", "dotnet", "publish", "--force" });
            }

            if (IsLinux)
            {
                processExecute.Start(testCommandProjectDir, "dotnet", new string[] { "publish", "--force" });
            }

            return(processExecute.ProcessExitCode == 0);
        }
    public static void ClassInit(TestContext context)
    {
      ProcessExecute processExecute;
      string executionPath;

      processExecute = new ProcessExecute();
      executionPath = Path.GetFullPath("../../../../TestValidationExpandedCommand");

      if (IsWindows)
      {
        processExecute.Start(executionPath, "cmd", new string[] { "/C", "dotnet", "build", "--force" });
      }

      if (IsLinux)
      {
        processExecute.Start(executionPath, "dotnet", new string[] { "build", "--force" });
      }
    }
    public void ParserExpanded_PassTest()
    {
      ProcessExecute processExecute;
      string executionPath;

      executionPath = Path.GetFullPath("../../../../TestParseExpandedCommand/bin/Debug/netcoreapp3.1");
      processExecute = new ProcessExecute();
      processExecute.Start(executionPath, "TestParseExpandedCommand", new string[] {  "delivery-date=2050-01-01", "[email protected]" });
      Assert.AreEqual(0, processExecute.ProcessExitCode, "The command should pass for valid arguments.");
    }
Exemplo n.º 4
0
    public void ParserExpanded_ValidArgumentTest()
    {
      ProcessExecute processExecute;
      string executionPath;

      executionPath = Path.GetFullPath("../../../../TestParseExpandedCommand/bin/Debug/netcoreapp3.1");
      processExecute = new ProcessExecute();
      processExecute.Start(executionPath, "TestParseExpandedCommand", new string[] { "delivery-date=2030-01-01" });
      Assert.AreEqual(0, processExecute.ProcessExitCode, "The command should succeed with a valid argument.");
    }
Exemplo n.º 5
0
        public void VersionTest_PassTest()
        {
            ProcessExecute processExecute;

            ResetTestCommand();

            processExecute = new ProcessExecute();
            processExecute.Start(testCommandPublishDir, testCommand, new string[] { "version" });
            Assert.AreNotEqual(0, processExecute.ProcessExitCode, "A version request should always result in an invalid parameter object.");
            StringAssert.Contains(processExecute.ProcessStandardOutput, "1.2.3.4", "The returned string should show expected version.");
        }
    public void ValidationExpanded_InvalidEmailTest()
    {
      ProcessExecute processExecute;
      string executionPath;

      executionPath = Path.GetFullPath("../../../../TestValidationExpandedCommand/bin/Debug/netcoreapp3.1");
      processExecute = new ProcessExecute();
      processExecute.Start(executionPath, "TestValidationExpandedCommand", new string[] { "delivery-date=2050-01-01", "email=blah@blah" });
      Assert.AreNotEqual(0, processExecute.ProcessExitCode, "The command should fail because of the invalid 'delivery-date' argument.");
      StringAssert.Contains(processExecute.ProcessErrorOutput, "One or more of the command line arguments are invalid.");
      StringAssert.Contains(processExecute.ProcessErrorOutput, "The value of argument 'email' must be a valid email address.");
      Debugger.Log(1, "ValidationExpandedTest", processExecute.ProcessErrorOutput + "\r\n\r\n");
    }
Exemplo n.º 7
0
    public void ParserExpanded_InvalidArgumentTest()
    {
      ProcessExecute processExecute;
      string executionPath;

      executionPath = Path.GetFullPath("../../../../TestParseExpandedCommand/bin/Debug/netcoreapp3.1");
      processExecute = new ProcessExecute();
      processExecute.Start(executionPath, "TestParseExpandedCommand", new string[] { "delivery-date=12345" });
      Assert.AreNotEqual(0, processExecute.ProcessExitCode, "The command should fail because of the invalid argument.");
      StringAssert.Contains(processExecute.ProcessErrorOutput, "One or more of the command line arguments are invalid.");
      StringAssert.Contains(processExecute.ProcessErrorOutput, "The mandatory command line argument 'delivery-date'");
      Debugger.Log(1, "ParserExpandedTest", processExecute.ProcessErrorOutput + "\r\n\r\n");
    }
    public void ScreenCreationOverride_HelpTest()
    {
      ProcessExecute processExecute;
      string executionPath;

      executionPath = Path.GetFullPath("../../../../TestScreenCreationOverrideCommand/bin/Debug/netcoreapp3.1");
      processExecute = new ProcessExecute();
      processExecute.Start(executionPath, "TestScreenCreationOverrideCommand", new string[] { "help" });
      Assert.AreNotEqual(0, processExecute.ProcessExitCode, "The command should fail because of the help request.");
      StringAssert.Contains(processExecute.ProcessStandardOutput, "Custom help screen");
      StringAssert.Contains(processExecute.ProcessStandardOutput, "The TestScreenCreationOverrideCommand is a command");
      Debugger.Log(1, "ScreenCreationOverride", processExecute.ProcessStandardOutput + "\r\n\r\n");
    }
    public void ScreenCreationOverride_NoArgumentUsageTest()
    {
      ProcessExecute processExecute;
      string executionPath;

      executionPath = Path.GetFullPath("../../../../TestScreenCreationOverrideCommand/bin/Debug/netcoreapp3.1");
      processExecute = new ProcessExecute();
      processExecute.Start(executionPath, "TestScreenCreationOverrideCommand", new string[] { "showUsageOnEmptyArgs" });
      Assert.AreNotEqual(0, processExecute.ProcessExitCode, "The command should fail because of the missing argument.");
      StringAssert.Contains(processExecute.ProcessErrorOutput, "Custom usage screen");
      StringAssert.Contains(processExecute.ProcessErrorOutput, "TestScreenCreationOverrideCommand [help] [version]");
      Debugger.Log(1, "ScreenCreationOverride", processExecute.ProcessErrorOutput + "\r\n\r\n");
    }
    public void ScreenCreationOverride_NoArgumentSummaryTest()
    {
      ProcessExecute processExecute;
      string executionPath;

      executionPath = Path.GetFullPath("../../../../TestScreenCreationOverrideCommand/bin/Debug/netcoreapp3.1");
      processExecute = new ProcessExecute();
      processExecute.Start(executionPath, "TestScreenCreationOverrideCommand", new string[] {  });
      Assert.AreNotEqual(0, processExecute.ProcessExitCode, "The command should fail because of the missing argument.");
      StringAssert.Contains(processExecute.ProcessErrorOutput, "Custom validation screen");
      StringAssert.Contains(processExecute.ProcessErrorOutput, "name");
      StringAssert.Contains(processExecute.ProcessErrorOutput, "items-total");
      Debugger.Log(1, "ScreenCreationOverride", processExecute.ProcessErrorOutput + "\r\n\r\n");
    }
Exemplo n.º 11
0
        public void ValidatonSummary_DefaultValueInt32FailTest()
        {
            string         parameterObjectSource;
            List <string>  parameterList;
            ProcessExecute processExecute;

            parameterList = new List <string>()
            {
                "[DefaultValue((object) \"abc\")]", "[Name(\"number\")]", "public Int32 Int32Number { get; set; }\r\n"
            };
            parameterObjectSource = CreateParameterObjectSource(parameterList);

            System.IO.File.Delete(System.IO.Path.Combine(testCommandProjectDir, sourceFileName));
            using (var stream = System.IO.File.OpenWrite(System.IO.Path.Combine(testCommandProjectDir, sourceFileName)))
            {
                using (var strWriter = new StreamWriter(stream))
                {
                    strWriter.Write(parameterObjectSource);
                    strWriter.Flush();
                    strWriter.Close();
                }
            }

            SetTestCommandShowUsageOnEmptyArgs(false);

            if (BuildTarget())
            {
                if (PublishTarget())
                {
                    processExecute = new ProcessExecute();
                    processExecute.Start(testCommandPublishDir, testCommand, new string[] {  });
                    Assert.AreNotEqual(0, processExecute.ProcessExitCode, "Validation of an invalid argument should result in a return code other than 0.");
                    StringAssert.Contains(processExecute.ProcessErrorOutput, "║ One or more of the command line arguments are invalid.                       ║", "The returned string should show the expected message.");
                    StringAssert.Contains(processExecute.ProcessErrorOutput, "║ number     ║ The default value for the command line argument 'number' is     ║", "The returned string should show the expected message.");
                    StringAssert.Contains(processExecute.ProcessErrorOutput, "The exceptions message is", "The returned string should show the expected message.");
                    StringAssert.Contains(processExecute.ProcessErrorOutput, "║            ║ String' cannot be converted to type 'System.Int32'.'            ║", "The returned string should show the expected message.");

                    Debugger.Log(1, "ValidationSummaryTest", processExecute.ProcessErrorOutput + "\r\n\r\n");
                }
                else
                {
                    Assert.Fail("Publishing the test target failed in function 'DefaultValueInt32FailTest'.");
                }
            }
            else
            {
                Assert.Fail("Building the test target failed in function 'DefaultValueInt32FailTest'.");
            }
        }
Exemplo n.º 12
0
        public void Help_DefaultDescriptionNameUInt32ParameterTest()
        {
            string         parameterObjectSource;
            List <string>  parameterList;
            ProcessExecute processExecute;

            parameterList = new List <string>()
            {
                "[Description(\"The number of items from the last delivery. It must be a number greater or equal 0.\")]", "[Name(\"amount\")]", "[DefaultValue((object)42)]", "public UInt32 itemCount { get; set; }\r\n"
            };
            parameterObjectSource = CreateParameterObjectSource(parameterList);

            System.IO.File.Delete(System.IO.Path.Combine(testCommandProjectDir, sourceFileName));
            using (var stream = System.IO.File.OpenWrite(System.IO.Path.Combine(testCommandProjectDir, sourceFileName)))
            {
                using (var strWriter = new StreamWriter(stream))
                {
                    strWriter.Write(parameterObjectSource);
                    strWriter.Flush();
                    strWriter.Close();
                }
            }

            if (BuildTarget())
            {
                if (PublishTarget())
                {
                    processExecute = new ProcessExecute();
                    processExecute.Start(testCommandPublishDir, testCommand, new string[] { "abcde", "help" });
                    Assert.AreNotEqual(0, processExecute.ProcessExitCode, "A help request results in a validation fail. For that reason the return value should not be 0.");
                    StringAssert.Contains(processExecute.ProcessStandardOutput, "╔═╦═[Parameter]═╦═[Type]═╦═[Default]═╦═[Description]═══════════════════════════╗", "The returned string should show the expected message.");
                    StringAssert.Contains(processExecute.ProcessStandardOutput, "║-║ amount      ║ UInt32 ║ 42        ║ The number of items from the last       ║", "The returned string should show the expected message.");
                    StringAssert.Contains(processExecute.ProcessStandardOutput, "║ ║             ║        ║           ║ delivery. It must be a number greater   ║", "The returned string should show the expected message.");
                    StringAssert.Contains(processExecute.ProcessStandardOutput, "║ ║             ║        ║           ║ or equal 0.                             ║", "The returned string should show the expected message.");
                    StringAssert.Contains(processExecute.ProcessStandardOutput, "TestCommand [help] [version] [amount=<UInt32>]", "The returned string should show the expected message.");

                    Debugger.Log(1, "DefaultDescriptionNameUInt32ParameterTest", processExecute.ProcessStandardOutput + "\r\n");
                }
                else
                {
                    Assert.Fail("Publishing the test target failed in function 'DefaultDescriptionNamedUInt32Param'.");
                }
            }
            else
            {
                Assert.Fail("Building the test target failed in function 'DefaultDescriptionNamedUInt32Param'.");
            }
        }
Exemplo n.º 13
0
        public void UsageTest_CustomPassTest()
        {
            string         parameterObjectSource;
            List <string>  parameterList;
            ProcessExecute processExecute;
            string         customUsage;

            customUsage   = "testcommand [-help] [-version] number<string in the range -10 - 10>";
            parameterList = new List <string>()
            {
                "[Name(\"number\")]", "public Int32 Int32Number { get; set; }\r\n"
            };
            parameterObjectSource = CreateParameterObjectSource(parameterList, usage: customUsage);

            System.IO.File.Delete(System.IO.Path.Combine(testCommandProjectDir, sourceFileName));
            using (var stream = System.IO.File.OpenWrite(System.IO.Path.Combine(testCommandProjectDir, sourceFileName)))
            {
                using (var strWriter = new StreamWriter(stream))
                {
                    strWriter.Write(parameterObjectSource);
                    strWriter.Flush();
                    strWriter.Close();
                }
            }

            SetTestCommandShowUsageOnEmptyArgs(true);

            if (BuildTarget())
            {
                if (PublishTarget())
                {
                    processExecute = new ProcessExecute();
                    processExecute.Start(testCommandPublishDir, testCommand, new string[] {});
                    Assert.AreNotEqual(0, processExecute.ProcessExitCode, "Validation of the missing arguments should result in a return code other than 0.");
                    StringAssert.Contains(processExecute.ProcessErrorOutput, customUsage, "The returned string should show the expected message.");
                    Debugger.Log(1, "UsageTest", processExecute.ProcessErrorOutput + "\r\n\r\n");
                }
                else
                {
                    Assert.Fail("Publishing the test target failed in function 'Int32FailTest'.");
                }
            }
            else
            {
                Assert.Fail("Building the test target failed in function 'Int32FailTest'.");
            }
        }
Exemplo n.º 14
0
        public void Help_MandatoryStringNameParameterTest()
        {
            string         parameterObjectSource;
            List <string>  parameterList;
            ProcessExecute processExecute;

            parameterList = new List <string>()
            {
                "[Mandatory]", "[Name(\"source\")]", "public string SourcePath { get; set; }\r\n"
            };
            parameterObjectSource = CreateParameterObjectSource(parameterList);

            System.IO.File.Delete(System.IO.Path.Combine(testCommandProjectDir, sourceFileName));
            using (var stream = System.IO.File.OpenWrite(System.IO.Path.Combine(testCommandProjectDir, sourceFileName)))
            {
                using (var strWriter = new StreamWriter(stream))
                {
                    strWriter.Write(parameterObjectSource);
                    strWriter.Flush();
                    strWriter.Close();
                }
            }

            if (BuildTarget())
            {
                if (PublishTarget())
                {
                    processExecute = new ProcessExecute();
                    processExecute.Start(testCommandPublishDir, testCommand, new string[] { "abcde", "help" });
                    Assert.AreNotEqual(0, processExecute.ProcessExitCode, "A help request results in a validation fail. For that reason the return value should not be 0.");


                    StringAssert.Contains(processExecute.ProcessStandardOutput, "║+║ source      ║ String ║           ║ source<String>                          ║", "The returned string should show the expected message.");
                    StringAssert.Contains(processExecute.ProcessStandardOutput, "TestCommand [help] [version] source=<String>", "The returned string should show the expected message.");

                    Debugger.Log(1, "MandatoryStringNameParameterTest", processExecute.ProcessStandardOutput + "\r\n");
                }
                else
                {
                    Assert.Fail("Publishing the test target failed in function 'MandatoryStringNameParam'.");
                }
            }
            else
            {
                Assert.Fail("Building the test target failed in function 'MandatoryStringNameParam'.");
            }
        }
Exemplo n.º 15
0
        public void ValidatonSummary_ValueSetInt32FailTest()
        {
            string         parameterObjectSource;
            List <string>  parameterList;
            ProcessExecute processExecute;

            parameterList = new List <string>()
            {
                "[ValueSet( new object[] { 5, 10, 15, 20})]", "[Name(\"number\")]", "public Int32 Int32Number { get; set; }\r\n"
            };
            parameterObjectSource = CreateParameterObjectSource(parameterList);

            System.IO.File.Delete(System.IO.Path.Combine(testCommandProjectDir, sourceFileName));
            using (var stream = System.IO.File.OpenWrite(System.IO.Path.Combine(testCommandProjectDir, sourceFileName)))
            {
                using (var strWriter = new StreamWriter(stream))
                {
                    strWriter.Write(parameterObjectSource);
                    strWriter.Flush();
                    strWriter.Close();
                }
            }

            ResetTestCommand();

            if (BuildTarget())
            {
                if (PublishTarget())
                {
                    processExecute = new ProcessExecute();
                    processExecute.Start(testCommandPublishDir, testCommand, new string[] { "number=6" });
                    Assert.AreNotEqual(0, processExecute.ProcessExitCode, "Validation of an invalid argument should result in a return code other than 0.");
                    StringAssert.Contains(processExecute.ProcessErrorOutput, "║ number     ║ The value of command line argument 'number' is not in the set   ║", "The returned string should show the expected message.");
                    StringAssert.Contains(processExecute.ProcessErrorOutput, "[5, 10, 15, 20]", "The returned string should show the expected message.");

                    Debugger.Log(1, "ValidationSummaryTest", processExecute.ProcessErrorOutput + "\r\n\r\n");
                }
                else
                {
                    Assert.Fail("Publishing the test target failed in function 'ValueSetInt32FailTest'.");
                }
            }
            else
            {
                Assert.Fail("Building the test target failed in function 'ValueSetInt32FailTest'.");
            }
        }
Exemplo n.º 16
0
        public void ValidatonSummary_Int32PassTest()
        {
            string         parameterObjectSource;
            List <string>  parameterList;
            ProcessExecute processExecute;

            parameterList = new List <string>()
            {
                "[Name(\"number\")]", "public Int32 Int32Number { get; set; }\r\n"
            };
            parameterObjectSource = CreateParameterObjectSource(parameterList);

            System.IO.File.Delete(System.IO.Path.Combine(testCommandProjectDir, sourceFileName));
            using (var stream = System.IO.File.OpenWrite(System.IO.Path.Combine(testCommandProjectDir, sourceFileName)))
            {
                using (var strWriter = new StreamWriter(stream))
                {
                    strWriter.Write(parameterObjectSource);
                    strWriter.Flush();
                    strWriter.Close();
                }
            }

            ResetTestCommand();

            if (BuildTarget())
            {
                if (PublishTarget())
                {
                    processExecute = new ProcessExecute();
                    processExecute.Start(testCommandPublishDir, testCommand, new string[] { "number=42" });
                    Assert.AreEqual(0, processExecute.ProcessExitCode, "Validation should pass and result in a return code equal to 0.");
                }
                else
                {
                    Assert.Fail("Publishing the test target failed in function 'Int32PassTest'.");
                }
            }
            else
            {
                Assert.Fail("Building the test target failed in function 'Int32PassTest'.");
            }
        }
Exemplo n.º 17
0
        public void Help_NoParameterTest()
        {
            string         parameterObjectSource;
            List <string>  parameterList;
            ProcessExecute processExecute;

            parameterList         = new List <string>();
            parameterObjectSource = CreateParameterObjectSource(parameterList);

            System.IO.File.Delete(System.IO.Path.Combine(testCommandProjectDir, sourceFileName));
            using (var stream = System.IO.File.OpenWrite(System.IO.Path.Combine(testCommandProjectDir, sourceFileName)))
            {
                using (var strWriter = new StreamWriter(stream))
                {
                    strWriter.Write(parameterObjectSource);
                    strWriter.Flush();
                    strWriter.Close();
                }
            }

            if (BuildTarget())
            {
                if (PublishTarget())
                {
                    processExecute = new ProcessExecute();
                    processExecute.Start(testCommandPublishDir, testCommand, new string[] { "help" });
                    Assert.AreNotEqual(0, processExecute.ProcessExitCode, "A help request results in a validation fail. For that reason the return value should not be 0.");
                    StringAssert.Contains(processExecute.ProcessStandardOutput, "The current parameter object has no parameter property!", "The returned string should match the expectation.");
                    StringAssert.Contains(processExecute.ProcessStandardOutput, "TestCommand [help] [version]", "The returned string should match the expectation.");

                    Debugger.Log(1, "NoParameterTest", processExecute.ProcessStandardOutput + "\r\n");
                }
                else
                {
                    Assert.Fail("Publishing the test target failed in function 'NoParameter'.");
                }
            }
            else
            {
                Assert.Fail("Building the test target failed in function 'NoParameter'.");
            }
        }