Ejemplo n.º 1
0
        public void Execute(string format, string version)
        {
            var tempFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));

            try
            {
                var rootDirectory      = Directory.CreateDirectory(tempFolder);
                var inputDirectory     = Directory.CreateDirectory(Path.Combine(rootDirectory.FullName, "input"));
                var packagedDirectory  = Directory.CreateDirectory(Path.Combine(rootDirectory.FullName, "packaged"));
                var extractedDirectory = Directory.CreateDirectory(Path.Combine(rootDirectory.FullName, "extracted"));
                File.WriteAllText(Path.Combine(inputDirectory.FullName, "Test.txt"), "Test");
                File.WriteAllText(Path.Combine(inputDirectory.FullName, "Test[squarebrackets].txt"), "Test");

                var args = new List <string>
                {
                    "pack",
                    "--id=TestPackage",
                    $"--basePath={inputDirectory.FullName}",
                    $"--outFolder={packagedDirectory.FullName}",
                    $"--format={format}"
                };

                if (!string.IsNullOrWhiteSpace(version))
                {
                    args.Add($"--version={version}");
                }

                var now    = DateTime.Now;
                var result = new CliProgram().Run(args.ToArray());

                result.Should().Be(0);

                if (!string.IsNullOrWhiteSpace(version))
                {
                    var expectedOutputFilePath = Path.Combine(packagedDirectory.FullName, $"TestPackage.{version}.{format}");
                    File.Exists(expectedOutputFilePath)
                    .Should()
                    .BeTrue("the package should have been given the right name.");
                }
                else
                {
                    var searchPattern = $"TestPackage.{now.Year}.{now.Month}.{now.Day}.*.{format}";
                    var files         = Directory.GetFiles(packagedDirectory.FullName, searchPattern, SearchOption.TopDirectoryOnly);
                    files.Should().HaveCount(1, "There should be a package where the version is calculated from the date");
                }

                // TODO: It would be really nice to have a simple end-to-end test that proves we can pack/unpack files preserving filenames and timestamps etc...
                //var calamariResult = SilentProcessRunner.ExecuteCommand(@"C:\dev\Calamari\source\Calamari\bin\Debug\netcoreapp1.0\win7-x64\Calamari.exe",
                //    $"extract-package --package={expectedOutputFilePath} --target={extractedDirectory.FullName}", rootDirectory.FullName, Console.WriteLine, Console.WriteLine);
                //calamariResult.Should().Be(0);

                //var extractedFiles = Directory.GetFiles(extractedDirectory.FullName, "*", SearchOption.AllDirectories).Select(x => x.Replace(extractedDirectory.FullName, ""));
                //var inputFiles = Directory.GetFiles(inputDirectory.FullName, "*", SearchOption.AllDirectories).Select(x => x.Replace(inputDirectory.FullName, ""));
                //extractedFiles.ShouldAllBeEquivalentTo(inputFiles);
            }
            finally
            {
                Directory.Delete(tempFolder, true);
            }
        }
Ejemplo n.º 2
0
        static CommandLineOptions.CommandLineOptions Parse(string [] args)
        {
            var result = CliProgram.Parse(args);

            if (result.Tag == CommandLine.ParserResultType.NotParsed)
            {
                return(null);
            }

            var options = ((CommandLine.Parsed <CommandLineOptions.CommandLineOptions>)result).Value;

            if (string.IsNullOrEmpty(options.Format))
            {
                options.Format = MarkdownWriters.First().FormatName;
            }
            if (options.IgnoreMethods)
            {
                options.DocumentMethodDetails = false;
            }
            if (options.AssemblyName != null && options.OutputFile == null)
            {
                options.OutputFile = Path.GetFileNameWithoutExtension(options.AssemblyName) + ".md";
            }
            return(options);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var console = new ConsoleWriter();

            CliProgram.Run(args,
                           (option) => Sample(option, console),
                           (option) => InlineGenerate(option, console),
                           (option) => Generate(option, console));
        }
Ejemplo n.º 4
0
        public void CheckModifiedDate(string format, string version)
        {
            var tempFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));

            try
            {
                var rootDirectory     = Directory.CreateDirectory(tempFolder);
                var inputDirectory    = Directory.CreateDirectory(Path.Combine(rootDirectory.FullName, "input"));
                var packagedDirectory = Directory.CreateDirectory(Path.Combine(rootDirectory.FullName, "packaged"));
                var inputFile         = Path.Combine(inputDirectory.FullName, "Test.txt");
                File.WriteAllText(inputFile, "Test");
                var lastModified = File.GetLastWriteTime(inputFile);

                // sleep a few seconds so our last modified time is not the same as the package creation time
                Thread.Sleep(TimeSpan.FromSeconds(5));

                var result = new CliProgram().Run(
                    new[]
                {
                    "pack",
                    "--id=TestPackage",
                    $"--basePath={inputDirectory.FullName}",
                    $"--outFolder={packagedDirectory.FullName}",
                    $"--version={version}",
                    $"--format={format}"
                }
                    );

                result.Should().Be(0);
                var expectedOutputFilePath = Path.Combine(packagedDirectory.FullName, $"TestPackage.{version}.{format}");
                File.Exists(expectedOutputFilePath)
                .Should()
                .BeTrue("the package should have been given the right name.");

                using (var stream = new FileStream(expectedOutputFilePath, FileMode.Open))
                    using (var archive = new ZipArchive(stream, ZipArchiveMode.Read))
                    {
                        var entry = archive.GetEntry("Test.txt");
                        (entry.LastWriteTime - lastModified).Duration().Should().BeLessThan(TimeSpan.FromSeconds(2), "the file should keep its modified date");
                    }
            }
            finally
            {
                Directory.Delete(tempFolder, true);
            }
        }
Ejemplo n.º 5
0
        internal ExecuteResult Execute(string command, params string[] args)
        {
            var logOutput = new StringBuilder();

            Log.Logger = new LoggerConfiguration()
                         .WriteTo.ColoredConsole(outputTemplate: "{Message}{NewLine}{Exception}")
                         .WriteTo.TextWriter(new StringWriter(logOutput), outputTemplate: "{Message}{NewLine}{Exception}")
                         .CreateLogger();

            var allArgs = new[]
            {
                command,
                $"--server={HostBaseUri}{TestRootPath}",
                "--apiKey=ABCDEF123456789"
            }.Concat(args)
            .ToArray();

            var code = new CliProgram().Run(allArgs);

            return(new ExecuteResult(code, logOutput.ToString()));
        }
Ejemplo n.º 6
0
 private static int Main(string[] args)
 {
     try
     {
         CliProgram.MainLogic(args);
         return(0);
     }
     catch (Exception e)
     {
         System.Console.Error.WriteLine(ExceptionDetails.GetDetails("Something went wrong.", e));
         return(-1);
     }
     finally
     {
         if (Debugger.IsAttached)
         {
             System.Console.Error.WriteLine("Press Enter to quit...");
             System.Console.ReadLine();
         }
     }
 }