public void PublishOptionsTest(string testIdentifier, string framework, string runtime, string config, string outputDir) { TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithLibrary", identifier: testIdentifier) .WithLockFiles() .WithBuildArtifacts(); string testRoot = _getProjectJson(instance.TestRoot, "TestApp"); outputDir = string.IsNullOrEmpty(outputDir) ? "" : Path.Combine(instance.TestRoot, outputDir); var publishCommand = new PublishCommand(testRoot, output: outputDir); publishCommand.Execute().Should().Pass(); // verify the output executable generated var publishedDir = publishCommand.GetOutputDirectory(); var outputExe = publishCommand.GetOutputExecutable(); var outputPdb = Path.ChangeExtension(outputExe, "pdb"); // lets make sure that the output exe is runnable var outputExePath = Path.Combine(publishedDir.FullName, publishCommand.GetOutputExecutable()); var command = new TestCommand(outputExePath); command.Execute("").Should().ExitWith(100); // the pdb should also be published publishedDir.Should().HaveFile(outputPdb); }
public void PublishOptionsTest(string framework, string runtime, string config, string outputDir) { // create unique directories in the 'temp' folder var root = Temp.CreateDirectory(); var testAppDir = root.CreateDirectory("TestApp"); var testLibDir = root.CreateDirectory("TestLibrary"); //copy projects to the temp dir CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestApp"), testAppDir); CopyProjectToTempDir(Path.Combine(_testProjectsRoot, "TestLibrary"), testLibDir); RunRestore(testAppDir.Path); RunRestore(testLibDir.Path); // run publish outputDir = string.IsNullOrEmpty(outputDir) ? "" : Path.Combine(root.Path, outputDir); var testProject = GetProjectPath(testAppDir); var publishCommand = new PublishCommand(testProject, output: outputDir); publishCommand.Execute().Should().Pass(); // verify the output executable generated var publishedDir = publishCommand.GetOutputDirectory(); var outputExe = publishCommand.GetOutputExecutable(); var outputPdb = Path.ChangeExtension(outputExe, "pdb"); // lets make sure that the output exe is runnable var outputExePath = Path.Combine(publishedDir.FullName, publishCommand.GetOutputExecutable()); var command = new TestCommand(outputExePath); command.Execute("").Should().ExitWith(100); // the pdb should also be published publishedDir.Should().HaveFile(outputPdb); }
protected void TestOutputExecutable(string outputDir, string executableName, string expectedOutput) { var executablePath = Path.Combine(outputDir, executableName); var executableCommand = new TestCommand(executablePath); var result = executableCommand.ExecuteWithCapturedOutput(""); result.Should().HaveStdOut(expectedOutput); result.Should().NotHaveStdErr(); result.Should().Pass(); }
public void When_dotnet_build_is_invoked_Then_project_builds_without_warnings() { var rootPath = Temp.CreateDirectory().Path; new TestCommand("dotnet") { WorkingDirectory = rootPath } .Execute("new"); new TestCommand("dotnet") { WorkingDirectory = rootPath } .Execute("restore"); var buildResult = new TestCommand("dotnet") { WorkingDirectory = rootPath } .ExecuteWithCapturedOutput("build"); buildResult.Should().Pass(); buildResult.Should().NotHaveStdErr(); }
public void When_dotnet_test_is_invoked_Then_tests_run_without_errors() { var rootPath = Temp.CreateDirectory().Path; new TestCommand("dotnet") { WorkingDirectory = rootPath } .Execute("new --type xunittest"); new TestCommand("dotnet") { WorkingDirectory = rootPath } .Execute("restore"); var buildResult = new TestCommand("dotnet") .WithWorkingDirectory(rootPath) .ExecuteWithCapturedOutput("test") .Should() .Pass() .And .NotHaveStdErr(); }
public void When_dotnet_new_is_invoked_mupliple_times_it_should_fail() { var rootPath = Temp.CreateDirectory().Path; new TestCommand("dotnet") { WorkingDirectory = rootPath } .Execute("new"); DateTime expectedState = Directory.GetLastWriteTime(rootPath); var result = new TestCommand("dotnet") { WorkingDirectory = rootPath } .ExecuteWithCapturedOutput("new"); DateTime actualState = Directory.GetLastWriteTime(rootPath); Assert.Equal(expectedState, actualState); result.Should().Fail(); result.Should().HaveStdErr(); }
public async Task DesktopApp_WithKestrel_WorksWhenPublished(string project, string url, string runtime, string libuvName, bool forceRunnable) { var runnable = forceRunnable || string.IsNullOrEmpty(runtime) || (RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier().Contains(runtime)); var testInstance = GetTestInstance() .WithLockFiles(); // Prevent path too long failure on CI machines var projectPath = Path.Combine(testInstance.TestRoot, project); var publishCommand = new PublishCommand(projectPath, runtime: runtime, output: Path.Combine(projectPath, "out")); var result = await publishCommand.ExecuteAsync(); result.Should().Pass(); // Test the output var outputDir = publishCommand.GetOutputDirectory(portable: false); outputDir.Should().HaveFile(libuvName); outputDir.Should().HaveFile(publishCommand.GetOutputExecutable()); Task exec = null; if (runnable) { var outputExePath = Path.Combine(outputDir.FullName, publishCommand.GetOutputExecutable()); var command = new TestCommand(outputExePath); try { exec = command.ExecuteAsync(url); NetworkHelper.IsServerUp(url).Should().BeTrue($"Unable to connect to kestrel server - {project} @ {url}"); NetworkHelper.TestGetRequest(url, url); } finally { command.KillTree(); } if (exec != null) { await exec; } } }
public void StandaloneAppHasResourceDependency() { // WindowsAzure.Services brings in en, zh etc. resource DLLs. // The host has to be able to find these assemblies from the deps file // from the standalone app base under the ietf tag directory. var testName = "TestAppWithResourceDeps"; TestInstance instance = TestAssetsManager .CreateTestInstance(testName) .WithLockFiles() .WithBuildArtifacts(); var publishCommand = new PublishCommand(instance.TestRoot); publishCommand.Execute().Should().Pass(); var publishedDir = publishCommand.GetOutputDirectory(); var extension = publishCommand.GetExecutableExtension(); var outputExe = testName + extension; publishedDir.Should().HaveFiles(new[] { $"{testName}.dll", outputExe }); var command = new TestCommand(Path.Combine(publishedDir.FullName, outputExe)); command.Execute("").Should().ExitWith(0); }
public void PublishFailsWhenProjectJsonDoesNotExist() { using (var dir = new DisposableDirectory(Temp)) { var command = new TestCommand("dotnet"); string temp = Path.Combine(dir.Path, "project.json"); command.Execute($"publish {temp}").Should().Fail(); } }
public void PublishFailsWhenProjectRootIsEmpty() { using (var dir = new DisposableDirectory(Temp)) { var command = new TestCommand("dotnet"); command.Execute($"publish {dir.Path}").Should().Fail(); } }
public void PublishAppWithOutputAssemblyName() { TestInstance instance = TestAssetsManager .CreateTestInstance("AppWithOutputAssemblyName") .WithLockFiles() .WithBuildArtifacts(); var testRoot = _getProjectJson(instance.TestRoot, "AppWithOutputAssemblyName"); var publishCommand = new PublishCommand(testRoot, output: testRoot); publishCommand.Execute().Should().Pass(); var publishedDir = publishCommand.GetOutputDirectory(); var extension = publishCommand.GetExecutableExtension(); var outputExe = "MyApp" + extension; publishedDir.Should().HaveFiles(new[] { "MyApp.dll", outputExe }); publishedDir.Should().NotHaveFile("AppWithOutputAssemblyName" + extension); publishedDir.Should().NotHaveFile("AppWithOutputAssemblyName.dll"); var command = new TestCommand(Path.Combine(publishedDir.FullName, outputExe)); command.Execute("").Should().ExitWith(0); }
private void Test(IEnumerable<string> inputs, IEnumerable<string> expectedProjects, string workingDirectory = null, [CallerMemberName] string testName = null) { var instance = TestAssetsManager.CreateTestInstance("TestProjectToProjectDependencies", testName) .WithLockFiles() .WithBuildArtifacts(); string args = string.Join(" ", inputs); workingDirectory = workingDirectory != null ? Path.Combine(instance.TestRoot, workingDirectory) : instance.TestRoot; var result = new TestCommand("dotnet") { WorkingDirectory = Path.Combine(workingDirectory) }.ExecuteWithCapturedOutput("--verbose build --no-dependencies " + args); if (expectedProjects != null) { result.Should().Pass(); foreach (var expectedProject in expectedProjects) { result.Should().HaveSkippedProjectCompilation(expectedProject, NuGetFramework.Parse("netstandard1.5").DotNetFrameworkName); } } else { result.Should().Fail(); } }
public void ItRunsKestrelStandaloneAfterPublish() { TestInstance instance = TestAssetsManager.CreateTestInstance(KestrelSampleBase) .WithLockFiles(); var url = NetworkHelper.GetLocalhostUrlWithFreePort(); var args = $"{url} {Guid.NewGuid().ToString()}"; var output = Publish(Path.Combine(instance.TestRoot, KestrelStandalone), false); var command = new TestCommand(output); try { command.ExecuteAsync($"{args}"); NetworkHelper.IsServerUp(url).Should().BeTrue($"Unable to connect to kestrel server - {KestrelStandalone} @ {url}"); NetworkHelper.TestGetRequest(url, args); } finally { command.KillTree(); } }
protected void TestExecutable(string outputDir, string executableName, string expectedOutput) { var executablePath = Path.Combine(outputDir, executableName); var args = new List<string>(); if (IsPortable(executablePath)) { args.Add("exec"); args.Add(ArgumentEscaper.EscapeSingleArg(executablePath)); var muxer = new Muxer(); executablePath = muxer.MuxerPath; } var executableCommand = new TestCommand(executablePath); var result = executableCommand.ExecuteWithCapturedOutput(string.Join(" ", args)); result.Should().HaveStdOut(expectedOutput); result.Should().NotHaveStdErr(); result.Should().Pass(); }
public void TestDotnetRun() { var restoreCommand = new TestCommand("dotnet"); restoreCommand.Execute($"restore {TestProject}") .Should() .Pass(); var runCommand = new RunCommand(TestProject); runCommand.Execute() .Should() .Pass(); }