コード例 #1
0
ファイル: ConsoleTest.cs プロジェクト: LosManos/LehmanLaidun
        public void OutputOneFolderAsXml()
        {
            //  As the output from the console contains information which is hard to compare between environments,
            //  like path and lastWriteTime, we choose to compare only simpler attributes.
            var expectedOutput =
                @"<root >
                  <directory name=""Summer 2018"">
                    <file name=""Birds at pier.jfif"" />
                    <file name=""field.jpg"" />
                    <file name=""swans.jpg"" />
                  </directory>
                </root>";

            var arguments =
                "--mypath=" + Path.Combine(TheFileSystem.FindDataPath(), MethodBase.GetCurrentMethod() !.Name, "ADrive") +
                " " +
                "--ox";

            //  Act.
            var output = TheFileSystem.Execute(arguments);

            //  Assert.
            //  It is hard to compare the string output as it contains environment information,
            //  like path, so we convert everything to Xml and compare just some attributes;
            //  but we do also compare the whole structure.
            var result = Logic.CompareXml(
                XDocument.Parse(expectedOutput),
                XDocument.Parse(output),
                new[] { "name", "length" });

            result.Result.Should().BeTrue();
        }
コード例 #2
0
 /// <summary>This method executes the console application
 /// with the parameters provided
 /// and returns the result.
 /// </summary>
 /// <param name="arguments"></param>
 /// <returns></returns>
 internal static string Execute(string arguments)
 {
     using (var p = new Process())
     {
         p.StartInfo.FileName               = TheFileSystem.FindConsoleExecutable();
         p.StartInfo.WorkingDirectory       = TheFileSystem.FindTesteePrjPath();
         p.StartInfo.Arguments              = arguments;
         p.StartInfo.UseShellExecute        = false;
         p.StartInfo.RedirectStandardOutput = true;
         p.Start();
         string output = p.StandardOutput.ReadToEnd();
         p.WaitForExit();
         if (p.ExitCode != 0)
         {
             output = output + Environment.NewLine + $"ExitCode=[{p.ExitCode}]{Environment.NewLine}{output}";
         }
         return(output.NormaliseLineEndings());
     }
 }
コード例 #3
0
ファイル: ConsoleTest.cs プロジェクト: LosManos/LehmanLaidun
        public void CompareTwoFolders()
        {
            var expectedOutput =
                @"Found only in first:/root/directory[@name='Summer 2018']/file[@name='cat.jpg'].
Found only in first:/root/directory[@name='Summer 2018']/file[@name='museum.jpg'].
Found only in second:/root/directory[@name='Summer 2018']/file[@name='Birds at pier.jfif'].
".NormaliseLineEndings().Split("\r\n");

            var arguments =
                "--mypath=" + Path.Combine(TheFileSystem.FindDataPath(), MethodBase.GetCurrentMethod() !.Name, "MyDrive") +
                " " +
                "--theirpath=" + Path.Combine(TheFileSystem.FindDataPath(), MethodBase.GetCurrentMethod() !.Name, "TheirDrive");

            //  Act.
            var output = TheFileSystem.Execute(arguments);

            //  Assert.
            output.NormaliseLineEndings().Split("\r\n").OrderBy(s => s)
            .Should().BeEquivalentTo(expectedOutput, options => options.WithoutStrictOrdering());
        }