Exemple #1
0
        public void Test_DuplicateArgument()
        {
            string[] args = { "-buildfile:test", "-buildfile:test" };

            string result = null;

            using (ConsoleCapture c = new ConsoleCapture()) {
                ConsoleDriver.Main(args);
                result = c.Close();
            }

            // using a regular expression to check for correct error message
            string expression = @"Duplicate command-line argument '-buildfile'.";

            Match match = Regex.Match(result, expression);

            Assert.IsTrue(match.Success, "Argument did not cause an error: " + result);
        }
Exemple #2
0
            public void TestDisplayedWhenHelpArgument(string helpArg)
            {
                using (var consoleCap = new ConsoleCapture())
                {
                    int code = AasxToolkit.Program.MainWithExitCode(new[] { helpArg });

                    if (consoleCap.Error() != "")
                    {
                        throw new AssertionException(
                                  $"Expected no stderr, but got:{System.Environment.NewLine}" +
                                  consoleCap.Error());
                    }

                    Assert.AreEqual(0, code);

                    Assert.IsTrue(consoleCap.Output().StartsWith("AasxToolkit:"));  // Start of the help message
                }
            }
 /// <summary>
 /// Executes a task and returns the console output as a string.
 /// </summary>
 /// <param name="task">The task to execute.</param>
 /// <returns>
 /// The console output.
 /// </returns>
 /// <remarks>
 /// Any exception that is thrown as part of the execution of the
 /// <see cref="Task" /> is wrapped in a <see cref="TestBuildException" />.
 /// </remarks>
 public static string ExecuteTask(Task task)
 {
     using (ConsoleCapture c = new ConsoleCapture()) {
         string output = null;
         try {
             task.Execute();
         } catch (Exception e) {
             output = c.Close();
             throw new TestBuildException("Error Executing Task", output, e);
         } finally {
             if (output == null)
             {
                 output = c.Close();
             }
         }
         return(output);
     }
 }
Exemple #4
0
        public void Test_UnknownArgument()
        {
            string[] args = { "-asdf", "-help", "-verbose" };

            string result = null;

            using (ConsoleCapture c = new ConsoleCapture()) {
                ConsoleDriver.Main(args);
                result = c.Close();
            }

            // using a regular expression to check for correct error message
            string expression = @"Unknown argument '-asdf'";

            Match match = Regex.Match(result, expression);

            Assert.IsTrue(match.Success, "Argument did not cause an error: " + result);
        }
Exemple #5
0
        public void Test_MissingNameForNameValuePair()
        {
            string[] args = { "-D:test=", "-D:test=" };

            string result = null;

            using (ConsoleCapture c = new ConsoleCapture()) {
                ConsoleDriver.Main(args);
                result = c.Close();
            }

            // using a regular expression to check for correct error message
            string expression = @"Duplicate property named 'test' for command-line argument 'D'.";

            Match match = Regex.Match(result, expression);

            Assert.IsTrue(match.Success, "Argument did not cause an error: " + result);
        }
 /// <summary>
 /// Executes the project and returns the console output as a string.
 /// </summary>
 /// <param name="p">The project to execute.</param>
 /// <returns>
 /// The console output.
 /// </returns>
 /// <remarks>
 /// Any exception that is thrown as part of the execution of the
 /// <see cref="Project" /> is wrapped in a <see cref="TestBuildException" />.
 /// </remarks>
 public static string ExecuteProject(Project p)
 {
     using (ConsoleCapture c = new ConsoleCapture()) {
         string output = null;
         try {
             p.Execute();
         } catch (BuildException e) {
             output = c.Close();
             throw new TestBuildException("Error Executing Project", output, e);
         } finally {
             if (output == null)
             {
                 output = c.Close();
             }
         }
         return(output);
     }
 }
Exemple #7
0
        public void Test_MissingValueForNameValuePair()
        {
            string[] args = { "-D:test", "-D:test" };

            string result = null;

            using (ConsoleCapture c = new ConsoleCapture()) {
                ConsoleDriver.Main(args);
                result = c.Close();
            }

            // using a regular expression to check for correct error message
            string expression = @"Expected name\/value pair \(<name>=<value>\).";

            Match match = Regex.Match(result, expression);

            Assert.IsTrue(match.Success, "Argument did not cause an error: " + result);
        }
Exemple #8
0
        public void Test_InvalidBoolValue()
        {
            string[] args = { "-debug:test" };

            string result = null;

            using (ConsoleCapture c = new ConsoleCapture()) {
                ConsoleDriver.Main(args);
                result = c.Close();
            }

            // using a regular expression to check for correct error message
            string expression = @"Invalid value 'test' for command-line argument '-debug'.";

            Match match = Regex.Match(result, expression);

            Assert.IsTrue(match.Success, "Argument did not cause an error: " + result);
        }
 public CsAgentModel AddCsAgent(CsAgentModel csAgent)
 {
     using (ConsoleCapture capture = new ConsoleCapture())
     {
         try
         {
             var lwCsAgent = lwSvc.HertzAddUpdateCSAgent(csAgent.USERNAME, csAgent.FIRSTNAME, csAgent.LASTNAME, csAgent.ROLEID.ToString(), ((int)(csAgent.STATUS)).ToString(), csAgent.GROUPID.ToString(), csAgent.AGENTNUMBER.ToString(), csAgent.EMAILADDRESS, csAgent.PHONENUMBER, csAgent.EXTENSION, null, out double elapsedTime);
             return(LODConvert.FromLW <CsAgentModel>(lwCsAgent));
         }
         catch (LWClientException ex)
         {
             throw new LWServiceException(ex.Message, ex.ErrorCode);
         }
         finally
         {
             stepContext.AddAttachment(new Attachment("HertzAddUpdateCSAgent", capture.Output, Attachment.Type.Text));
         }
     }
 }
Exemple #10
0
            public void TestHelpTrumpsOtherArguments()
            {
                using (var consoleCap = new ConsoleCapture())
                {
                    int code = AasxToolkit.Program.MainWithExitCode(
                        new[] { "load", "doesnt-exist.aasx", "help" });

                    if (consoleCap.Error() != "")
                    {
                        throw new AssertionException(
                                  $"Expected no stderr, but got:{System.Environment.NewLine}" +
                                  consoleCap.Error());
                    }

                    Assert.AreEqual(0, code);

                    Assert.IsTrue(consoleCap.Output().StartsWith("AasxToolkit:"));  // Start of the help message
                }
            }
Exemple #11
0
        public void WriteAndClear()
        {
            var capture = new ConsoleCapture();

            HConsole.WriteAndClear();
            Assert.That(HConsole.Text.Length, Is.Zero);

            HConsole.WriteAndClear();
            Assert.That(HConsole.Text.Length, Is.Zero);

            HConsole.Configure(x => x.Set(xx => xx.Verbose()));
            HConsole.WriteLine(this, "meh");
            Assert.That(HConsole.Text.Length, Is.GreaterThan(0));

            using (capture.Output())
            {
                HConsole.WriteAndClear();
            }

            Assert.That(HConsole.Text.Length, Is.Zero);
            Assert.That(capture.ReadToEnd(), Does.EndWith("meh" + Environment.NewLine));

            HConsole.WriteLine(this, "meh");
            Assert.That(HConsole.Text.Length, Is.GreaterThan(0));

            using (capture.Output())
            {
                HConsole.Clear();
            }

            Assert.That(HConsole.Text.Length, Is.Zero);
            Assert.That(capture.ReadToEnd().Length, Is.Zero);

            HConsole.WriteLine(this, "meh");
            using (capture.Output())
            {
                using (HConsole.Capture()) { }
            }

            Assert.That(HConsole.Text.Length, Is.Zero);
            Assert.That(capture.ReadToEnd(), Does.EndWith("meh" + Environment.NewLine));
        }
Exemple #12
0
        public List <RewardCatalogSummaryResponseModel> GetRewardCatalog(bool?activeOnly, string tier,
                                                                         string language, long?categoryId, bool?returnRewardCategory,
                                                                         List <ContentSearchAttribute> contentSearchAttributes, int?startIndex,
                                                                         int?batchSize, long?currencyToEarnLow, long?currencyToEarnHigh)
        {
            List <RewardCatalogSummaryResponseModel> rewardCatalogSummary = new List <RewardCatalogSummaryResponseModel>();

            using (ConsoleCapture capture = new ConsoleCapture())
            {
                try
                {
                    var lwGetRewardsCatalog = lwSvc.GetRewardCatalog(activeOnly, tier, language, categoryId,
                                                                     returnRewardCategory,
                                                                     contentSearchAttributes != null?
                                                                     contentSearchAttributes.Select(x =>
                                                                                                    new Brierley.LoyaltyWare.ClientLib.DomainModel.Client.ContentSearchAttributesStruct
                    {
                        AttributeName  = x.AttributeName,
                        AttributeValue = x.AttributeValue
                    }).ToArray():null,
                                                                     startIndex, batchSize, currencyToEarnLow, currencyToEarnHigh,
                                                                     String.Empty, out double time);
                    foreach (var lwGetRewardCatalog in lwGetRewardsCatalog)
                    {
                        rewardCatalogSummary.Add(LODConvert.FromLW <RewardCatalogSummaryResponseModel>(lwGetRewardCatalog));
                    }
                }
                catch (LWClientException ex)
                {
                    throw new LWServiceException(ex.Message, ex.ErrorCode);
                }
                catch (Exception ex)
                {
                    throw new LWServiceException(ex.Message, -1);
                }
                finally
                {
                    stepContext.AddAttachment(new Attachment("GetRewardCatalog", capture.Output, Attachment.Type.Text));
                }
            }
            return(rewardCatalogSummary);
        }
Exemple #13
0
        public static void GameIntroduction_DisplaysCorrectly()
        {
            using (ConsoleCapture theConsole = new ConsoleCapture())
            {
                // Arrange
                string theExpectedOutput =
                    "***********************\r\n" +
                    "* Noughts and Crosses *\r\n" +
                    "***********************\r\n" +
                    "\r\n" +
                    "Two computer players will compete for your amusement.\r\n" +
                    "\r\n";

                // Act
                Game.DisplayGameIntroduction();

                // Assert
                Assert.That(theConsole.Output, Is.EqualTo(theExpectedOutput));
            }
        }
Exemple #14
0
        public MemberModel AddMember(MemberModel member)
        {
            var         lwMemberIn = LODConvert.ToLW <Member>(member);
            MemberModel memberOut  = default;

            using (ConsoleCapture capture = new ConsoleCapture())
            {
                try
                {
                    var lwMemOut = lwSvc.AddMember(lwMemberIn, String.Empty, out double elapsed);
                    memberOut = LODConvert.FromLW <MemberModel>(lwMemOut);
                    stepContext.AddAttachment(new Attachment("AddMember", capture.Output, Attachment.Type.Text));
                }
                catch (LWClientException ex)
                {
                    stepContext.AddAttachment(new Attachment("AddMember", capture.Output, Attachment.Type.Text));
                    throw new LWServiceException(ex.Message, ex.ErrorCode);
                }
            }
            return(memberOut);
        }
Exemple #15
0
        public void TestNoErrorOnSamples()
        {
            foreach (string pth in SamplesAasxDir.ListAasxPaths())
            {
                using (var tmpDir = new TemporaryDirectory())
                {
                    using (var consoleCap = new ConsoleCapture())
                    {
                        int code = AasxToolkit.Program.MainWithExitCode(
                            new[]
                        {
                            "load", pth,
                            "export-template", Path.Combine(tmpDir.Path, "exported.template")
                        });

                        Assert.AreEqual(0, code);
                        Assert.AreEqual("", consoleCap.Error());
                    }
                }
            }
        }
Exemple #16
0
 public void HertzValidateToken(string loyaltyId, string token)
 {
     using (ConsoleCapture capture = new ConsoleCapture())
     {
         try
         {
             lwSvc.HertzValidateToken(loyaltyId, token, String.Empty, out double time);
         }
         catch (LWClientException ex)
         {
             throw new LWServiceException(ex.Message, ex.ErrorCode);
         }
         catch (Exception ex)
         {
             throw new LWServiceException(ex.Message, -1);
         }
         finally
         {
             stepContext.AddAttachment(new Attachment("HertzAwardLoyaltyCurrency", capture.Output, Attachment.Type.Text));
         }
     }
 }
Exemple #17
0
        public void Test_DefineProperty()
        {
            string buildFileContents = @"<?xml version='1.0' ?>
                <project name='Test' default='test' basedir='.'>
                    <target name='test'>
                        <property name='project.name' value='Foo.Bar' overwrite='false' />
                        <echo message='project.name = ${project.name}'/>
                    </target>
                </project>";

            // write build file to temp file
            string buildFileName = CreateTempFile("buildfile.xml", buildFileContents);

            Assert.IsTrue(File.Exists(buildFileName), buildFileName + " does not exist.");

            string[] args =
            {
                "-D:project.name=MyCompany.MyProject",
                String.Format("-buildfile:{0}",       buildFileName),
            };

            string result = null;

            using (ConsoleCapture c = new ConsoleCapture()) {
                ConsoleDriver.Main(args);
                result = c.Close();
            }

            // regular expression to look for expected output
            string expression = @"project.name = MyCompany.MyProject";
            Match  match      = Regex.Match(result, expression);

            Assert.IsTrue(match.Success, "Property 'project.name' appears to have been overridden by <property> task." + Environment.NewLine + result);

            // delete the build file
            File.Delete(buildFileName);
            Assert.IsFalse(File.Exists(buildFileName), buildFileName + " exists.");
        }
Exemple #18
0
 public int GetMemberPromotionCount(string ipCode)
 {
     using (ConsoleCapture capture = new ConsoleCapture())
     {
         try
         {
             var lwMemberPromoCount = lwSvc.GetMemberPromotionsCount(ipCode, null, out double time);
             return(lwMemberPromoCount);
         }
         catch (LWClientException ex)
         {
             throw new LWServiceException(ex.Message, ex.ErrorCode);
         }
         catch (Exception ex)
         {
             throw new LWServiceException(ex.Message, -1);
         }
         finally
         {
             stepContext.AddAttachment(new Attachment("GetMemberPromotionCount", capture.Output, Attachment.Type.Text));
         }
     }
 }
Exemple #19
0
 public long CancelMemberReward(string memberRewardId, string programCode, string resvId, DateTime?chkoutDt,
                                string chkoutAreanum, string chkoutLocNum, string chkoutLocId, string externalId)
 {
     using (ConsoleCapture capture = new ConsoleCapture())
     {
         try
         {
             return(lwSvc.CancelMemberReward(Convert.ToInt64(memberRewardId), resvId, chkoutDt, chkoutAreanum, chkoutLocNum, chkoutLocId, programCode, externalId, out double time));
         }
         catch (LWClientException ex)
         {
             throw new LWServiceException(ex.Message, ex.ErrorCode);
         }
         catch (Exception ex)
         {
             throw new LWServiceException(ex.Message, -1);
         }
         finally
         {
             stepContext.AddAttachment(new Attachment("CancelMemberReward", capture.Output, Attachment.Type.Text));
         }
     }
 }
Exemple #20
0
        public static void GameState_WhenFirstInitialised_DisplaysCorrectly()
        {
            using (ConsoleCapture theConsole = new ConsoleCapture())
            {
                // Arrange
                string theExpectedOutput =
                    "\r\n" +
                    "Here's the current state of the game board:\r\n" +
                    "\r\n" +
                    " | | \r\n" +
                    "-|-|-\r\n" +
                    " | | \r\n" +
                    "-|-|-\r\n" +
                    " | | \r\n";
                GameState theGameState = new GameState();

                // Act
                theGameState.Display();

                // Assert
                Assert.That(theConsole.Output, Is.EqualTo(theExpectedOutput));
            }
        }
Exemple #21
0
        protected override void HandleRepo(string relativeDir, RepositoryDefinition repoDef, string dir)
        {
            string currentDir = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory(dir);
            try
            {
                PrintLine($"{Cyan}{relativeDir}");
                string program = ExecArgs.First();
                string args    = string.Join(" ", ExecArgs.Skip(1).ToArray());

                var cc = new ConsoleCapture(program, args)
                         .OnOutput(line => PrintLine(line))
                         .OnError(line => PrintLine($"{Red}{line}"));
                cc.Start();

                PrintBlank();
            }
            finally
            {
                Directory.SetCurrentDirectory(currentDir);
            }
        }
Exemple #22
0
        public static void GameState_WhenFirstInitialised_DisplaysCorrectly()
        {
            using (ConsoleCapture theConsole = new ConsoleCapture())
            {
                // Arrange
                string theExpectedOutput =
                    "\r\n" +
                    "Here's the current state of the game board:\r\n" +
                    "\r\n" +
                    " | | \r\n" +
                    "-|-|-\r\n" +
                    " | | \r\n" +
                    "-|-|-\r\n" +
                    " | | \r\n";
                GameState theGameState = new GameState();

                // Act
                theGameState.Display();

                // Assert
                Assert.That(theConsole.Output, Is.EqualTo(theExpectedOutput));
            }
        }
Exemple #23
0
 public string[] GetLoyaltyEventNames(string externalId)
 {
     using (ConsoleCapture capture = new ConsoleCapture())
     {
         try
         {
             var lwMemberPromoCount = lwSvc.GetLoyaltyEventNames(externalId, out double time);
             return(lwMemberPromoCount);
         }
         catch (LWClientException ex)
         {
             throw new LWServiceException(ex.Message, ex.ErrorCode);
         }
         catch (Exception ex)
         {
             throw new LWServiceException(ex.Message, -1);
         }
         finally
         {
             stepContext.AddAttachment(new Attachment("GetLoyaltyEventNames", capture.Output, Attachment.Type.Text));
         }
     }
 }
Exemple #24
0
        public void Test_ShowHelp()
        {
            string[] args = { "-help" };

            string result = null;

            using (ConsoleCapture c = new ConsoleCapture()) {
                ConsoleDriver.Main(args);
                result = c.Close();
            }

            // using a regular expression look for a plausible version number and valid copyright date
            string expression = @"^NAnt (?<infoMajor>[0-9]+).(?<infoMinor>[0-9]+) "
                                + @"\(Build (?<buildMajor>[0-9]+).(?<buildMinor>[0-9]+).(?<buildBuild>[0-9]+).(?<buildRevision>[0-9]+); "
                                + @"(?<configuration>.*); (?<releasedate>.*)\)"
                                + ".*\n" + @"Copyright \(C\) 2001-(?<year>20[0-9][0-9]) Gerry Shaw";

            Match match = Regex.Match(result, expression);

            Assert.IsTrue(match.Success, "Help text does not appear to be valid.");
            int infoMajor     = Int32.Parse(match.Groups["infoMajor"].Value);
            int infoMinor     = Int32.Parse(match.Groups["infoMinor"].Value);
            int buildMajor    = Int32.Parse(match.Groups["buildMajor"].Value);
            int buildMinor    = Int32.Parse(match.Groups["buildMinor"].Value);
            int buildBuild    = Int32.Parse(match.Groups["buildBuild"].Value);
            int buildRevision = Int32.Parse(match.Groups["buildRevision"].Value);
            int year          = Int32.Parse(match.Groups["year"].Value);

            Assert.IsTrue(infoMajor >= 0, "Version numbers must be positive.");
            Assert.IsTrue(infoMinor >= 0, "Version numbers must be positive.");
            Assert.IsTrue(buildMajor >= 0, "Version numbers must be positive.");
            Assert.IsTrue(buildMinor >= 0, "Version numbers must be positive.");
            Assert.IsTrue(buildBuild >= 0, "Version numbers must be positive.");
            Assert.IsTrue(buildRevision >= 0, "Version numbers must be positive.");
            Assert.IsTrue(year <= DateTime.Now.Year, "Copyright year should be equal or less than current year.");
        }
        public void CanResetConfiguration()
        {
            var capture = new ConsoleCapture();

            var o = new object();

            HConsole.Configure(o, config => config.SetMaxLevel(1));

            using (capture.Output())
            {
                HConsole.WriteLine(o, 1, "text1");
            }

            Assert.That(capture.ReadToEnd().ToLf(), Is.EqualTo($"{Prefix()}text1\n".ToLf()));

            HConsole.Reset();

            using (capture.Output())
            {
                HConsole.WriteLine(o, 1, "text0");
            }

            Assert.That(capture.ReadToEnd(), Is.EqualTo(""));
        }
Exemple #26
0
 public ConsoleTest()
 {
     Capture = new ConsoleCapture();
     Console.SetOut(Capture);
     engine = new Engine();
 }
Exemple #27
0
        public void DoTestShowProjectHelp(string nantNamespace, string prefix)
        {
            string buildFileContents = @"<?xml version='1.0' ?>
                <{1}{2}project {0} name='Hello World' default='build' basedir='.'>

                    <{1}{2}property name='basename' value='HelloWorld'/>
                    <{1}{2}target name='init'/> <!-- fake subtarget for unit test -->

                    <{1}{2}target name='clean' description='cleans build directory'>
                        <{1}{2}delete file='${{basename}}.exe' failonerror='false'/>
                    </{1}{2}target>

                    <{1}{2}target name='build' description='compiles the source code'>
                        <{1}{2}csc target='exe' output='${{basename}}.exe'>
                            <{1}{2}sources>
                                <{1}{2}include name='${{basename}}.cs'/>
                            </{1}{2}sources>
                        </{1}{2}csc>
                    </{1}{2}target>

                    <{1}{2}target name='test' depends='build' description='run the program'>
                        <{1}{2}exec program='${{basename}}.exe'/>
                    </{1}{2}target>
                </{1}{2}project>";

            string colon         = prefix.Length == 0? string.Empty: ":";
            string namespaceDecl = nantNamespace.Length == 0? string.Empty:
                                   string.Format("xmlns{2}{1}=\"{0}\"", nantNamespace, prefix, colon);
            // write build file to temp file
            string buildFileName = CreateTempFile("buildfile.xml", string.Format(buildFileContents, namespaceDecl, prefix, colon));

            Assert.IsTrue(File.Exists(buildFileName), buildFileName + " does not exist.");

            X.XmlDocument document = new Project(buildFileName, Level.Warning, 0).Document;
            Assert.AreEqual(nantNamespace, document.DocumentElement.NamespaceURI);
            string result = null;

            using (ConsoleCapture c = new ConsoleCapture()) {
                ConsoleDriver.ShowProjectHelp(document);
                result = c.Close();
            }

            /* expecting output in the form of"
             *
             *  Default Target:
             *
             *   build         compiles the source code
             *
             *  Main Targets:
             *
             *   clean         cleans build directory
             *   build         compiles the source code
             *   test          run the program
             *
             *  Sub Targets:
             *
             *   init
             */

            // using a regular expression to look for valid output
            // expression created by RegEx http://www.organicbit.com/regex/
            string expression = @"Default Target:[\s]*(?<default>build)\s*compiles the source code[\s]*Main Targets:[\s]*(?<main1>build)\s*compiles the source code[\s]*(?<main2>clean)\s*cleans build directory[\s]*(?<main3>test)\s*run the program[\s]*Sub Targets:[\s]*(?<subtarget1>init)";

            Match match = Regex.Match(result, expression);

            if (match.Success)
            {
                Assert.AreEqual("build", match.Groups["default"].Value);
                Assert.AreEqual("build", match.Groups["main1"].Value);
                Assert.AreEqual("clean", match.Groups["main2"].Value);
                Assert.AreEqual("test", match.Groups["main3"].Value);
                Assert.AreEqual("init", match.Groups["subtarget1"].Value);
            }
            else
            {
                Assert.Fail("Project help text does not appear to be valid, see results for details:" + Environment.NewLine + result);
            }

            // delete the build file
            File.Delete(buildFileName);
            Assert.IsFalse(File.Exists(buildFileName), buildFileName + " exists.");
        }
Exemple #28
0
 public void Setup()
 {
     _consoleCapture = new ConsoleCapture();
 }