public void ItPublishesARunnableSelfContainedApp() { var testAppName = "MSBuildTestApp"; var testInstance = TestAssets.Get(testAppName) .CreateInstance() .WithSourceFiles() .WithRestoreFiles(); var testProjectDirectory = testInstance.Root; var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); new PublishCommand() .WithFramework("netcoreapp1.0") .WithRuntime(rid) .WithWorkingDirectory(testProjectDirectory) //Workaround for https://github.com/dotnet/cli/issues/4501 .WithEnvironmentVariable("SkipInvalidConfigurations", "true") .Execute("/p:SkipInvalidConfigurations=true") .Should().Pass(); var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug"; var outputProgram = testProjectDirectory .GetDirectory("bin", configuration, "netcoreapp1.0", rid, "publish", $"{testAppName}{Constants.ExeSuffix}") .FullName; new TestCommand(outputProgram) .ExecuteWithCapturedOutput() .Should().Pass() .And.HaveStdOutContaining("Hello World"); }
public void MStestMultiTFM() { var testProjectDirectory = TestAssets.Get("VSTestDesktopAndNetCore") .CreateInstance() .WithSourceFiles() .WithNuGetConfig(new RepoDirectoriesProvider().TestPackages) .Root; var runtime = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); new RestoreCommand() .WithWorkingDirectory(testProjectDirectory) .WithRuntime(runtime) .Execute() .Should().Pass(); var result = new DotnetTestCommand() .WithWorkingDirectory(testProjectDirectory) .WithRuntime(runtime) .ExecuteWithCapturedOutput(TestBase.ConsoleLoggerOutputNormal); result.StdOut .Should().Contain("Total tests: 3. Passed: 2. Failed: 1. Skipped: 0.", "because .NET 4.6 tests will pass") .And.Contain("Passed TestNamespace.VSTestTests.VSTestPassTestDesktop", "because .NET 4.6 tests will pass") .And.Contain("Total tests: 3. Passed: 1. Failed: 2. Skipped: 0.", "because netcoreapp2.0 tests will fail") .And.Contain("Failed TestNamespace.VSTestTests.VSTestFailTestNetCoreApp", "because netcoreapp2.0 tests will fail"); result.ExitCode.Should().Be(1); }
public void TestLibraryBindingRedirectGeneration() { TestInstance instance = TestAssetsManager.CreateTestInstance("TestBindingRedirectGeneration") .WithLockFiles() .WithBuildArtifacts(); var lesserTestProject = _getProjectJson(instance.TestRoot, "TestLibraryLesser"); var publishCommand = new PublishCommand(lesserTestProject, "net451"); publishCommand.Execute().Should().Pass(); publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.exe"); publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.pdb"); publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.exe.config"); publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryLesser.deps.json"); // dependencies should also be copied publishCommand.GetOutputDirectory().Should().HaveFile("Newtonsoft.Json.dll"); publishCommand.GetOutputDirectory().Delete(true); publishCommand = new PublishCommand( lesserTestProject, "netcoreapp1.0", DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier()); publishCommand.Execute().Should().Pass(); publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.dll"); publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.pdb"); publishCommand.GetOutputDirectory().Should().NotHaveFile("TestLibraryLesser.dll.config"); publishCommand.GetOutputDirectory().Should().HaveFile("TestLibraryLesser.deps.json"); // dependencies should also be copied publishCommand.GetOutputDirectory().Should().HaveFile("Newtonsoft.Json.dll"); }
public void ItPublishesSuccessfullyWithNoBuildIfPreviouslyBuilt(bool selfContained) { var testInstance = TestAssets.Get("TestAppSimple") .CreateInstance(nameof(ItPublishesSuccessfullyWithNoBuildIfPreviouslyBuilt) + selfContained) .WithSourceFiles(); var rootPath = testInstance.Root; var rid = selfContained ? DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier() : ""; var ridArg = selfContained ? $"-r {rid}" : ""; new BuildCommand() .WithWorkingDirectory(rootPath) .ExecuteWithCapturedOutput(ridArg) .Should() .Pass(); new PublishCommand() .WithWorkingDirectory(rootPath) .ExecuteWithCapturedOutput($"{ridArg} --no-build") .Should() .Pass(); var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug"; var outputProgram = rootPath .GetDirectory("bin", configuration, "netcoreapp3.0", rid, "publish", $"{rootPath.Name}.dll") .FullName; new TestCommand(outputProgram) .ExecuteWithCapturedOutput() .Should() .Pass() .And.HaveStdOutContaining("Hello World"); }
public void ItTestsWithTheSpecifiedRuntimeOption() { var testInstance = TestAssets.Get("XunitCore") .CreateInstance() .WithSourceFiles(); var rootPath = testInstance.Root.FullName; var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); new BuildCommand() .WithWorkingDirectory(rootPath) .ExecuteWithCapturedOutput($"--runtime {rid}") .Should() .Pass() .And.NotHaveStdErr(); var result = new DotnetTestCommand() .WithWorkingDirectory(rootPath) .ExecuteWithCapturedOutput($"{TestBase.ConsoleLoggerOutputNormal} --no-build --runtime {rid}"); result .Should() .NotHaveStdErrContaining("MSB1001") .And .HaveStdOutContaining(rid); if (!DotnetUnderTest.IsLocalized()) { result.StdOut.Should().Contain("Total tests: 2"); result.StdOut.Should().Contain("Passed: 1"); result.StdOut.Should().Contain("Failed: 1"); } result.ExitCode.Should().Be(1); }
public void ItPublishesFrameworkDependentWithRid(string args) { var testAppName = "MSBuildTestApp"; var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); var outputDirectory = PublishApp(testAppName, rid, args); outputDirectory.Should().OnlyHaveFiles(new[] { $"{testAppName}{Constants.ExeSuffix}", $"{testAppName}.dll", $"{testAppName}.pdb", $"{testAppName}.deps.json", $"{testAppName}.runtimeconfig.json", }); var outputProgram = Path.Combine(outputDirectory.FullName, $"{testAppName}{Constants.ExeSuffix}"); var command = new TestCommand(outputProgram); command.Environment[Environment.Is64BitProcess ? "DOTNET_ROOT" : "DOTNET_ROOT(x86)"] = new RepoDirectoriesProvider().DotnetRoot; command.ExecuteWithCapturedOutput() .Should() .Pass() .And .HaveStdOutContaining("Hello World"); }
public void ItPublishesARunnableSelfContainedApp() { var testAppName = "MSBuildTestApp"; var testInstance = TestAssetsManager .CreateTestInstance(testAppName); var testProjectDirectory = testInstance.TestRoot; var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); new Publish3Command() .WithFramework("netcoreapp1.0") .WithRuntime(rid) .WithWorkingDirectory(testProjectDirectory) .Execute() .Should() .Pass(); var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug"; var outputProgram = Path.Combine(testProjectDirectory, "bin", configuration, "netcoreapp1.0", rid, "publish", $"{testAppName}{Constants.ExeSuffix}"); new TestCommand(outputProgram) .ExecuteWithCapturedOutput() .Should() .Pass() .And .HaveStdOutContaining("Hello World"); }
public void It_resolves_desktop_apps_when_configuration_is_Debug() { var runtime = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); var configuration = "Debug"; var testInstance = TestAssets.Get(TestAssetKinds.DesktopTestProjects, "AppWithProjTool2Fx") .CreateInstance() .WithSourceFiles() .WithNuGetConfig(_repoDirectoriesProvider.TestPackages); var restoreCommand = new RestoreCommand() .WithWorkingDirectory(testInstance.Root) .WithRuntime(runtime) .ExecuteWithCapturedOutput() .Should().Pass(); var buildCommand = new BuildCommand() .WithWorkingDirectory(testInstance.Root) .WithConfiguration(configuration) .WithRuntime(runtime) .Execute() .Should().Pass(); var factory = new ProjectDependenciesCommandFactory( s_desktopTestFramework, configuration, null, null, testInstance.Root.FullName); var command = factory.Create("dotnet-desktop-and-portable", null); command.CommandName.Should().Contain(testInstance.Root.GetDirectory("bin", configuration).FullName); Path.GetFileName(command.CommandName).Should().Be("dotnet-desktop-and-portable.exe"); }
public void It_passes_a_RuntimeOutputDir_variable_to_the_pre_compile_scripts_if_rid_is_set_in_the_ProjectContext() { var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); var fixture = ScriptVariablesFixture.GetFixtureWithRids(rid); fixture.PreCompileScriptVariables.Should().ContainKey("compile:RuntimeOutputDir"); fixture.PreCompileScriptVariables["compile:RuntimeOutputDir"].Should().Be(fixture.RuntimeOutputDir); }
public void ItPublishesAnAppWithMultipleProfiles() { var testAppName = "MultiDependentProject"; var profileProjectName = "NewtonsoftProfile"; var profileProjectName1 = "FluentProfile"; var testInstance = TestAssets.Get(testAppName) .CreateInstance() .WithSourceFiles() .UseCurrentRuntimeFrameworkVersion(); var testProjectDirectory = testInstance.Root.ToString(); var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); var localAssemblyCache = Path.Combine(testProjectDirectory, "lAC"); var intermediateWorkingDirectory = Path.Combine(testProjectDirectory, "workingDirectory"); var profileProjectPath = TestAssets.Get(profileProjectName).Root.FullName; var profileProject = Path.Combine(profileProjectPath, $"{profileProjectName}.xml"); var profileFilter = Path.Combine(profileProjectPath, "NewtonsoftFilterProfile.xml"); var profileProjectPath1 = TestAssets.Get(profileProjectName1).Root.FullName; var profileProject1 = Path.Combine(profileProjectPath1, $"{profileProjectName1}.xml"); var profileFilter1 = Path.Combine(profileProjectPath1, "FluentFilterProfile.xml"); new RestoreCommand() .WithWorkingDirectory(testProjectDirectory) .Execute() .Should().Pass(); new CacheCommand() .WithEntries(profileProject) .WithEntries(profileProject1) .WithFramework(_tfm) .WithRuntime(rid) .WithOutput(localAssemblyCache) .WithRuntimeFrameworkVersion(_frameworkVersion) .WithIntermediateWorkingDirectory(intermediateWorkingDirectory) .Execute($"--preserve-working-dir") .Should().Pass(); var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug"; new PublishCommand() .WithFramework(_tfm) .WithWorkingDirectory(testProjectDirectory) .WithProFileProject(profileFilter) .WithProFileProject(profileFilter1) .Execute() .Should().Pass(); var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, _tfm, "publish", $"{testAppName}.dll"); new DotnetCommand() .WithEnvironmentVariable("DOTNET_SHARED_PACKAGES", localAssemblyCache) .ExecuteWithCapturedOutput(outputDll) .Should().Pass() .And.HaveStdOutContaining("{}"); }
public void ItAutoAddDesktopReferencesDuringMigrate(string testGroup, string projectName, bool isDesktopApp) { var runtime = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); var testAssetManager = GetTestGroupTestAssetsManager(testGroup); var projectDirectory = testAssetManager.CreateTestInstance(projectName).WithLockFiles().Path; CleanBinObj(projectDirectory); MigrateProject(new string[] { projectDirectory }); Restore(projectDirectory, runtime: runtime); BuildMSBuild(projectDirectory, projectName, runtime: runtime); VerifyAutoInjectedDesktopReferences(projectDirectory, projectName, isDesktopApp); VerifyAllMSBuildOutputsRunnable(projectDirectory); }
public void ItPublishesSelfContainedWithRid(string args) { var testAppName = "MSBuildTestApp"; var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); var outputDirectory = PublishApp(testAppName, rid, args); var outputProgram = Path.Combine(outputDirectory.FullName, $"{testAppName}{Constants.ExeSuffix}"); new TestCommand(outputProgram) .ExecuteWithCapturedOutput() .Should().Pass() .And.HaveStdOutContaining("Hello World"); }
public void ItPublishesARunnablePortableApp() { var testAppName = "NewtonSoftDependentProject"; var profileProjectName = "NewtonsoftProfile"; var testInstance = TestAssets.Get(testAppName) .CreateInstance() .WithSourceFiles() .UseCurrentRuntimeFrameworkVersion(); var testProjectDirectory = testInstance.Root.ToString(); var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); var localAssemblyCache = Path.Combine(testProjectDirectory, "localAssemblyCache"); var intermediateWorkingDirectory = Path.Combine(testProjectDirectory, "workingDirectory"); var profileProjectPath = TestAssets.Get(profileProjectName).Root.FullName; var profileProject = Path.Combine(profileProjectPath, $"{profileProjectName}.xml"); new RestoreCommand() .WithWorkingDirectory(testProjectDirectory) .Execute() .Should().Pass(); new StoreCommand() .WithManifest(profileProject) .WithFramework(_tfm) .WithRuntime(rid) .WithOutput(localAssemblyCache) .WithRuntimeFrameworkVersion(_frameworkVersion) .WithIntermediateWorkingDirectory(intermediateWorkingDirectory) .Execute() .Should().Pass(); var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug"; var profileFilter = Path.Combine(localAssemblyCache, _arch, _tfm, "artifact.xml"); new PublishCommand() .WithFramework(_tfm) .WithWorkingDirectory(testProjectDirectory) .WithTargetManifest(profileFilter) .Execute() .Should().Pass(); var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, _tfm, "publish", $"{testAppName}.dll"); new DotnetCommand() .WithEnvironmentVariable("DOTNET_SHARED_STORE", localAssemblyCache) .ExecuteWithCapturedOutput(outputDll) .Should().Pass() .And.HaveStdOutContaining("{}"); }
public async Task DesktopApp_WithKestrel_WorksWhenPublished(string project, string url, string runtime, string libuvName, bool forceRunnable) { var runnable = forceRunnable || string.IsNullOrEmpty(runtime) || (DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier().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 ItAutoAddDesktopReferencesDuringMigrate(string testGroup, string projectName, bool isDesktopApp) { var runtime = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); var projectDirectory = TestAssets .GetProjectJson(testGroup, projectName) .CreateInstance() .WithSourceFiles() .WithRestoreFiles() .Root; CleanBinObj(projectDirectory); MigrateProject(new string[] { projectDirectory.FullName }); Restore(projectDirectory, runtime: runtime); BuildMSBuild(projectDirectory, projectName, runtime: runtime); VerifyAutoInjectedDesktopReferences(projectDirectory, projectName, isDesktopApp); VerifyAllMSBuildOutputsRunnable(projectDirectory); }
public void ItFailsToPublishWithConflictingArgument(string args) { var testAppName = "MSBuildTestApp"; var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); var testInstance = TestAssets.Get(testAppName) .CreateInstance($"PublishApp_{rid ?? "none"}_{args ?? "none"}") .WithSourceFiles() .WithRestoreFiles(); var testProjectDirectory = testInstance.Root; new PublishCommand() .WithRuntime(rid) .WithWorkingDirectory(testProjectDirectory) .Execute(args) .Should().Fail() .And.HaveStdErrContaining(LocalizableStrings.SelfContainAndNoSelfContainedConflict); }
public void ItPublishesFrameworkDependentWithRid(string args) { var testAppName = "MSBuildTestApp"; var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); var outputDirectory = PublishApp(testAppName, rid, args); outputDirectory.Should().OnlyHaveFiles(new[] { $"{testAppName}.dll", $"{testAppName}.pdb", $"{testAppName}.deps.json", $"{testAppName}.runtimeconfig.json", }); var outputProgram = Path.Combine(outputDirectory.FullName, $"{testAppName}{Constants.ExeSuffix}"); new DotnetCommand() .ExecuteWithCapturedOutput(Path.Combine(outputDirectory.FullName, $"{testAppName}.dll")) .Should().Pass() .And.HaveStdOutContaining("Hello World"); }
public void ItPublishesSuccessfullyWithNoBuildIfPreviouslyBuilt(bool selfContained) { var rootPath = TestAssets.CreateTestDirectory(identifier: selfContained ? "_sc" : "").FullName; var rootDir = new DirectoryInfo(rootPath); string newArgs = $"console -o \"{rootPath}\" --no-restore"; new NewCommandShim() .WithWorkingDirectory(rootPath) .Execute(newArgs) .Should() .Pass(); var rid = selfContained ? DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier() : ""; var ridArg = selfContained ? $"-r {rid}" : ""; new BuildCommand() .WithWorkingDirectory(rootPath) .ExecuteWithCapturedOutput(ridArg) .Should() .Pass(); new PublishCommand() .WithWorkingDirectory(rootPath) .ExecuteWithCapturedOutput($"{ridArg} --no-build") .Should() .Pass(); var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug"; var outputProgram = rootDir .GetDirectory("bin", configuration, "netcoreapp2.1", rid, "publish", $"{rootDir.Name}.dll") .FullName; new TestCommand(outputProgram) .ExecuteWithCapturedOutput() .Should() .Pass() .And.HaveStdOutContaining("Hello World"); }
private DirectoryInfo PublishAppWithSelfContained(string testAppName, bool selfContained) { var testInstance = TestAssets.Get(testAppName) .CreateInstance($"PublishesSelfContained{selfContained}") .WithSourceFiles() .WithRestoreFiles(); var testProjectDirectory = testInstance.Root; var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); new PublishCommand() .WithRuntime(rid) .WithSelfContained(selfContained) .WithWorkingDirectory(testProjectDirectory) .Execute() .Should().Pass(); var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug"; return(testProjectDirectory .GetDirectory("bin", configuration, "netcoreapp2.0", rid, "publish")); }
public void ItPublishesAppWhenRestoringToSpecificPackageDirectory() { var rootPath = TestAssetsManager.CreateTestDirectory().Path; var rootDir = new DirectoryInfo(rootPath); string dir = "pkgs"; string args = $"--packages {dir}"; new NewCommand() .WithWorkingDirectory(rootPath) .Execute() .Should() .Pass(); new RestoreCommand() .WithWorkingDirectory(rootPath) .Execute(args) .Should() .Pass(); new PublishCommand() .WithWorkingDirectory(rootPath) .ExecuteWithCapturedOutput() .Should().Pass(); var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier(); var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug"; var outputProgram = rootDir .GetDirectory("bin", configuration, "netcoreapp1.0", "publish", $"{rootDir.Name}.dll") .FullName; new TestCommand(outputProgram) .ExecuteWithCapturedOutput() .Should().Pass() .And.HaveStdOutContaining("Hello World"); }