From 9212605e8955eaf171af1d852bca2669b20b5b39 Mon Sep 17 00:00:00 2001 From: Krzysztof Wicher Date: Mon, 14 Nov 2016 14:26:03 -0800 Subject: [PATCH] binding redirects tests: Simplify and get ready for enabling (#4692) * binding redirects tests: Simplify and get ready for enabling * fix targets broken during cleanup * fix non-windows build * apply pr feedback: remove some not needed code * remigrate BindingRedirects samples, add x64 to bind redir proj --- .../AppWithRedirectsAndConfig.csproj | 53 ++++ .../AppWithRedirectsAndConfig/project.json | 29 --- .../AppWithRedirectsNoConfig.csproj | 53 ++++ .../AppWithRedirectsNoConfig/project.json | 29 --- .../BindingRedirectSample/NuGet.Config | 6 + .../dotnet-desktop-binding-redirects.csproj | 43 ++++ .../dotnet-desktop-binding-redirects.xproj | 19 -- .../project.json | 17 -- build/Microsoft.DotNet.Cli.Test.targets | 57 ++++- build/test/TestPackageProjects.targets | 2 + build/test/TestProjects.targets | 3 - .../dotnet-cli-build/DotNetBuild.cs | 26 +- build_projects/dotnet-cli-build/DotNetPack.cs | 14 +- .../dotnet-cli-build/DotNetRestore.cs | 14 +- .../Commands/BuildPJCommand.cs | 21 +- .../BindingRedirectTests.cs | 240 +----------------- test/binding-redirects.Tests/NuGet.Config | 6 + .../TestSetupFixture.cs | 48 ++-- test/binding-redirects.Tests/project.json | 16 +- .../GivenThatIWantToMigrateTestApps.cs | 20 +- .../GivenDotnetMSBuildBuildsProjects.cs | 24 +- ...atTheUserIsRunningDotNetForTheFirstTime.cs | 10 +- 22 files changed, 363 insertions(+), 387 deletions(-) create mode 100644 TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/AppWithRedirectsAndConfig.csproj delete mode 100644 TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/project.json create mode 100644 TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/AppWithRedirectsNoConfig.csproj delete mode 100644 TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/project.json create mode 100644 TestAssets/DesktopTestProjects/BindingRedirectSample/NuGet.Config create mode 100644 TestAssets/TestPackages/dotnet-desktop-binding-redirects/dotnet-desktop-binding-redirects.csproj delete mode 100644 TestAssets/TestPackages/dotnet-desktop-binding-redirects/dotnet-desktop-binding-redirects.xproj delete mode 100644 TestAssets/TestPackages/dotnet-desktop-binding-redirects/project.json create mode 100644 test/binding-redirects.Tests/NuGet.Config diff --git a/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/AppWithRedirectsAndConfig.csproj b/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/AppWithRedirectsAndConfig.csproj new file mode 100644 index 000000000..c37d839a7 --- /dev/null +++ b/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/AppWithRedirectsAndConfig.csproj @@ -0,0 +1,53 @@ + + + + + net46 + AppWithRedirectsAndConfig + Exe + win7-x64;win7-x86 + + + + + + + + + + + + 1.0.0-alpha-20161104-2 + All + + + 8.0.3 + + + 3.0.50813.1 + + + 3.0.1304 + + + 1.0.0-* + + + + + + + + + + + 1.0.0-* + + + + + $(DefineConstants);RELEASE + + + + diff --git a/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/project.json b/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/project.json deleted file mode 100644 index bad344e19..000000000 --- a/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsAndConfig/project.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "version": "1.0.0-*", - "buildOptions": { - "emitEntryPoint": true, - "compile": { - "include": [ - "../src/*.cs" - ] - } - }, - "dependencies": { - "Newtonsoft.Json": "8.0.3", - "Microsoft.AspNet.Mvc": "3.0.50813.1", - "Unity.Mvc": "3.0.1304", - "dotnet-desktop-binding-redirects": "1.0.0-*" - }, - "frameworks": { - "net46": {} - }, - "tools": { - "dotnet-dependency-tool-invoker": { - "version": "1.0.0-*", - "imports": [ - "dnxcore50", - "portable-net45+win8" - ] - } - } -} \ No newline at end of file diff --git a/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/AppWithRedirectsNoConfig.csproj b/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/AppWithRedirectsNoConfig.csproj new file mode 100644 index 000000000..a7e2f565f --- /dev/null +++ b/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/AppWithRedirectsNoConfig.csproj @@ -0,0 +1,53 @@ + + + + + net46 + AppWithRedirectsNoConfig + Exe + win7-x64;win7-x86 + + + + + + + + + + + + 1.0.0-alpha-20161104-2 + All + + + 8.0.3 + + + 3.0.50813.1 + + + 3.0.1304 + + + 1.0.0-* + + + + + + + + + + + 1.0.0-* + + + + + $(DefineConstants);RELEASE + + + + diff --git a/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/project.json b/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/project.json deleted file mode 100644 index bad344e19..000000000 --- a/TestAssets/DesktopTestProjects/BindingRedirectSample/AppWithRedirectsNoConfig/project.json +++ /dev/null @@ -1,29 +0,0 @@ -{ - "version": "1.0.0-*", - "buildOptions": { - "emitEntryPoint": true, - "compile": { - "include": [ - "../src/*.cs" - ] - } - }, - "dependencies": { - "Newtonsoft.Json": "8.0.3", - "Microsoft.AspNet.Mvc": "3.0.50813.1", - "Unity.Mvc": "3.0.1304", - "dotnet-desktop-binding-redirects": "1.0.0-*" - }, - "frameworks": { - "net46": {} - }, - "tools": { - "dotnet-dependency-tool-invoker": { - "version": "1.0.0-*", - "imports": [ - "dnxcore50", - "portable-net45+win8" - ] - } - } -} \ No newline at end of file diff --git a/TestAssets/DesktopTestProjects/BindingRedirectSample/NuGet.Config b/TestAssets/DesktopTestProjects/BindingRedirectSample/NuGet.Config new file mode 100644 index 000000000..b8e876fcb --- /dev/null +++ b/TestAssets/DesktopTestProjects/BindingRedirectSample/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + diff --git a/TestAssets/TestPackages/dotnet-desktop-binding-redirects/dotnet-desktop-binding-redirects.csproj b/TestAssets/TestPackages/dotnet-desktop-binding-redirects/dotnet-desktop-binding-redirects.csproj new file mode 100644 index 000000000..27221cf00 --- /dev/null +++ b/TestAssets/TestPackages/dotnet-desktop-binding-redirects/dotnet-desktop-binding-redirects.csproj @@ -0,0 +1,43 @@ + + + + + 1.0.0-rc + net451 + dotnet-desktop-binding-redirects + Exe + win7-x86;win7-x64 + true + + + + + + + + + + + 1.0.0-alpha-20161104-2 + All + + + 5.0.0 + + + 3.3.0 + + + + + + + + + + + $(DefineConstants);RELEASE + + + + diff --git a/TestAssets/TestPackages/dotnet-desktop-binding-redirects/dotnet-desktop-binding-redirects.xproj b/TestAssets/TestPackages/dotnet-desktop-binding-redirects/dotnet-desktop-binding-redirects.xproj deleted file mode 100644 index 9574b745e..000000000 --- a/TestAssets/TestPackages/dotnet-desktop-binding-redirects/dotnet-desktop-binding-redirects.xproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - 14.0 - $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) - - - - 281f1cdb-8627-47c7-9bb1-cde8d30d93d1 - dotnet-desktop-binding-redirects - ..\artifacts\obj\$(MSBuildProjectName) - ..\artifacts\bin\$(MSBuildProjectName)\ - - - - 2.0 - - - \ No newline at end of file diff --git a/TestAssets/TestPackages/dotnet-desktop-binding-redirects/project.json b/TestAssets/TestPackages/dotnet-desktop-binding-redirects/project.json deleted file mode 100644 index 587bf0ef4..000000000 --- a/TestAssets/TestPackages/dotnet-desktop-binding-redirects/project.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "version": "1.0.0-rc-*", - "buildOptions": { - "emitEntryPoint": true - }, - "dependencies": { - "Newtonsoft.Json": "5.0.0", - "NuGet.Protocol.Core.v3": "3.3.0" - }, - "frameworks": { - "net451": { - "frameworkAssemblies": { - "System.Configuration": "" - } - } - } -} \ No newline at end of file diff --git a/build/Microsoft.DotNet.Cli.Test.targets b/build/Microsoft.DotNet.Cli.Test.targets index 2354e0cd0..4de854ca7 100644 --- a/build/Microsoft.DotNet.Cli.Test.targets +++ b/build/Microsoft.DotNet.Cli.Test.targets @@ -172,7 +172,8 @@ - @@ -197,45 +198,81 @@ + + + - + + + + - - - - + + + %(TestPackageProject.Framework) + %(TestPackageProject.Runtime) + rc-%(TestPackageProject.VersionSuffix) + %(TestPackageProject.FullPath) + + + + + - + + + + - \ No newline at end of file + diff --git a/build/test/TestPackageProjects.targets b/build/test/TestPackageProjects.targets index 8f95f4740..2bf7b9cd8 100644 --- a/build/test/TestPackageProjects.targets +++ b/build/test/TestPackageProjects.targets @@ -109,11 +109,13 @@ Condition=" '$(IsDesktopAvailable)' == 'True' "> dotnet-desktop-binding-redirects True + True $(DesktopAvailable) 1.0.0-rc- $(TestPackageBuildVersionSuffix) True net451 + win7-x86 dotnet-hello diff --git a/build/test/TestProjects.targets b/build/test/TestProjects.targets index 505f8dd33..b263c5c9a 100644 --- a/build/test/TestProjects.targets +++ b/build/test/TestProjects.targets @@ -85,9 +85,6 @@ $(RepoRoot)%(TestProjects.RelativeDir)bin/$(Configuration)/%(TestProjects.Framework)/%(TestProjects.OutputName).dll - - net46 - net46 diff --git a/build_projects/dotnet-cli-build/DotNetBuild.cs b/build_projects/dotnet-cli-build/DotNetBuild.cs index ee57e1f82..fbe0dcae4 100644 --- a/build_projects/dotnet-cli-build/DotNetBuild.cs +++ b/build_projects/dotnet-cli-build/DotNetBuild.cs @@ -12,7 +12,7 @@ namespace Microsoft.DotNet.Cli.Build protected override string Args { - get { return $"{GetProjectPath()} {GetConfiguration()} {GetFramework()}"; } + get { return $"{GetProjectPath()} {GetConfiguration()} {GetFramework()} {GetRuntime()} {GetOutputPath()}"; } } public string BuildBasePath { get; set; } @@ -20,9 +20,23 @@ namespace Microsoft.DotNet.Cli.Build public string Configuration { get; set; } public string Framework { get; set; } + + public string Runtime { get; set; } public string ProjectPath { get; set; } + + public string OutputPath { get; set; } + private string GetOutputPath() + { + if (!string.IsNullOrEmpty(OutputPath)) + { + return $"--output {OutputPath}"; + } + + return null; + } + private string GetConfiguration() { if (!string.IsNullOrEmpty(Configuration)) @@ -42,6 +56,16 @@ namespace Microsoft.DotNet.Cli.Build return null; } + + private string GetRuntime() + { + if (!string.IsNullOrEmpty(Runtime)) + { + return $"--runtime {Runtime}"; + } + + return null; + } private string GetProjectPath() { diff --git a/build_projects/dotnet-cli-build/DotNetPack.cs b/build_projects/dotnet-cli-build/DotNetPack.cs index 60005785a..0dbeefe5c 100644 --- a/build_projects/dotnet-cli-build/DotNetPack.cs +++ b/build_projects/dotnet-cli-build/DotNetPack.cs @@ -12,7 +12,7 @@ namespace Microsoft.DotNet.Cli.Build protected override string Args { - get { return $"{GetProjectPath()} {GetConfiguration()} {GetNoBuild()} {GetOutput()} {GetVersionSuffix()}"; } + get { return $"{GetProjectPath()} {GetConfiguration()} {GetNoBuild()} {GetOutput()} {GetVersionSuffix()} {GetRuntime()}"; } } public string Configuration { get; set; } @@ -24,6 +24,8 @@ namespace Microsoft.DotNet.Cli.Build public string ProjectPath { get; set; } public string VersionSuffix { get; set; } + + public string Runtime { get; set; } private string GetConfiguration() { @@ -74,5 +76,15 @@ namespace Microsoft.DotNet.Cli.Build return null; } + + private string GetRuntime() + { + if (!string.IsNullOrEmpty(Runtime)) + { + return $"/p:RuntimeIdentifier={Runtime}"; + } + + return null; + } } } diff --git a/build_projects/dotnet-cli-build/DotNetRestore.cs b/build_projects/dotnet-cli-build/DotNetRestore.cs index 522c41f27..cd145bfc2 100644 --- a/build_projects/dotnet-cli-build/DotNetRestore.cs +++ b/build_projects/dotnet-cli-build/DotNetRestore.cs @@ -12,7 +12,7 @@ namespace Microsoft.DotNet.Cli.Build protected override string Args { - get { return $"{GetProjectPath()} {GetSource()} {GetPackages()} {GetSkipInvalidConfigurations()}"; } + get { return $"{GetProjectPath()} {GetSource()} {GetPackages()} {GetSkipInvalidConfigurations()} {GetRuntime()}"; } } public string ProjectPath { get; set; } @@ -22,6 +22,8 @@ namespace Microsoft.DotNet.Cli.Build public string Packages { get; set; } public bool SkipInvalidConfigurations { get; set; } + + public string Runtime { get; set; } private string GetSource() { @@ -62,5 +64,15 @@ namespace Microsoft.DotNet.Cli.Build return null; } + + private string GetRuntime() + { + if (!string.IsNullOrEmpty(Runtime)) + { + return $"/p:RuntimeIdentifier={Runtime}"; + } + + return null; + } } } diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/BuildPJCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/BuildPJCommand.cs index 0c673da4e..6b05edfe8 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/BuildPJCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/BuildPJCommand.cs @@ -16,6 +16,8 @@ namespace Microsoft.DotNet.Tools.Test.Utilities private NuGetFramework _framework; + private string _runtime; + private bool _noDependencies; private DirectoryInfo _outputPath; @@ -31,7 +33,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities public override CommandResult Execute(string args = "") { - args = $"build {GetNoDependencies()} {GetProjectFile()} {GetOutputPath()} {GetConfiguration()} {GetFramework()} {args}"; + args = $"build {GetNoDependencies()} {GetProjectFile()} {GetOutputPath()} {GetConfiguration()} {GetFramework()} {GetRuntime()} {args}"; if (_workingDirectory != null) { @@ -76,6 +78,13 @@ namespace Microsoft.DotNet.Tools.Test.Utilities return this; } + public BuildPJCommand WithRuntime(string runtime) + { + _runtime = runtime; + + return this; + } + public BuildPJCommand WithNoDependencies() { _noDependencies = true; @@ -131,6 +140,16 @@ namespace Microsoft.DotNet.Tools.Test.Utilities return $"--framework {_framework.GetShortFolderName()}"; } + private string GetRuntime() + { + if (_runtime == null) + { + return null; + } + + return $"--runtime {_runtime}"; + } + private string GetNoDependencies() { if (!_noDependencies) diff --git a/test/binding-redirects.Tests/BindingRedirectTests.cs b/test/binding-redirects.Tests/BindingRedirectTests.cs index c808f859b..67401f8c0 100644 --- a/test/binding-redirects.Tests/BindingRedirectTests.cs +++ b/test/binding-redirects.Tests/BindingRedirectTests.cs @@ -1,12 +1,6 @@ // Copyright (c) .NET Foundation and contributors. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; -using System.Collections.Generic; -using System.Configuration; -using System.IO; -using System.Linq; -using System.Xml.Linq; using FluentAssertions; using Microsoft.DotNet.Tools.Test.Utilities; using Xunit; @@ -15,245 +9,31 @@ namespace Microsoft.DotNet.BindingRedirects.Tests { public class GivenAnAppWithRedirectsAndExecutableDependency : TestBase, IClassFixture { - private const string ExecutableDependency = "dotnet-desktop-binding-redirects.exe"; - private const string ExecutableDependencyCommand = "desktop-binding-redirects"; - private TestSetupFixture _testSetup; public string _appWithConfigProjectRoot; public string _appWithoutConfigProjectRoot; - private string _appWithConfigBuildOutput; - private string _appWithoutConfigBuildOutput; - private string _appWithConfigPublishOutput; - private string _appWithoutConfigPublishOutput; - private string _executableDependencyBuildOutput; - private string _executableDependencyPublishOutput; public GivenAnAppWithRedirectsAndExecutableDependency(TestSetupFixture testSetup) { - _testSetup = testSetup; - _appWithConfigProjectRoot = _testSetup.AppWithConfigProjectRoot; - _appWithConfigBuildOutput = _testSetup.AppWithConfigBuildOutput; - _appWithConfigPublishOutput = _testSetup.AppWithConfigPublishOutput; - _appWithoutConfigProjectRoot = _testSetup.AppWithoutConfigProjectRoot; - _appWithoutConfigBuildOutput = _testSetup.AppWithoutConfigBuildOutput; - _appWithoutConfigPublishOutput = _testSetup.AppWithoutConfigPublishOutput; - _executableDependencyBuildOutput = Path.Combine(Path.GetDirectoryName(_appWithConfigBuildOutput), ExecutableDependency); - _executableDependencyPublishOutput = Path.Combine(Path.GetDirectoryName(_appWithConfigPublishOutput), ExecutableDependency); - } - - private static List BindingsAppNoConfig - { - get - { - List bindings = new List() - { - @" - - - - ", - @" - - - " - }; - - return bindings; - } - } - - private static List BindingsAppWithConfig - { - get - { - List bindings = new List() - { - @" - - - - - ", - @" - - - ", - @" - - - " - }; - - return bindings; - } - } - - private static List ExpectedBindingsAppNoConfig - { - get - { - List bindingElements = new List(); - - foreach (var binding in BindingsAppNoConfig) - { - bindingElements.Add(XElement.Parse(binding)); - } - - return bindingElements; - } - } - - private static List ExpectedBindingsAppWithConfig - { - get - { - List bindingElements = new List(); - - foreach (var binding in BindingsAppWithConfig) - { - bindingElements.Add(XElement.Parse(binding)); - } - - return bindingElements; - } - } - - private static Dictionary ExpectedAppSettings - { - get - { - Dictionary appSettings = new Dictionary() - { - {"Setting1", "Hello"}, - {"Setting2", "World"} - }; - - return appSettings; - } - } - - private IEnumerable GetRedirects(string exePath) - { - var configFile = exePath + ".config"; - - File.Exists(configFile).Should().BeTrue($"Config file not found - {configFile}"); - - var config = ConfigurationManager.OpenExeConfiguration(exePath); - - var runtimeSectionXml = config.Sections["runtime"].SectionInformation.GetRawXml(); - - var runtimeSectionElement = XElement.Parse(runtimeSectionXml); - - var redirects = runtimeSectionElement.Elements() - .Where(e => e.Name.LocalName == "assemblyBinding").Elements() - .Where(e => e.Name.LocalName == "dependentAssembly"); - - return redirects; - } - - private void VerifyRedirects(IEnumerable redirects, IEnumerable generatedBindings) - { - foreach (var binding in generatedBindings) - { - var redirect = redirects.SingleOrDefault(r => /*XNode.DeepEquals(r, binding)*/ r.ToString() == binding.ToString()); - - redirect.Should().NotBeNull($"Binding not found in runtime section : {Environment.NewLine}{binding}"); - } - } - - private void VerifyAppSettings(string exePath) - { - var configFile = ConfigurationManager.OpenExeConfiguration(exePath); - foreach (var appSetting in ExpectedAppSettings) - { - var value = configFile.AppSettings.Settings[appSetting.Key]; - value.Should().NotBeNull($"AppSetting with key '{appSetting.Key}' not found in config file."); - value.Value.Should().Be(appSetting.Value, $"For AppSetting '{appSetting.Key}' - Expected Value '{appSetting.Value}', Actual '{ value.Value}'"); - } - } - - [Fact(Skip="https://github.com/dotnet/cli/issues/4514")] - public void Build_Generates_Redirects_For_App_Without_Config() - { - var redirects = GetRedirects(_appWithoutConfigBuildOutput); - VerifyRedirects(redirects, ExpectedBindingsAppNoConfig); - - var commandResult = new TestCommand(_appWithoutConfigBuildOutput) - .Execute(); - commandResult.Should().Pass(); - } - - [Fact(Skip="https://github.com/dotnet/cli/issues/4514")] - public void Publish_Generates_Redirects_For_App_Without_Config() - { - var redirects = GetRedirects(_appWithoutConfigPublishOutput); - VerifyRedirects(redirects, ExpectedBindingsAppNoConfig); - - var commandResult = new TestCommand(_appWithoutConfigPublishOutput) - .Execute(); - commandResult.Should().Pass(); - } - - [Fact(Skip="https://github.com/dotnet/cli/issues/4514")] - public void Build_Generates_Redirects_For_Executable_Dependency() - { - var redirects = GetRedirects(_executableDependencyBuildOutput); - VerifyRedirects(redirects, ExpectedBindingsAppNoConfig); - - var commandResult = new TestCommand(_executableDependencyBuildOutput) - .Execute(); - commandResult.Should().Pass(); - } - - [Fact(Skip = "https://github.com/dotnet/cli/issues/2632")] - public void Publish_Generates_Redirects_For_Executable_Dependency() - { - var redirects = GetRedirects(_executableDependencyPublishOutput); - VerifyRedirects(redirects, ExpectedBindingsAppNoConfig); - - var commandResult = new TestCommand(_executableDependencyPublishOutput) - .Execute(); - commandResult.Should().Pass(); - } - - [Fact(Skip="https://github.com/dotnet/cli/issues/4514")] - public void Build_Generates_Redirects_For_App_With_Config() - { - var redirects = GetRedirects(_appWithConfigBuildOutput); - VerifyRedirects(redirects, ExpectedBindingsAppWithConfig); - VerifyAppSettings(_appWithConfigBuildOutput); - - var commandResult = new TestCommand(_appWithConfigBuildOutput) - .Execute(); - commandResult.Should().Pass(); - } - - [Fact(Skip="https://github.com/dotnet/cli/issues/4514")] - public void Publish_Generates_Redirects_For_App_With_Config() - { - var redirects = GetRedirects(_appWithConfigPublishOutput); - VerifyRedirects(redirects, ExpectedBindingsAppWithConfig); - VerifyAppSettings(_appWithConfigPublishOutput); - - var commandResult = new TestCommand(_appWithConfigPublishOutput) - .Execute(); - commandResult.Should().Pass(); + _appWithConfigProjectRoot = testSetup.AppWithConfigProjectRoot; + _appWithoutConfigProjectRoot = testSetup.AppWithoutConfigProjectRoot; } [Fact(Skip="https://github.com/dotnet/cli/issues/4514")] public void Tool_Command_Runs_Executable_Dependency_For_App_With_Config() { - var commandResult = new DependencyToolInvokerCommand { WorkingDirectory = _appWithConfigProjectRoot } - .Execute("desktop-binding-redirects", "net46", ""); - commandResult.Should().Pass(); + new DependencyToolInvokerCommand() + .WithWorkingDirectory(_appWithConfigProjectRoot) + .ExecuteWithCapturedOutput("desktop-binding-redirects", "net46", "") + .Should().Pass().And.NotHaveStdErr(); } [Fact(Skip="https://github.com/dotnet/cli/issues/4514")] public void Tool_Command_Runs_Executable_Dependency_For_App_Without_Config() { - var appDirectory = Path.GetDirectoryName(_appWithoutConfigProjectRoot); - var commandResult = new DependencyToolInvokerCommand { WorkingDirectory = _appWithoutConfigProjectRoot } - .Execute("desktop-binding-redirects", "net46", ""); - commandResult.Should().Pass(); + new DependencyToolInvokerCommand() + .WithWorkingDirectory(_appWithoutConfigProjectRoot) + .ExecuteWithCapturedOutput("desktop-binding-redirects", "net46", "") + .Should().Pass().And.NotHaveStdErr(); } } } diff --git a/test/binding-redirects.Tests/NuGet.Config b/test/binding-redirects.Tests/NuGet.Config new file mode 100644 index 000000000..507db39a6 --- /dev/null +++ b/test/binding-redirects.Tests/NuGet.Config @@ -0,0 +1,6 @@ + + + + + + diff --git a/test/binding-redirects.Tests/TestSetupFixture.cs b/test/binding-redirects.Tests/TestSetupFixture.cs index d41473f34..d5ce331a9 100644 --- a/test/binding-redirects.Tests/TestSetupFixture.cs +++ b/test/binding-redirects.Tests/TestSetupFixture.cs @@ -2,7 +2,7 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.IO; -using Microsoft.DotNet.InternalAbstractions; +using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.TestFramework; using Microsoft.DotNet.Tools.Test.Utilities; using NuGet.Frameworks; @@ -17,46 +17,36 @@ namespace Microsoft.DotNet.BindingRedirects.Tests private const string AppWithoutConfig = "AppWithRedirectsNoConfig"; private string _Runtime = RuntimeEnvironmentRidExtensions.GetLegacyRestoreRuntimeIdentifier(); - private string _desktopProjectsRoot = Path.Combine(RepoRoot, "TestAssets", "DesktopTestProjects"); - private string _buildRelativePath; private string _appWithConfigProjectRoot; - private string _appWithConfigBuildDir; - private string _appWithConfigPublishDir; private string _appWithoutConfigProjectRoot; - private string _appWithoutConfigBuildDir; - private string _appWithoutConfigPublishDir; - private TestInstance _testInstance; + private TestAssetInstance _testInstance; public string AppWithConfigProjectRoot { get { return _appWithConfigProjectRoot; } } - public string AppWithConfigBuildOutput { get; } - public string AppWithConfigPublishOutput { get; } public string AppWithoutConfigProjectRoot { get { return _appWithoutConfigProjectRoot; } } - public string AppWithoutConfigBuildOutput { get; } - public string AppWithoutConfigPublishOutput { get; } public TestSetupFixture() { - _buildRelativePath = Path.Combine("bin", Config, Framework.GetShortFolderName(), _Runtime); - var testAssetsMgr = new TestAssetsManager(_desktopProjectsRoot); - _testInstance = testAssetsMgr.CreateTestInstance("BindingRedirectSample") - .WithLockFiles(); + _testInstance = TestAssets.Get("DesktopTestProjects", "BindingRedirectSample") + .CreateInstance() + .WithSourceFiles() + .WithNuGetConfig(new RepoDirectoriesProvider().TestPackages); - Setup(AppWithConfig, ref _appWithConfigProjectRoot, ref _appWithConfigBuildDir, ref _appWithConfigPublishDir); - Setup(AppWithoutConfig, ref _appWithoutConfigProjectRoot, ref _appWithoutConfigBuildDir, ref _appWithoutConfigPublishDir); - - AppWithConfigBuildOutput = Path.Combine(_appWithConfigBuildDir, AppWithConfig + ".exe"); - AppWithConfigPublishOutput = Path.Combine(_appWithConfigPublishDir, AppWithConfig + ".exe"); - AppWithoutConfigBuildOutput = Path.Combine(_appWithoutConfigBuildDir, AppWithoutConfig + ".exe"); - AppWithoutConfigPublishOutput = Path.Combine(_appWithoutConfigPublishDir, AppWithoutConfig + ".exe"); + _appWithConfigProjectRoot = Setup(AppWithConfig); + _appWithoutConfigProjectRoot = Setup(AppWithoutConfig); } - private void Setup(string project, ref string projectDir, ref string buildDir, ref string publishDir) + private string Setup(string project) { - projectDir = Path.Combine(_testInstance.TestRoot, project); - buildDir = Path.Combine(projectDir, _buildRelativePath); - publishDir = Path.Combine(projectDir, "publish"); + string projectDir = Path.Combine(_testInstance.Root.FullName, project); + string publishDir = Path.Combine(projectDir, "publish"); - var buildCommand = new BuildCommand() + new RestoreCommand() + .WithWorkingDirectory(projectDir) + .WithRuntime(_Runtime) + .ExecuteWithCapturedOutput() + .Should().Pass(); + + new BuildCommand() .WithWorkingDirectory(projectDir) .WithFramework(Framework) .WithRuntime(_Runtime) @@ -70,6 +60,8 @@ namespace Microsoft.DotNet.BindingRedirects.Tests .WithRuntime(_Runtime) .Execute() .Should().Pass(); + + return projectDir; } } } diff --git a/test/binding-redirects.Tests/project.json b/test/binding-redirects.Tests/project.json index 3d6493dc6..44fae00f3 100644 --- a/test/binding-redirects.Tests/project.json +++ b/test/binding-redirects.Tests/project.json @@ -5,18 +5,18 @@ "dotnet-test-xunit": "1.0.0-rc2-350904-49", "Microsoft.NETCore.Platforms": "1.0.1", "Microsoft.DotNet.PlatformAbstractions": "1.0.1-beta-000933", - "Microsoft.DotNet.Tools.Tests.Utilities": { - "target": "project" - } + "Microsoft.DotNet.Cli.Utils": { "target": "project" }, + "Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" } }, "frameworks": { - "net46": { - "frameworkAssemblies": { - "System.Configuration": "" - }, + "netcoreapp1.0": { "dependencies": { "System.Console": "4.0.0" - } + }, + "imports": [ + "dotnet5.4", + "portable-net451+win8" + ] } }, "runtimes": { diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs index c954d0206..9a26e2c93 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs @@ -557,6 +557,24 @@ namespace Microsoft.DotNet.Migration.Tests .Select(p => Path.GetFullPath(p).Substring(fullBinPath.Length)); } + private static void DeleteDirectory(string dir) + { + foreach (string directory in Directory.EnumerateDirectories(dir)) + { + DeleteDirectory(directory); + } + + try + { + Directory.Delete(dir, true); + } + catch + { + // retry, if still doesn't delete then throw + Directory.Delete(dir, true); + } + } + private void CleanBinObj(string projectDirectory) { var dirs = new string[] { Path.Combine(projectDirectory, "bin"), Path.Combine(projectDirectory, "obj") }; @@ -565,7 +583,7 @@ namespace Microsoft.DotNet.Migration.Tests { if(Directory.Exists(dir)) { - Directory.Delete(dir, true); + DeleteDirectory(dir); } } } diff --git a/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs b/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs index 40de30809..6a88377fc 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs @@ -80,13 +80,17 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [Fact] public void WhenTelemetryIsEnabledTheLoggerIsAddedToTheCommandLine() { - string[] allArgs = GetArgsForMSBuild(() => true); + Telemetry telemetry; + string[] allArgs = GetArgsForMSBuild(() => true, out telemetry); + // telemetry will still be disabled if environmental variable is set + if (telemetry.Enabled) + { + allArgs.Should().NotBeNull(); - allArgs.Should().NotBeNull(); - - allArgs.Should().Contain( - value => value.IndexOf("/Logger", StringComparison.OrdinalIgnoreCase) >= 0, - "The MSBuild logger argument should be specified when telemetry is enabled."); + allArgs.Should().Contain( + value => value.IndexOf("/Logger", StringComparison.OrdinalIgnoreCase) >= 0, + "The MSBuild logger argument should be specified when telemetry is enabled."); + } } [Fact] @@ -103,7 +107,13 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests private string[] GetArgsForMSBuild(Func sentinelExists) { - Telemetry telemetry = new Telemetry(new MockNuGetCacheSentinel(sentinelExists)); + Telemetry telemetry; + return GetArgsForMSBuild(sentinelExists, out telemetry); + } + + private string[] GetArgsForMSBuild(Func sentinelExists, out Telemetry telemetry) + { + telemetry = new Telemetry(new MockNuGetCacheSentinel(sentinelExists)); MSBuildForwardingApp msBuildForwardingApp = new MSBuildForwardingApp(Enumerable.Empty()); diff --git a/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs b/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs index 5a2012847..938e97b60 100644 --- a/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs +++ b/test/dotnet.Tests/GivenThatTheUserIsRunningDotNetForTheFirstTime.cs @@ -69,9 +69,10 @@ Configuring... ------------------- A command is running to initially populate your local package cache, to improve restore speed and enable offline access. This command will take up to a minute to complete and will only happen once."; - _firstDotnetVerbUseCommandResult.StdOut + // normalizing line endings as git is occasionally replacing line endings in this file causing this test to fail + NormalizeLineEndings(_firstDotnetVerbUseCommandResult.StdOut) .Should() - .StartWith(firstTimeUseWelcomeMessage); + .StartWith(NormalizeLineEndings(firstTimeUseWelcomeMessage)); } [Fact] @@ -95,5 +96,10 @@ A command is running to initially populate your local package cache, to improve return new DotnetCommand().ExecuteWithCapturedOutput("--version").StdOut .TrimEnd(Environment.NewLine.ToCharArray()); } + + private static string NormalizeLineEndings(string s) + { + return s.Replace("\r\n", "\n").Replace("\r", "\n"); + } } } \ No newline at end of file