public static async Task <Project> DotnetNew(
            this TempDirectory tempDirectory,
            string templateName,
            string name,
            IDictionary <string, string> arguments = null,
            TimeSpan?timeout = null)
        {
            var stringBuilder = new StringBuilder($"new {templateName} --name \"{name}\"");

            if (arguments != null)
            {
                foreach (var argument in arguments)
                {
                    stringBuilder.Append($" --{argument.Key} \"{argument.Value}\"");
                }
            }

            await ProcessAssert.AssertStart(
                tempDirectory.DirectoryPath,
                "dotnet",
                stringBuilder.ToString(),
                CancellationTokenFactory.GetCancellationToken(timeout));

            var projectDirectoryPath = Path.Combine(tempDirectory.DirectoryPath, name);
            var projectFilePath      = Path.Combine(projectDirectoryPath, name + ".csproj");
            var publishDirectoryPath = Path.Combine(projectDirectoryPath, "Publish");

            return(new Project(name, projectFilePath, projectDirectoryPath, publishDirectoryPath));
        }
Пример #2
0
        public static Task DotnetBuild(this Project project, bool?noRestore = true, TimeSpan?timeout = null)
        {
            var noRestoreArgument = noRestore == null ? null : "--no-restore";

            return(ProcessAssert.AssertStart(
                       project.DirectoryPath,
                       "dotnet",
                       $"build {noRestoreArgument}",
                       CancellationTokenFactory.GetCancellationToken(timeout)));
        }
Пример #3
0
        public static async Task <Project> DotnetNew(
            this TempDirectory tempDirectory,
            string templateName,
            string name      = null,
            TimeSpan?timeout = null)
        {
            await ProcessAssert.AssertStart(tempDirectory.DirectoryPath, "dotnet", $"new {templateName} --name \"{name}\"", timeout ?? TimeSpan.FromSeconds(20));

            var projectDirectoryPath = Path.Combine(tempDirectory.DirectoryPath, name);
            var projectFilePath      = Path.Combine(projectDirectoryPath, name + ".csproj");
            var publishDirectoryPath = Path.Combine(projectDirectoryPath, "Publish");

            return(new Project(name, projectFilePath, projectDirectoryPath, publishDirectoryPath));
        }
Пример #4
0
        public static Task DotnetPublish(
            this Project project,
            string framework = null,
            string runtime   = null,
            bool?noRestore   = true,
            TimeSpan?timeout = null)
        {
            var frameworkArgument = framework == null ? null : $"--framework {framework}";
            var runtimeArgument   = runtime == null ? null : $"--self-contained --runtime {runtime}";
            var noRestoreArgument = noRestore == null ? null : "--no-restore";

            DirectoryExtended.CheckCreate(project.PublishDirectoryPath);
            return(ProcessAssert.AssertStart(
                       project.DirectoryPath,
                       "dotnet",
                       $"publish {noRestoreArgument} {frameworkArgument} {runtimeArgument} --output {project.PublishDirectoryPath}",
                       CancellationTokenFactory.GetCancellationToken(timeout)));
        }
Пример #5
0
        public static async Task DotnetRun(this Project project, Func <Task> action, TimeSpan?delay = null)
        {
            var cancellationTokenSource = new CancellationTokenSource();
            var task = ProcessAssert.AssertStart(
                project.DirectoryPath,
                "dotnet",
                "run",
                cancellationTokenSource.Token);
            await Task.Delay(delay ?? TimeSpan.FromSeconds(3));

            Exception unhandledException = null;

            try
            {
                await action();
            }
            catch (Exception exception)
            {
                unhandledException = exception;
            }

            cancellationTokenSource.Cancel();

            try
            {
                await task;
            }
            catch (ProcessStartException exception) when(exception.GetBaseException() is TaskCanceledException)
            {
            }

            if (unhandledException != null)
            {
                Assert.False(true, unhandledException.ToString());
            }
        }
Пример #6
0
 public static Task DotnetNewInstall(string source, TimeSpan?timeout = null) =>
 ProcessAssert.AssertStart(
     DirectoryExtended.GetCurrentDirectory(),
     "dotnet",
     $"new --install \"{source}\"",
     timeout ?? TimeSpan.FromSeconds(20));
Пример #7
0
 public static Task DotnetRestore(this Project project, TimeSpan?timeout = null) =>
 ProcessAssert.AssertStart(
     project.DirectoryPath,
     "dotnet",
     "restore",
     CancellationTokenFactory.GetCancellationToken(timeout));
Пример #8
0
 public static Task DotnetNewInstall(string source, TimeSpan?timeout = null) =>
 ProcessAssert.AssertStart(
     DirectoryExtended.GetCurrentDirectory(),
     "dotnet",
     $"new --install \"{source}\"",
     CancellationTokenFactory.GetCancellationToken(timeout));
Пример #9
0
        public static Task DotnetBuild(this Project project, bool?noRestore = true, TimeSpan?timeout = null)
        {
            var noRestoreArgument = noRestore == null ? null : "--no-restore";

            return(ProcessAssert.AssertStart(project.DirectoryPath, "dotnet", $"build {noRestoreArgument}", timeout ?? TimeSpan.FromSeconds(20)));
        }
Пример #10
0
 public static Task DotnetRestore(this Project project, TimeSpan?timeout = null) =>
 ProcessAssert.AssertStart(project.DirectoryPath, "dotnet", "restore", timeout ?? TimeSpan.FromSeconds(20));