From 6fb66eb47d8bb5f67d6ba06150ad4df6ff20a9ff Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Fri, 8 Feb 2019 13:02:57 +0530 Subject: [PATCH 01/24] depItemInNetcoreWithoutUT --- .../MSTest.CoreAdapter.csproj | 15 +- .../PlatformServices.Desktop.csproj | 91 ++++- .../DesktopTestContextImplementation.cs | 22 -- .../Utilities/DeploymentUtility.cs | 346 ++---------------- .../Deployment/AssemblyLoadWorker.cs | 43 +++ .../PlatformServices.NetCore.csproj | 47 ++- .../Utilities/AssemblyUtility.cs | 43 +++ .../Utilities/DeploymentUtility.cs | 197 ++++++++++ .../Utilities/RecursiveDirectoryPath.cs | 61 +++ .../Utilities/ReflectionUtility.cs | 43 +++ .../netstandard1.0/Constants.cs | 7 + .../ns10TestContextPropertyStrings.cs | 22 ++ .../Extensions/ns13ExceptionExtensions.cs} | 1 + .../Resources/Resource.Designer.cs | 7 +- .../netstandard1.3}/Resources/Resource.resx | 0 .../Resources/xlf/Resource.cs.xlf | 0 .../Resources/xlf/Resource.de.xlf | 0 .../Resources/xlf/Resource.es.xlf | 0 .../Resources/xlf/Resource.fr.xlf | 0 .../Resources/xlf/Resource.it.xlf | 0 .../Resources/xlf/Resource.ja.xlf | 0 .../Resources/xlf/Resource.ko.xlf | 0 .../Resources/xlf/Resource.pl.xlf | 0 .../Resources/xlf/Resource.pt-BR.xlf | 0 .../Resources/xlf/Resource.ru.xlf | 0 .../Resources/xlf/Resource.tr.xlf | 0 .../Resources/xlf/Resource.xlf | 0 .../Resources/xlf/Resource.zh-Hans.xlf | 0 .../Resources/xlf/Resource.zh-Hant.xlf | 0 .../Services/ns13MSTestAdapterSettings.cs} | 2 + .../Services/ns13SettingsProvider.cs | 62 ++++ .../ns13TestContextPropertyStrings.cs | 25 ++ .../Services/ns13TestDeployment.cs | 225 ++++++++++++ .../Utilities/ns13DeploymentItemUtility.cs} | 2 + .../Utilities/ns13DeploymentUtilityBase.cs | 315 ++++++++++++++++ .../Utilities/ns13FileUtility.cs} | 2 + .../netstandard1.3/Utilities/ns13Validate.cs} | 2 + .../netstandard1.3/ns13DeploymentItem.cs} | 2 + .../netstandard1.3/ns13TestRunDirectories.cs} | 2 + 39 files changed, 1226 insertions(+), 358 deletions(-) create mode 100644 src/Adapter/PlatformServices.NetCore/Deployment/AssemblyLoadWorker.cs create mode 100644 src/Adapter/PlatformServices.NetCore/Utilities/AssemblyUtility.cs create mode 100644 src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtility.cs create mode 100644 src/Adapter/PlatformServices.NetCore/Utilities/RecursiveDirectoryPath.cs create mode 100644 src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtility.cs create mode 100644 src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextPropertyStrings.cs rename src/Adapter/{PlatformServices.Desktop/Extensions/ExceptionExtensions.cs => PlatformServices.Shared/netstandard1.3/Extensions/ns13ExceptionExtensions.cs} (95%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/Resource.Designer.cs (99%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/Resource.resx (100%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/xlf/Resource.cs.xlf (100%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/xlf/Resource.de.xlf (100%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/xlf/Resource.es.xlf (100%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/xlf/Resource.fr.xlf (100%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/xlf/Resource.it.xlf (100%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/xlf/Resource.ja.xlf (100%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/xlf/Resource.ko.xlf (100%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/xlf/Resource.pl.xlf (100%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/xlf/Resource.pt-BR.xlf (100%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/xlf/Resource.ru.xlf (100%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/xlf/Resource.tr.xlf (100%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/xlf/Resource.xlf (100%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/xlf/Resource.zh-Hans.xlf (100%) rename src/Adapter/{PlatformServices.Desktop => PlatformServices.Shared/netstandard1.3}/Resources/xlf/Resource.zh-Hant.xlf (100%) rename src/Adapter/{PlatformServices.Desktop/Services/MSTestAdapterSettings.cs => PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs} (99%) create mode 100644 src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13SettingsProvider.cs create mode 100644 src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestContextPropertyStrings.cs create mode 100644 src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs rename src/Adapter/{PlatformServices.Desktop/Utilities/DeploymentItemUtility.cs => PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs} (99%) create mode 100644 src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs rename src/Adapter/{PlatformServices.Desktop/Utilities/FileUtility.cs => PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs} (99%) rename src/Adapter/{PlatformServices.Desktop/Utilities/Validate.cs => PlatformServices.Shared/netstandard1.3/Utilities/ns13Validate.cs} (94%) rename src/Adapter/{PlatformServices.Desktop/Deployment/DeploymentItem.cs => PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs} (98%) rename src/Adapter/{PlatformServices.Desktop/Deployment/TestRunDirectories.cs => PlatformServices.Shared/netstandard1.3/ns13TestRunDirectories.cs} (97%) diff --git a/src/Adapter/MSTest.CoreAdapter/MSTest.CoreAdapter.csproj b/src/Adapter/MSTest.CoreAdapter/MSTest.CoreAdapter.csproj index 33567b9e2f..cdbac5552b 100644 --- a/src/Adapter/MSTest.CoreAdapter/MSTest.CoreAdapter.csproj +++ b/src/Adapter/MSTest.CoreAdapter/MSTest.CoreAdapter.csproj @@ -111,6 +111,20 @@ + + + + + + + + + + + + + + @@ -125,7 +139,6 @@ ResXFileCodeGenerator Resource.Designer.cs - Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter diff --git a/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj b/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj index 4496d6a4b8..0ca5217a84 100644 --- a/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj +++ b/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj @@ -44,6 +44,36 @@ + + Extensions\ns13ExceptionExtensions.cs + + + Utilities\ns13DeploymentItem.cs + + + Deployment\ns13TestRunDirectories.cs + + + Resources\Resource.Designer.cs + + + Services\ns13MSTestAdapterSettings.cs + + + Services\ns13TestContextPropertyStrings.cs + + + Utilities\ns13DeploymentItemUtility.cs + + + Utilities\ns13DeploymentUtilityBase.cs + + + Utilities\ns13FileUtility.cs + + + Utilities\ns13Validate.cs + @@ -55,19 +85,10 @@ - - - - - - True - True - Resource.resx - Services\ns13TraceListener.cs @@ -88,13 +109,10 @@ - - - @@ -116,14 +134,53 @@ + + Resources\xlf\Resource.cs.xlf + + + Resources\xlf\Resource.de.xlf + + + Resources\xlf\Resource.es.xlf + + + Resources\xlf\Resource.fr.xlf + + + Resources\xlf\Resource.it.xlf + + + Resources\xlf\Resource.ja.xlf + + + Resources\xlf\Resource.ko.xlf + + + Resources\xlf\Resource.pl.xlf + + + Resources\xlf\Resource.pt-BR.xlf + + + Resources\xlf\Resource.ru.xlf + + + Resources\xlf\Resource.tr.xlf + + + Resources\xlf\Resource.xlf + + + Resources\xlf\Resource.zh-Hans.xlf + + + Resources\xlf\Resource.zh-Hant.xlf + - - ResXFileCodeGenerator - Resource.Designer.cs - Designer - Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices + + Resources\Resource.resx diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs index b625eebbfc..4bb97b58ce 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs @@ -463,26 +463,4 @@ private void InitializeProperties() this.properties[TestContextPropertyStrings.TestName] = this.testMethod.Name; } } - -#pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName -#pragma warning disable SA1402 // File may only contain a single class - - /// - /// Test Context Property Names. - /// - internal static class TestContextPropertyStrings -#pragma warning restore SA1402 // File may only contain a single class - { - public static readonly string TestRunDirectory = "TestRunDirectory"; - public static readonly string DeploymentDirectory = "DeploymentDirectory"; - public static readonly string ResultsDirectory = "ResultsDirectory"; - public static readonly string TestRunResultsDirectory = "TestRunResultsDirectory"; - public static readonly string TestResultsDirectory = "TestResultsDirectory"; - public static readonly string TestDir = "TestDir"; - public static readonly string TestDeploymentDir = "TestDeploymentDir"; - public static readonly string TestLogsDir = "TestLogsDir"; - - public static readonly string FullyQualifiedTestClassName = "FullyQualifiedTestClassName"; - public static readonly string TestName = "TestName"; - } } diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtility.cs b/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtility.cs index c5338cc829..6d8766b671 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtility.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtility.cs @@ -18,124 +18,16 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; - internal class DeploymentUtility + internal class DeploymentUtility : DeploymentUtilityBase { - private const string TestAssemblyConfigFileExtension = ".config"; - private const string NetAppConfigFile = "App.Config"; - - /// - /// Prefix for deployment folder to avoid confusions with other folders (like trx attachments). - /// - private const string DeploymentFolderPrefix = "Deploy"; - - private DeploymentItemUtility deploymentItemUtility; - private FileUtility fileUtility; - private AssemblyUtility assemblyUtility; - public DeploymentUtility() - : this(new DeploymentItemUtility(new ReflectionUtility()), new AssemblyUtility(), new FileUtility()) + : base() { } public DeploymentUtility(DeploymentItemUtility deploymentItemUtility, AssemblyUtility assemblyUtility, FileUtility fileUtility) + : base(deploymentItemUtility, assemblyUtility, fileUtility) { - this.deploymentItemUtility = deploymentItemUtility; - this.assemblyUtility = assemblyUtility; - this.fileUtility = fileUtility; - } - - public bool Deploy(IEnumerable tests, string source, IRunContext runContext, ITestExecutionRecorder testExecutionRecorder, TestRunDirectories runDirectories) - { - IList deploymentItems = this.deploymentItemUtility.GetDeploymentItems(tests); - - // we just deploy source if there are no deployment items for current source but there are deployment items for other sources - return this.Deploy(source, runContext, testExecutionRecorder, deploymentItems, runDirectories); - } - - /// - /// Create deployment directories - /// - /// The run context. - /// TestRunDirectories instance. - public TestRunDirectories CreateDeploymentDirectories(IRunContext runContext) - { - var resultsDirectory = this.GetTestResultsDirectory(runContext); - var rootDeploymentDirectory = this.GetRootDeploymentDirectory(resultsDirectory); - - var result = new TestRunDirectories(rootDeploymentDirectory); - var inDirectory = result.InDirectory; - var outDirectory = result.OutDirectory; - var inMachineDirectory = result.InMachineNameDirectory; - - this.fileUtility.CreateDirectoryIfNotExists(rootDeploymentDirectory); - this.fileUtility.CreateDirectoryIfNotExists(inDirectory); - this.fileUtility.CreateDirectoryIfNotExists(outDirectory); - this.fileUtility.CreateDirectoryIfNotExists(inMachineDirectory); - - return result; - } - - internal string GetConfigFile(string testSource) - { - string configFile = null; - - if (this.fileUtility.DoesFileExist(testSource + TestAssemblyConfigFileExtension)) - { - // Path to config file cannot be bad: storage is already checked, and extension is valid. - configFile = testSource + TestAssemblyConfigFileExtension; - } - else - { - var netAppConfigFile = Path.Combine(Path.GetDirectoryName(testSource), NetAppConfigFile); - if (this.fileUtility.DoesFileExist(netAppConfigFile)) - { - configFile = netAppConfigFile; - } - } - - return configFile; - } - - /// - /// Log the parameter warnings on the parameter logger - /// - /// Execution recorder. - /// Warnings. - private static void LogWarnings(ITestExecutionRecorder testExecutionRecorder, IEnumerable warnings) - { - if (warnings == null) - { - return; - } - - Debug.Assert(testExecutionRecorder != null, "Logger should not be null"); - - // log the warnings - foreach (string warning in warnings) - { - testExecutionRecorder.SendMessage(TestMessageLevel.Warning, warning); - } - } - - private bool Deploy(string source, IRunContext runContext, ITestExecutionRecorder testExecutionRecorder, IList deploymentItems, TestRunDirectories runDirectories) - { - ValidateArg.NotNull(runDirectories, "runDirectories"); - if (EqtTrace.IsInfoEnabled) - { - EqtTrace.Info("MSTestExecutor: Found that deployment items for source {0} are: ", source); - foreach (var item in deploymentItems) - { - EqtTrace.Info("MSTestExecutor: SourcePath: - {0}", item.SourcePath); - } - } - - // Do the deployment. - EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "MSTestExecutor: Using deployment directory {0} for source {1}.", runDirectories.OutDirectory, source); - var warnings = this.Deploy(new List(deploymentItems), source, runDirectories.OutDirectory, this.GetTestResultsDirectory(runContext)); - - // Log warnings - LogWarnings(testExecutionRecorder, warnings); - return deploymentItems != null && deploymentItems.Count > 0; } /// @@ -147,12 +39,12 @@ private bool Deploy(string source, IRunContext runContext, ITestExecutionRecorde /// Root results directory /// Returns a list of deployment warnings [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] - private IEnumerable Deploy(IList deploymentItems, string testSource, string deploymentDirectory, string resultsDirectory) + public override IEnumerable Deploy(IList deploymentItems, string testSource, string deploymentDirectory, string resultsDirectory) { Validate.IsFalse(string.IsNullOrWhiteSpace(deploymentDirectory), "Deployment directory is null or empty"); - Validate.IsTrue(this.fileUtility.DoesDirectoryExist(deploymentDirectory), $"Deployment directory {deploymentDirectory} does not exist"); + Validate.IsTrue(this.FileUtility.DoesDirectoryExist(deploymentDirectory), $"Deployment directory {deploymentDirectory} does not exist"); Validate.IsFalse(string.IsNullOrWhiteSpace(testSource), "TestSource directory is null/empty"); - Validate.IsTrue(this.fileUtility.DoesFileExist(testSource), $"TestSource {testSource} does not exist."); + Validate.IsTrue(this.FileUtility.DoesFileExist(testSource), $"TestSource {testSource} does not exist."); testSource = Path.GetFullPath(testSource); var warnings = new List(); @@ -168,13 +60,13 @@ private IEnumerable Deploy(IList deploymentItems, string var satelliteItems = this.GetSatellites(deploymentItems, testSource, warnings); foreach (var satelliteItem in satelliteItems) { - this.deploymentItemUtility.AddDeploymentItem(deploymentItems, satelliteItem); + this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, satelliteItem); } } else { EqtTrace.Info("Adding the test source directory to the deploymentitems list"); - this.deploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(Path.GetDirectoryName(testSource))); + this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(Path.GetDirectoryName(testSource))); } // Maps relative to Out dir destination -> source and used to determine if there are conflicted items. @@ -211,7 +103,7 @@ private IEnumerable Deploy(IList deploymentItems, string // Find dependencies of test deployment items and deploy them at the same time as master file. if (deploymentItem.OriginType == DeploymentItemOriginType.PerTestDeployment && - this.assemblyUtility.IsAssemblyExtension(Path.GetExtension(deploymentItemFile))) + this.AssemblyUtility.IsAssemblyExtension(Path.GetExtension(deploymentItemFile))) { this.AddDependenciesOfDeploymentItem(deploymentItemFile, filesToDeploy, warnings); } @@ -233,7 +125,7 @@ private IEnumerable Deploy(IList deploymentItems, string { // Deploy into subdirectory of deployment (Out) dir. Debug.Assert(fileToDeploy.StartsWith(fullPathToDeploymentItemSource, StringComparison.Ordinal), "Somehow source is outside original dir."); - relativeDestination = this.fileUtility.TryConvertPathToRelative(fileToDeploy, fullPathToDeploymentItemSource); + relativeDestination = this.FileUtility.TryConvertPathToRelative(fileToDeploy, fullPathToDeploymentItemSource); } else { @@ -260,7 +152,7 @@ private IEnumerable Deploy(IList deploymentItems, string destToSource.Add(relativeDestination, fileToDeploy); // Now, finally we can copy the file... - destination = this.fileUtility.CopyFileOverwrite(fileToDeploy, destination, out string warning); + destination = this.FileUtility.CopyFileOverwrite(fileToDeploy, destination, out string warning); if (!string.IsNullOrEmpty(warning)) { warnings.Add(warning); @@ -272,10 +164,10 @@ private IEnumerable Deploy(IList deploymentItems, string } // We clear the attributes so that e.g. you can write to the copies of files originally under SCC. - this.fileUtility.SetAttributes(destination, FileAttributes.Normal); + this.FileUtility.SetAttributes(destination, FileAttributes.Normal); // Deploy PDB for line number info in stack trace. - this.fileUtility.FindAndDeployPdb(destination, relativeDestination, fileToDeploy, destToSource); + this.FileUtility.FindAndDeployPdb(destination, relativeDestination, fileToDeploy, destToSource); } else if ( !string.Equals( @@ -296,6 +188,20 @@ private IEnumerable Deploy(IList deploymentItems, string return warnings; } + /// + /// Get root deployment directory + /// + /// The base directory. + /// Root deployment directory. + protected override string GetRootDeploymentDirectory(string baseDirectory) + { + string dateTimeSufix = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo); + string directoryName = string.Format(CultureInfo.CurrentCulture, Resource.TestRunName, DeploymentFolderPrefix, Environment.UserName, dateTimeSufix); + directoryName = this.FileUtility.ReplaceInvalidFileNameCharacters(directoryName); + + return this.FileUtility.GetNextIterationDirectoryName(baseDirectory, directoryName); + } + private void AddDependenciesOfDeploymentItem(string deploymentItemFile, IList filesToDeploy, IList warnings) { var dependencies = new List(); @@ -329,7 +235,7 @@ private void AddDependencies(string testSource, string configFile, IList warningList; - string[] references = this.assemblyUtility.GetFullPathToDependentAssemblies(testSource, configFile, out warningList); + string[] references = this.AssemblyUtility.GetFullPathToDependentAssemblies(testSource, configFile, out warningList); if (warningList != null && warningList.Count > 0) { warnings = warnings.Concat(warningList).ToList(); @@ -343,7 +249,7 @@ private void AddDependencies(string testSource, string configFile, IList - /// Get files corresponding to parameter deployment item. - /// - /// Deployment Item. - /// The test source. - /// Results directory which should be skipped for deployment - /// Warnings. - /// Is this a directory. - /// Paths to items to deploy. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] - private string[] GetFullPathToFilesCorrespondingToDeploymentItem(DeploymentItem deploymentItem, string testSource, string resultsDirectory, IList warnings, out bool isDirectory) - { - Debug.Assert(deploymentItem != null, "deploymentItem should not be null."); - Debug.Assert(!string.IsNullOrEmpty(testSource), "testsource should not be null or empty."); - - try - { - isDirectory = this.IsDeploymentItemSourceADirectory(deploymentItem, testSource, out string directory); - if (isDirectory) - { - return this.fileUtility.AddFilesFromDirectory( - directory, (deployDirectory) => string.Equals(deployDirectory, resultsDirectory, StringComparison.OrdinalIgnoreCase), false).ToArray(); - } - - if (this.IsDeploymentItemSourceAFile(deploymentItem.SourcePath, testSource, out string fileName)) - { - return new[] { fileName }; - } - - // If file/directory is not found, then try removing the prefix and see if it is present. - string fileOrDirNameOnly = Path.GetFileName(deploymentItem.SourcePath.TrimEnd( - new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar })); - if (this.IsDeploymentItemSourceAFile(fileOrDirNameOnly, testSource, out fileName)) - { - return new[] { fileName }; - } - - string message = string.Format(CultureInfo.CurrentCulture, Resource.CannotFindFile, fileName); - throw new FileNotFoundException(message, fileName); - } - catch (Exception e) - { - warnings.Add(string.Format( - CultureInfo.CurrentCulture, Resource.DeploymentErrorFailedToGetFileForDeploymentItem, deploymentItem, e.GetType(), e.Message)); - } - - isDirectory = false; - return null; - } - - private bool IsDeploymentItemSourceAFile(string deploymentItemSourcePath, string testSource, out string file) - { - file = this.GetFullPathToDeploymentItemSource(deploymentItemSourcePath, testSource); - - return this.fileUtility.DoesFileExist(file); - } - - private bool IsDeploymentItemSourceADirectory(DeploymentItem deploymentItem, string testSource, out string resultDirectory) - { - resultDirectory = null; - - string directory = this.GetFullPathToDeploymentItemSource(deploymentItem.SourcePath, testSource); - directory = directory.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); - - if (this.fileUtility.DoesDirectoryExist(directory)) - { - resultDirectory = directory; - return true; - } - - return false; - } - private IEnumerable GetSatellites(IEnumerable deploymentItems, string testSource, IList warnings) { List satellites = new List(); @@ -437,8 +270,8 @@ private IEnumerable GetSatellites(IEnumerable de path = this.GetFullPathToDeploymentItemSource(item.SourcePath, testSource); path = Path.GetFullPath(path); - if (string.IsNullOrEmpty(path) || !this.assemblyUtility.IsAssemblyExtension(Path.GetExtension(path)) - || !this.fileUtility.DoesFileExist(path) || !this.assemblyUtility.IsAssembly(path)) + if (string.IsNullOrEmpty(path) || !this.AssemblyUtility.IsAssemblyExtension(Path.GetExtension(path)) + || !this.FileUtility.DoesFileExist(path) || !this.AssemblyUtility.IsAssembly(path)) { continue; } @@ -469,7 +302,7 @@ private IEnumerable GetSatellites(IEnumerable de { string itemDir = Path.GetDirectoryName(path).TrimEnd( new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }); - List itemSatellites = this.assemblyUtility.GetSatelliteAssemblies(path); + List itemSatellites = this.AssemblyUtility.GetSatelliteAssemblies(path); foreach (string satellite in itemSatellites) { Debug.Assert(!string.IsNullOrEmpty(satellite), "DeploymentManager.DoDeployment: got empty satellite!"); @@ -490,7 +323,7 @@ private IEnumerable GetSatellites(IEnumerable de // Now finally add the item! DeploymentItem satelliteItem = new DeploymentItem(satellite, relativeOutputDir, DeploymentItemOriginType.Satellite); - this.deploymentItemUtility.AddDeploymentItem(satellites, satelliteItem); + this.DeploymentItemUtility.AddDeploymentItem(satellites, satelliteItem); } } catch (ArgumentException ex) @@ -517,86 +350,23 @@ private IEnumerable GetSatellites(IEnumerable de return satellites; } - private string GetFullPathToDeploymentItemSource(string deploymentItemSourcePath, string testSource) - { - if (Path.IsPathRooted(deploymentItemSourcePath)) - { - return deploymentItemSourcePath; - } - - return Path.Combine(Path.GetDirectoryName(testSource), deploymentItemSourcePath); - } - - /// - /// Validate the output directory for the parameter deployment item. - /// - /// The deployment item. - /// The deployment directory. - /// Warnings. - /// True if valid. - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] - private bool IsOutputDirectoryValid(DeploymentItem deploymentItem, string deploymentDirectory, IList warnings) - { - Debug.Assert(deploymentItem != null, "deploymentItem should not be null."); - Debug.Assert(!string.IsNullOrEmpty(deploymentDirectory), "deploymentDirectory should not be null or empty."); - Debug.Assert(warnings != null, "warnings should not be null."); - - // Check that item.output dir does not go outside deployment Out dir, otherwise you can erase any file! - string outputDir = deploymentDirectory; - try - { - outputDir = Path.GetFullPath(Path.Combine(deploymentDirectory, deploymentItem.RelativeOutputDirectory)); - - // convert the short path to full length path (like joe~1.dom to joe.domain) and the comparison - // startsWith in the next loop will work for the matching paths. - deploymentDirectory = Path.GetFullPath(deploymentDirectory); - } - catch (Exception e) - { - string warning = string.Format( - CultureInfo.CurrentCulture, - Resource.DeploymentErrorFailedToAccesOutputDirectory, - deploymentItem.SourcePath, - outputDir, - e.GetType(), - e.GetExceptionMessage()); - - warnings.Add(warning); - return false; - } - - if (!outputDir.StartsWith(deploymentDirectory, StringComparison.OrdinalIgnoreCase)) - { - string warning = string.Format( - CultureInfo.CurrentCulture, - Resource.DeploymentErrorBadDeploymentItem, - deploymentItem.SourcePath, - deploymentItem.RelativeOutputDirectory); - warnings.Add(warning); - - return false; - } - - return true; - } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] private void ProcessNewStorage(string testSource, IList deploymentItems, IList warnings) { // Add deployment items and process .config files only for storages we have not processed before. string errorMessage; - if (!this.deploymentItemUtility.IsValidDeploymentItem(testSource, string.Empty, out errorMessage)) + if (!this.DeploymentItemUtility.IsValidDeploymentItem(testSource, string.Empty, out errorMessage)) { warnings.Add(errorMessage); return; } - this.deploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(testSource, string.Empty, DeploymentItemOriginType.TestStorage)); + this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(testSource, string.Empty, DeploymentItemOriginType.TestStorage)); // Deploy .config file if exists, only for assemlbies, i.e. DLL and EXE. // First check .config, then if not found check for App.Config // and deploy AppConfig to .config. - if (this.assemblyUtility.IsAssemblyExtension(Path.GetExtension(testSource))) + if (this.AssemblyUtility.IsAssemblyExtension(Path.GetExtension(testSource))) { var configFile = this.AddTestSourceConfigFileIfExists(testSource, deploymentItems); @@ -613,49 +383,5 @@ private void ProcessNewStorage(string testSource, IList deployme } } } - - /// - /// Get the parent test results directory where deployment will be done. - /// - /// The run context. - /// The test results directory. - private string GetTestResultsDirectory(IRunContext runContext) - { - var resultsDirectory = (!string.IsNullOrEmpty(runContext?.TestRunDirectory)) ? - runContext.TestRunDirectory : null; - - if (string.IsNullOrEmpty(resultsDirectory)) - { - resultsDirectory = Path.GetFullPath(Path.Combine(Path.GetTempPath(), TestRunDirectories.DefaultDeploymentRootDirectory)); - } - - return resultsDirectory; - } - - /// - /// Get root deployment directory - /// - /// The base directory. - /// Root deployment directory. - private string GetRootDeploymentDirectory(string baseDirectory) - { - string dateTimeSufix = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo); - string directoryName = string.Format(CultureInfo.CurrentCulture, Resource.TestRunName, DeploymentFolderPrefix, Environment.UserName, dateTimeSufix); - directoryName = this.fileUtility.ReplaceInvalidFileNameCharacters(directoryName); - - return this.fileUtility.GetNextIterationDirectoryName(baseDirectory, directoryName); - } - - private string AddTestSourceConfigFileIfExists(string testSource, IList deploymentItems) - { - string configFile = this.GetConfigFile(testSource); - - if (string.IsNullOrEmpty(configFile) == false) - { - this.deploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(configFile)); - } - - return configFile; - } } } diff --git a/src/Adapter/PlatformServices.NetCore/Deployment/AssemblyLoadWorker.cs b/src/Adapter/PlatformServices.NetCore/Deployment/AssemblyLoadWorker.cs new file mode 100644 index 0000000000..5bebdff7b2 --- /dev/null +++ b/src/Adapter/PlatformServices.NetCore/Deployment/AssemblyLoadWorker.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment +{ + using System; + using System.Collections.Generic; + using System.Diagnostics; + using System.Globalization; + using System.IO; + using System.Reflection; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + + /// + /// Utility function for Assembly related info + /// The caller is supposed to create AppDomain and create instance of given class in there. + /// + internal class AssemblyLoadWorker : MarshalByRefObject + { + private AssemblyUtility assemblyUtility; + + public AssemblyLoadWorker() + : this(new AssemblyUtility()) + { + } + + internal AssemblyLoadWorker(AssemblyUtility assemblyUtility) + { + this.assemblyUtility = assemblyUtility; + } + + /// + /// initialize the lifetime service. + /// + /// The . + public override object InitializeLifetimeService() + { + // Infinite. + return null; + } + } +} diff --git a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj index 87bde00062..60df0d1581 100644 --- a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj +++ b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj @@ -19,30 +19,67 @@ - - + + + + + + + + + + + + + + + + + - + + + + + - + + + + + + - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/AssemblyUtility.cs b/src/Adapter/PlatformServices.NetCore/Utilities/AssemblyUtility.cs new file mode 100644 index 0000000000..923d005162 --- /dev/null +++ b/src/Adapter/PlatformServices.NetCore/Utilities/AssemblyUtility.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities +{ + using System; + using System.Collections.Generic; + using System.Diagnostics; + using System.Globalization; + using System.IO; + using System.Reflection; + + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + + /// + /// Utility for assembly specific functionality. + /// + internal class AssemblyUtility + { + private readonly string[] assemblyExtensions = new string[] { ".dll", ".exe" }; + + /// + /// Whether file extension is an assembly file extension. + /// Returns true for .exe and .dll, otherwise false. + /// + /// Extension containing leading dot, e.g. ".exe". + /// Path.GetExtension() returns extension with leading dot. + /// True if this is an assembly extension. + internal bool IsAssemblyExtension(string extensionWithLeadingDot) + { + foreach (var realExtension in this.assemblyExtensions) + { + if (string.Equals(extensionWithLeadingDot, realExtension, StringComparison.OrdinalIgnoreCase)) + { + return true; + } + } + + return false; + } + } +} diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtility.cs b/src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtility.cs new file mode 100644 index 0000000000..4a96d32bfa --- /dev/null +++ b/src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtility.cs @@ -0,0 +1,197 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities +{ + using System; + using System.Collections.Generic; + using System.Diagnostics; + using System.Globalization; + using System.IO; + using System.Linq; + using System.Reflection; + using System.Security; + + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + + internal class DeploymentUtility : DeploymentUtilityBase + { + public DeploymentUtility() + : base() + { + } + + public DeploymentUtility(DeploymentItemUtility deploymentItemUtility, AssemblyUtility assemblyUtility, FileUtility fileUtility) + : base(deploymentItemUtility, assemblyUtility, fileUtility) + { + } + + /// + /// Does the deployment of parameter deployment items & the testSource to the parameter directory. + /// + /// The deployment item. + /// The test source. + /// The deployment directory. + /// Root results directory + /// Returns a list of deployment warnings + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] + public override IEnumerable Deploy(IList deploymentItems, string testSource, string deploymentDirectory, string resultsDirectory) + { + Validate.IsFalse(string.IsNullOrWhiteSpace(deploymentDirectory), "Deployment directory is null or empty"); + Validate.IsTrue(this.FileUtility.DoesDirectoryExist(deploymentDirectory), $"Deployment directory {deploymentDirectory} does not exist"); + Validate.IsFalse(string.IsNullOrWhiteSpace(testSource), "TestSource directory is null/empty"); + Validate.IsTrue(this.FileUtility.DoesFileExist(testSource), $"TestSource {testSource} does not exist."); + + testSource = Path.GetFullPath(testSource); + var warnings = new List(); + + EqtTrace.Info("Adding the test source directory to the deploymentitems list"); + this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(Path.GetDirectoryName(testSource))); + + // Maps relative to Out dir destination -> source and used to determine if there are conflicted items. + var destToSource = new Dictionary(StringComparer.OrdinalIgnoreCase); + + // Copy the deployment items. (As deployment item can correspond to directories as well, so each deployment item may map to n files) + foreach (var deploymentItem in deploymentItems) + { + ValidateArg.NotNull(deploymentItem, "deploymentItem should not be null."); + + // Validate the output directory. + if (!this.IsOutputDirectoryValid(deploymentItem, deploymentDirectory, warnings)) + { + continue; + } + + // Get the files corresponding to this deployment item + var deploymentItemFiles = this.GetFullPathToFilesCorrespondingToDeploymentItem(deploymentItem, testSource, resultsDirectory, warnings, out bool itemIsDirectory); + if (deploymentItemFiles == null) + { + continue; + } + + var fullPathToDeploymentItemSource = this.GetFullPathToDeploymentItemSource(deploymentItem.SourcePath, testSource); + + // Note: source is already rooted. + foreach (var deploymentItemFile in deploymentItemFiles) + { + Debug.Assert(Path.IsPathRooted(deploymentItemFile), "File " + deploymentItemFile + " is not rooted"); + + // List of files to deploy, by default, just itemFile. + var filesToDeploy = new List(1); + filesToDeploy.Add(deploymentItemFile); + + foreach (var fileToDeploy in filesToDeploy) + { + Debug.Assert(Path.IsPathRooted(fileToDeploy), "File " + fileToDeploy + " is not rooted"); + + // Ignore the test platform files. + var tempFile = Path.GetFileName(fileToDeploy); + var assemblyName = Path.GetFileName(this.GetType().GetTypeInfo().Assembly.Location); + if (tempFile.Equals(assemblyName, StringComparison.OrdinalIgnoreCase)) + { + continue; + } + + string relativeDestination; + if (itemIsDirectory) + { + // Deploy into subdirectory of deployment (Out) dir. + Debug.Assert(fileToDeploy.StartsWith(fullPathToDeploymentItemSource, StringComparison.Ordinal), "Somehow source is outside original dir."); + relativeDestination = this.FileUtility.TryConvertPathToRelative(fileToDeploy, fullPathToDeploymentItemSource); + } + else + { + // Deploy just to the deployment (Out) dir. + relativeDestination = Path.GetFileName(fileToDeploy); + } + + relativeDestination = Path.Combine(deploymentItem.RelativeOutputDirectory, relativeDestination); // Ignores empty arg1. + var destination = Path.Combine(deploymentDirectory, relativeDestination); + try + { + destination = Path.GetFullPath(destination); + } + catch (Exception e) + { + var warning = string.Format(CultureInfo.CurrentCulture, Resource.DeploymentErrorFailedToAccessFile, destination, e.GetType(), e.Message); + warnings.Add(warning); + + continue; + } + + if (!destToSource.ContainsKey(relativeDestination)) + { + destToSource.Add(relativeDestination, fileToDeploy); + + // Now, finally we can copy the file... + destination = this.FileUtility.CopyFileOverwrite(fileToDeploy, destination, out string warning); + if (!string.IsNullOrEmpty(warning)) + { + warnings.Add(warning); + } + + if (string.IsNullOrEmpty(destination)) + { + continue; + } + + // We clear the attributes so that e.g. you can write to the copies of files originally under SCC. + this.FileUtility.SetAttributes(destination, FileAttributes.Normal); + + // Deploy PDB for line number info in stack trace. + this.FileUtility.FindAndDeployPdb(destination, relativeDestination, fileToDeploy, destToSource); + } + else if ( + !string.Equals( + fileToDeploy, + destToSource[relativeDestination], + StringComparison.OrdinalIgnoreCase)) + { + EqtTrace.WarningIf( + EqtTrace.IsWarningEnabled, + "Conflict during copiyng file: '{0}' and '{1}' are from different origins although they might be the same.", + fileToDeploy, + destToSource[relativeDestination]); + } + } // foreach fileToDeploy. + } // foreach itemFile. + } + + return warnings; + } + + /// + /// Get root deployment directory + /// + /// The base directory. + /// Root deployment directory. + protected override string GetRootDeploymentDirectory(string baseDirectory) + { + string dateTimeSufix = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo); + string directoryName = string.Format(CultureInfo.CurrentCulture, Resource.TestRunName, DeploymentFolderPrefix, Environment.GetEnvironmentVariable("USERNAME") ?? Environment.GetEnvironmentVariable("USER"), dateTimeSufix); + directoryName = this.FileUtility.ReplaceInvalidFileNameCharacters(directoryName); + + return this.FileUtility.GetNextIterationDirectoryName(baseDirectory, directoryName); + } + + private bool IsDeploymentItemSourceADirectory(DeploymentItem deploymentItem, string testSource, out string resultDirectory) + { + resultDirectory = null; + + string directory = this.GetFullPathToDeploymentItemSource(deploymentItem.SourcePath, testSource); + directory = directory.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + + if (this.FileUtility.DoesDirectoryExist(directory)) + { + resultDirectory = directory; + return true; + } + + return false; + } + } +} diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/RecursiveDirectoryPath.cs b/src/Adapter/PlatformServices.NetCore/Utilities/RecursiveDirectoryPath.cs new file mode 100644 index 0000000000..8fade77d98 --- /dev/null +++ b/src/Adapter/PlatformServices.NetCore/Utilities/RecursiveDirectoryPath.cs @@ -0,0 +1,61 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices +{ + using System; + using System.Diagnostics.CodeAnalysis; + using System.Security; + + /// + /// Mstest settings in runsettings look like this + /// + /// + /// + /// + /// ...// by default includeSubDirectories is false + /// + /// + /// + /// For each directory we need to have two info 1) path 2) includeSubDirectories + /// + [Serializable] + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1603:DocumentationMustContainValidXml", Justification = "Reviewed. Suppression is OK here.")] + public class RecursiveDirectoryPath : MarshalByRefObject + { + /// + /// Initializes a new instance of the class. + /// + /// The directory path. + /// + /// True if to include subdirectory else false + /// + public RecursiveDirectoryPath(string dirPath, bool includeSubDirectories) + { + this.DirectoryPath = dirPath; + this.IncludeSubDirectories = includeSubDirectories; + } + + /// + /// Gets the directory path. + /// + public string DirectoryPath { get; private set; } + + /// + /// Gets a value indicating whether to include sub directories. + /// + public bool IncludeSubDirectories { get; private set; } + + /// + /// Returns object to be used for controlling lifetime, null means infinite lifetime. + /// + /// + /// The . + /// + [SecurityCritical] + public override object InitializeLifetimeService() + { + return null; + } + } +} diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtility.cs b/src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtility.cs new file mode 100644 index 0000000000..09c34c6fe1 --- /dev/null +++ b/src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtility.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Diagnostics; + using System.IO; + using System.Linq; + using System.Reflection; + + /// + /// Utility for reflection API's + /// + internal class ReflectionUtility + { + internal virtual object[] GetCustomAttributes(MemberInfo attributeProvider, Type type) + { + return this.GetCustomAttributes(attributeProvider, type, true); + } + + internal object[] GetCustomAttributes(MemberInfo memberInfo, Type type, bool inherit) + { + if (memberInfo == null) + { + return null; + } + + bool shouldGetAllAttributes = type == null; + + if (shouldGetAllAttributes) + { + return memberInfo.GetCustomAttributes(inherit).ToArray(); + } + else + { + return memberInfo.GetCustomAttributes(type, inherit).ToArray(); + } + } + } +} diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.0/Constants.cs b/src/Adapter/PlatformServices.Shared/netstandard1.0/Constants.cs index b7c31b98b9..0f69f4fd48 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.0/Constants.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.0/Constants.cs @@ -3,13 +3,20 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices { + using System.Collections.Generic; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + #pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName internal class Constants { + public static readonly TestProperty DeploymentItemsProperty = TestProperty.Register("MSTestDiscoverer.DeploymentItems", DeploymentItemsLabel, typeof(KeyValuePair[]), TestPropertyAttributes.Hidden, typeof(TestCase)); + internal const string DllExtension = ".dll"; internal const string ExeExtension = ".exe"; internal const string AppxPackageExtension = ".appx"; + + private const string DeploymentItemsLabel = "DeploymentItems"; } #pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextPropertyStrings.cs b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextPropertyStrings.cs new file mode 100644 index 0000000000..1a303a998c --- /dev/null +++ b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextPropertyStrings.cs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices +{ + #pragma warning disable SA1649 // File name must match first type name + + internal static class TestContextPropertyStrings + { + public static readonly string TestRunDirectory = "TestRunDirectory"; + public static readonly string DeploymentDirectory = "DeploymentDirectory"; + public static readonly string ResultsDirectory = "ResultsDirectory"; + public static readonly string TestRunResultsDirectory = "TestRunResultsDirectory"; + public static readonly string TestResultsDirectory = "TestResultsDirectory"; + public static readonly string TestDir = "TestDir"; + public static readonly string TestDeploymentDir = "TestDeploymentDir"; + public static readonly string TestLogsDir = "TestLogsDir"; + + public static readonly string FullyQualifiedTestClassName = "FullyQualifiedTestClassName"; + public static readonly string TestName = "TestName"; + } +} diff --git a/src/Adapter/PlatformServices.Desktop/Extensions/ExceptionExtensions.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Extensions/ns13ExceptionExtensions.cs similarity index 95% rename from src/Adapter/PlatformServices.Desktop/Extensions/ExceptionExtensions.cs rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Extensions/ns13ExceptionExtensions.cs index 4b9ce94cd0..588c233e9f 100644 --- a/src/Adapter/PlatformServices.Desktop/Extensions/ExceptionExtensions.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Extensions/ns13ExceptionExtensions.cs @@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Ext { using System; using System.Diagnostics; +#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName /// /// Extension methods for the exception class. diff --git a/src/Adapter/PlatformServices.Desktop/Resources/Resource.Designer.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/Resource.Designer.cs similarity index 99% rename from src/Adapter/PlatformServices.Desktop/Resources/Resource.Designer.cs rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/Resource.Designer.cs index d02be0ed02..fd65a3f5d4 100644 --- a/src/Adapter/PlatformServices.Desktop/Resources/Resource.Designer.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/Resource.Designer.cs @@ -10,8 +10,9 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices { using System; - - + using System.Reflection; + + /// /// A strongly-typed resource class, for looking up localized strings, etc. /// @@ -40,7 +41,7 @@ internal Resource() { get { if (object.ReferenceEquals(resourceMan, null)) { global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources.Reso" + - "urce", typeof(Resource).Assembly); + "urce", typeof(Resource).GetTypeInfo().Assembly); resourceMan = temp; } return resourceMan; diff --git a/src/Adapter/PlatformServices.Desktop/Resources/Resource.resx b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/Resource.resx similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Resources/Resource.resx rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/Resource.resx diff --git a/src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.cs.xlf b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.cs.xlf similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.cs.xlf rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.cs.xlf diff --git a/src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.de.xlf b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.de.xlf similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.de.xlf rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.de.xlf diff --git a/src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.es.xlf b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.es.xlf similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.es.xlf rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.es.xlf diff --git a/src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.fr.xlf b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.fr.xlf similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.fr.xlf rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.fr.xlf diff --git a/src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.it.xlf b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.it.xlf similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.it.xlf rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.it.xlf diff --git a/src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.ja.xlf b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.ja.xlf similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.ja.xlf rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.ja.xlf diff --git a/src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.ko.xlf b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.ko.xlf similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.ko.xlf rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.ko.xlf diff --git a/src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.pl.xlf b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.pl.xlf similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.pl.xlf rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.pl.xlf diff --git a/src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.pt-BR.xlf b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.pt-BR.xlf similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.pt-BR.xlf rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.pt-BR.xlf diff --git a/src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.ru.xlf b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.ru.xlf similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.ru.xlf rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.ru.xlf diff --git a/src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.tr.xlf b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.tr.xlf similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.tr.xlf rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.tr.xlf diff --git a/src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.xlf b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.xlf similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.xlf rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.xlf diff --git a/src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.zh-Hans.xlf b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.zh-Hans.xlf similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.zh-Hans.xlf rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.zh-Hans.xlf diff --git a/src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.zh-Hant.xlf b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.zh-Hant.xlf similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Resources/xlf/Resource.zh-Hant.xlf rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/xlf/Resource.zh-Hant.xlf diff --git a/src/Adapter/PlatformServices.Desktop/Services/MSTestAdapterSettings.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs similarity index 99% rename from src/Adapter/PlatformServices.Desktop/Services/MSTestAdapterSettings.cs rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs index 77977c7a36..67c1015039 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/MSTestAdapterSettings.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs @@ -11,6 +11,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + #pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName + public class MSTestAdapterSettings { /// diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13SettingsProvider.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13SettingsProvider.cs new file mode 100644 index 0000000000..e3311986df --- /dev/null +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13SettingsProvider.cs @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices +{ + using System.Collections.Generic; + using System.Xml; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + + using ISettingsProvider = Interface.ISettingsProvider; +#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName + + /// + /// Class to read settings from the runsettings xml for the desktop. + /// + public class MSTestSettingsProvider : ISettingsProvider + { + /// + /// Member variable for Adapter settings + /// + private static MSTestAdapterSettings settings; + + /// + /// Gets settings provided to the adapter. + /// + public static MSTestAdapterSettings Settings + { + get + { + if (settings == null) + { + settings = new MSTestAdapterSettings(); + } + + return settings; + } + } + + /// + /// Reset the settings to its default. + /// + public static void Reset() + { + settings = null; + } + + /// + /// Load the settings from the reader. + /// + /// Reader to load the settings from. + public void Load(XmlReader reader) + { + ValidateArg.NotNull(reader, "reader"); + settings = MSTestAdapterSettings.ToSettings(reader); + } + + public IDictionary GetProperties(string source) + { + return TestDeployment.GetDeploymentInformation(source); + } + } +} diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestContextPropertyStrings.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestContextPropertyStrings.cs new file mode 100644 index 0000000000..b379eed2ac --- /dev/null +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestContextPropertyStrings.cs @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices +{ +#pragma warning disable SA1649 // File name must match first type name + + internal static class TestContextPropertyStrings + { + /// + /// Test Context Property Names. + /// + public static readonly string TestRunDirectory = "TestRunDirectory"; + public static readonly string DeploymentDirectory = "DeploymentDirectory"; + public static readonly string ResultsDirectory = "ResultsDirectory"; + public static readonly string TestRunResultsDirectory = "TestRunResultsDirectory"; + public static readonly string TestResultsDirectory = "TestResultsDirectory"; + public static readonly string TestDir = "TestDir"; + public static readonly string TestDeploymentDir = "TestDeploymentDir"; + public static readonly string TestLogsDir = "TestLogsDir"; + + public static readonly string FullyQualifiedTestClassName = "FullyQualifiedTestClassName"; + public static readonly string TestName = "TestName"; + } +} diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs new file mode 100644 index 0000000000..2d27f4f87e --- /dev/null +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs @@ -0,0 +1,225 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices +{ + using System; + using System.Collections.Generic; + using System.Diagnostics; + using System.IO; + using System.Linq; + using System.Reflection; + + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + +#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName + + /// + /// The test deployment. + /// + public class TestDeployment : ITestDeployment + { + #region Service Utility Variables + + private DeploymentItemUtility deploymentItemUtility; + private DeploymentUtility deploymentUtility; + private FileUtility fileUtility; + private MSTestAdapterSettings adapterSettings; + + #endregion + + /// + /// Initializes a new instance of the class. + /// + public TestDeployment() + : this(new DeploymentItemUtility(new ReflectionUtility()), new DeploymentUtility(), new FileUtility()) + { + } + + /// + /// Initializes a new instance of the class. Used for unit tests. + /// + /// The deployment item utility. + /// The deployment utility. + /// The file utility. + internal TestDeployment(DeploymentItemUtility deploymentItemUtility, DeploymentUtility deploymentUtility, FileUtility fileUtility) + { + this.deploymentItemUtility = deploymentItemUtility; + this.deploymentUtility = deploymentUtility; + this.fileUtility = fileUtility; + this.adapterSettings = null; + RunDirectories = null; + } + + /// + /// Gets the current run directories for this session. + /// + /// + /// This is intialized at the beginning of a run session when Deploy is called. + /// Leaving this as a static varaible since the testContext needs to be filled in with this information. + /// + internal static TestRunDirectories RunDirectories + { + get; + private set; + } + + /// + /// The get deployment items. + /// + /// The method. + /// The type. + /// The warnings. + /// A string of deployment items. + public KeyValuePair[] GetDeploymentItems(MethodInfo method, Type type, ICollection warnings) + { + return this.deploymentItemUtility.GetDeploymentItems(method, this.deploymentItemUtility.GetClassLevelDeploymentItems(type, warnings), warnings); + } + + /// + /// The cleanup. + /// + public void Cleanup() + { + // Delete the deployment directory + if (RunDirectories != null && this.adapterSettings.DeleteDeploymentDirectoryAfterTestRunIsComplete) + { + EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "Deleting deployment directory {0}", RunDirectories.RootDeploymentDirectory); + + this.fileUtility.DeleteDirectories(RunDirectories.RootDeploymentDirectory); + + EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "Deleted deployment directory {0}", RunDirectories.RootDeploymentDirectory); + } + } + + /// + /// Gets the deployment output directory where the source file along with all its dependencies is dropped. + /// + /// The deployment output directory. + public string GetDeploymentDirectory() + { + return RunDirectories?.OutDirectory; + } + + /// + /// Deploy files related to the list of tests specified. + /// + /// The tests. + /// The run context. + /// The framework handle. + /// Return true if deployment is done. + public bool Deploy(IEnumerable tests, IRunContext runContext, IFrameworkHandle frameworkHandle) + { + Debug.Assert(tests != null, "tests"); + + // Reset runDirectories before doing deployment, so that older values of runDirectories is not picked + // even if test host is kept alive. + RunDirectories = null; + + this.adapterSettings = MSTestSettingsProvider.Settings; + bool canDeploy = this.CanDeploy(); + var hasDeploymentItems = tests.Any(test => this.deploymentItemUtility.HasDeploymentItems(test)); + + // deployment directories should not be created in this case,simply return + if (!canDeploy && hasDeploymentItems) + { + return false; + } + + RunDirectories = this.deploymentUtility.CreateDeploymentDirectories(runContext); + + // Deployment directories are created but deployment will not happen. + // This is added just to keep consistency with MSTestv1 behaviour. + if (!hasDeploymentItems) + { + return false; + } + + // Group the tests by source + var testsBySource = from test in tests + group test by test.Source into testGroup + select new { Source = testGroup.Key, Tests = testGroup }; + + var runDirectories = RunDirectories; + foreach (var group in testsBySource) + { + // do the deployment + this.deploymentUtility.Deploy(@group.Tests, @group.Source, runContext, frameworkHandle, RunDirectories); + } + + // Update the runDirectories + RunDirectories = runDirectories; + + return true; + } + + internal static IDictionary GetDeploymentInformation(string source) + { + var properties = new Dictionary(); + + var applicationBaseDirectory = string.Empty; + + // Run directories can be null in win8. + if (RunDirectories == null && !string.IsNullOrEmpty(source)) + { + // applicationBaseDirectory is set at source level + applicationBaseDirectory = Path.GetDirectoryName(source); + } + + properties[TestContextPropertyStrings.TestRunDirectory] = RunDirectories != null + ? RunDirectories.RootDeploymentDirectory + : applicationBaseDirectory; + properties[TestContextPropertyStrings.DeploymentDirectory] = RunDirectories != null + ? RunDirectories.OutDirectory + : applicationBaseDirectory; + properties[TestContextPropertyStrings.ResultsDirectory] = RunDirectories != null + ? RunDirectories.InDirectory + : applicationBaseDirectory; + properties[TestContextPropertyStrings.TestRunResultsDirectory] = RunDirectories != null + ? RunDirectories.InMachineNameDirectory + : applicationBaseDirectory; + properties[TestContextPropertyStrings.TestResultsDirectory] = RunDirectories != null + ? RunDirectories.InDirectory + : applicationBaseDirectory; + properties[TestContextPropertyStrings.TestDir] = RunDirectories != null + ? RunDirectories.RootDeploymentDirectory + : applicationBaseDirectory; + properties[TestContextPropertyStrings.TestDeploymentDir] = RunDirectories != null + ? RunDirectories.OutDirectory + : applicationBaseDirectory; + properties[TestContextPropertyStrings.TestLogsDir] = RunDirectories != null + ? RunDirectories.InMachineNameDirectory + : applicationBaseDirectory; + + return properties; + } + + /// + /// Reset the static varaible to default values. Used only for testing purposes. + /// + internal static void Reset() + { + RunDirectories = null; + } + + /// + /// Returns whether deployment can happen or not + /// + /// True if deployment can be done. + private bool CanDeploy() + { + if (!this.adapterSettings.DeploymentEnabled) + { + EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "MSTestExecutor: CanDeploy is false."); + return false; + } + + return true; + } + } +} diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentItemUtility.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs similarity index 99% rename from src/Adapter/PlatformServices.Desktop/Utilities/DeploymentItemUtility.cs rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs index aee1ec0dde..cabc054564 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentItemUtility.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs @@ -15,6 +15,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestTools.UnitTesting; +#pragma warning disable SA1649 // File name must match first type name + /// /// The deployment utility. /// diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs new file mode 100644 index 0000000000..d60742f848 --- /dev/null +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs @@ -0,0 +1,315 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities +{ + using System; + using System.Collections.Generic; + using System.Diagnostics; + using System.Globalization; + using System.IO; + using System.Linq; + using System.Reflection; + using System.Security; + + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + +#pragma warning disable SA1649 // File name must match first type name + + internal abstract class DeploymentUtilityBase + { + protected const string TestAssemblyConfigFileExtension = ".config"; + protected const string NetAppConfigFile = "App.Config"; + + /// + /// Prefix for deployment folder to avoid confusions with other folders (like trx attachments). + /// + protected const string DeploymentFolderPrefix = "Deploy"; + + public DeploymentUtilityBase() + : this(new DeploymentItemUtility(new ReflectionUtility()), new AssemblyUtility(), new FileUtility()) + { + } + + public DeploymentUtilityBase(DeploymentItemUtility deploymentItemUtility, AssemblyUtility assemblyUtility, FileUtility fileUtility) + { + this.DeploymentItemUtility = deploymentItemUtility; + this.AssemblyUtility = assemblyUtility; + this.FileUtility = fileUtility; + } + + protected FileUtility FileUtility { get; set; } + + protected DeploymentItemUtility DeploymentItemUtility { get; set; } + + protected AssemblyUtility AssemblyUtility { get; set; } + + public bool Deploy(IEnumerable tests, string source, IRunContext runContext, ITestExecutionRecorder testExecutionRecorder, TestRunDirectories runDirectories) + { + IList deploymentItems = this.DeploymentItemUtility.GetDeploymentItems(tests); + + // we just deploy source if there are no deployment items for current source but there are deployment items for other sources + return this.Deploy(source, runContext, testExecutionRecorder, deploymentItems, runDirectories); + } + + /// + /// Create deployment directories + /// + /// The run context. + /// TestRunDirectories instance. + public TestRunDirectories CreateDeploymentDirectories(IRunContext runContext) + { + var resultsDirectory = this.GetTestResultsDirectory(runContext); + var rootDeploymentDirectory = this.GetRootDeploymentDirectory(resultsDirectory); + + var result = new TestRunDirectories(rootDeploymentDirectory); + var inDirectory = result.InDirectory; + var outDirectory = result.OutDirectory; + var inMachineDirectory = result.InMachineNameDirectory; + + this.FileUtility.CreateDirectoryIfNotExists(rootDeploymentDirectory); + this.FileUtility.CreateDirectoryIfNotExists(inDirectory); + this.FileUtility.CreateDirectoryIfNotExists(outDirectory); + this.FileUtility.CreateDirectoryIfNotExists(inMachineDirectory); + + return result; + } + + public abstract IEnumerable Deploy(IList deploymentItems, string testSource, string deploymentDirectory, string resultsDirectory); + + internal string GetConfigFile(string testSource) + { + string configFile = null; + + if (this.FileUtility.DoesFileExist(testSource + TestAssemblyConfigFileExtension)) + { + // Path to config file cannot be bad: storage is already checked, and extension is valid. + configFile = testSource + TestAssemblyConfigFileExtension; + } + else + { + var netAppConfigFile = Path.Combine(Path.GetDirectoryName(testSource), NetAppConfigFile); + if (this.FileUtility.DoesFileExist(netAppConfigFile)) + { + configFile = netAppConfigFile; + } + } + + return configFile; + } + + protected abstract string GetRootDeploymentDirectory(string baseDirectory); + + /// + /// Get files corresponding to parameter deployment item. + /// + /// Deployment Item. + /// The test source. + /// Results directory which should be skipped for deployment + /// Warnings. + /// Is this a directory. + /// Paths to items to deploy. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] + protected string[] GetFullPathToFilesCorrespondingToDeploymentItem(DeploymentItem deploymentItem, string testSource, string resultsDirectory, IList warnings, out bool isDirectory) + { + Debug.Assert(deploymentItem != null, "deploymentItem should not be null."); + Debug.Assert(!string.IsNullOrEmpty(testSource), "testsource should not be null or empty."); + + try + { + isDirectory = this.IsDeploymentItemSourceADirectory(deploymentItem, testSource, out string directory); + if (isDirectory) + { + return this.FileUtility.AddFilesFromDirectory( + directory, (deployDirectory) => string.Equals(deployDirectory, resultsDirectory, StringComparison.OrdinalIgnoreCase), false).ToArray(); + } + + if (this.IsDeploymentItemSourceAFile(deploymentItem.SourcePath, testSource, out string fileName)) + { + return new[] { fileName }; + } + + // If file/directory is not found, then try removing the prefix and see if it is present. + string fileOrDirNameOnly = Path.GetFileName(deploymentItem.SourcePath.TrimEnd( + new char[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar })); + if (this.IsDeploymentItemSourceAFile(fileOrDirNameOnly, testSource, out fileName)) + { + return new[] { fileName }; + } + + string message = string.Format(CultureInfo.CurrentCulture, Resource.CannotFindFile, fileName); + throw new FileNotFoundException(message, fileName); + } + catch (Exception e) + { + warnings.Add(string.Format( + CultureInfo.CurrentCulture, Resource.DeploymentErrorFailedToGetFileForDeploymentItem, deploymentItem, e.GetType(), e.Message)); + } + + isDirectory = false; + return null; + } + + protected string GetFullPathToDeploymentItemSource(string deploymentItemSourcePath, string testSource) + { + if (Path.IsPathRooted(deploymentItemSourcePath)) + { + return deploymentItemSourcePath; + } + + return Path.Combine(Path.GetDirectoryName(testSource), deploymentItemSourcePath); + } + + /// + /// Validate the output directory for the parameter deployment item. + /// + /// The deployment item. + /// The deployment directory. + /// Warnings. + /// True if valid. + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] + protected bool IsOutputDirectoryValid(DeploymentItem deploymentItem, string deploymentDirectory, IList warnings) + { + Debug.Assert(deploymentItem != null, "deploymentItem should not be null."); + Debug.Assert(!string.IsNullOrEmpty(deploymentDirectory), "deploymentDirectory should not be null or empty."); + Debug.Assert(warnings != null, "warnings should not be null."); + + // Check that item.output dir does not go outside deployment Out dir, otherwise you can erase any file! + string outputDir = deploymentDirectory; + try + { + outputDir = Path.GetFullPath(Path.Combine(deploymentDirectory, deploymentItem.RelativeOutputDirectory)); + + // convert the short path to full length path (like joe~1.dom to joe.domain) and the comparison + // startsWith in the next loop will work for the matching paths. + deploymentDirectory = Path.GetFullPath(deploymentDirectory); + } + catch (Exception e) + { + string warning = string.Format( + CultureInfo.CurrentCulture, + Resource.DeploymentErrorFailedToAccesOutputDirectory, + deploymentItem.SourcePath, + outputDir, + e.GetType(), + e.GetExceptionMessage()); + + warnings.Add(warning); + return false; + } + + if (!outputDir.StartsWith(deploymentDirectory, StringComparison.OrdinalIgnoreCase)) + { + string warning = string.Format( + CultureInfo.CurrentCulture, + Resource.DeploymentErrorBadDeploymentItem, + deploymentItem.SourcePath, + deploymentItem.RelativeOutputDirectory); + warnings.Add(warning); + + return false; + } + + return true; + } + + protected string AddTestSourceConfigFileIfExists(string testSource, IList deploymentItems) + { + string configFile = this.GetConfigFile(testSource); + + if (string.IsNullOrEmpty(configFile) == false) + { + this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(configFile)); + } + + return configFile; + } + + /// + /// Log the parameter warnings on the parameter logger + /// + /// Execution recorder. + /// Warnings. + private static void LogWarnings(ITestExecutionRecorder testExecutionRecorder, IEnumerable warnings) + { + if (warnings == null) + { + return; + } + + Debug.Assert(testExecutionRecorder != null, "Logger should not be null"); + + // log the warnings + foreach (string warning in warnings) + { + testExecutionRecorder.SendMessage(TestMessageLevel.Warning, warning); + } + } + + private bool Deploy(string source, IRunContext runContext, ITestExecutionRecorder testExecutionRecorder, IList deploymentItems, TestRunDirectories runDirectories) + { + ValidateArg.NotNull(runDirectories, "runDirectories"); + if (EqtTrace.IsInfoEnabled) + { + EqtTrace.Info("MSTestExecutor: Found that deployment items for source {0} are: ", source); + foreach (var item in deploymentItems) + { + EqtTrace.Info("MSTestExecutor: SourcePath: - {0}", item.SourcePath); + } + } + + // Do the deployment. + EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "MSTestExecutor: Using deployment directory {0} for source {1}.", runDirectories.OutDirectory, source); + var warnings = this.Deploy(new List(deploymentItems), source, runDirectories.OutDirectory, this.GetTestResultsDirectory(runContext)); + + // Log warnings + LogWarnings(testExecutionRecorder, warnings); + return deploymentItems != null && deploymentItems.Count > 0; + } + + private bool IsDeploymentItemSourceAFile(string deploymentItemSourcePath, string testSource, out string file) + { + file = this.GetFullPathToDeploymentItemSource(deploymentItemSourcePath, testSource); + + return this.FileUtility.DoesFileExist(file); + } + + private bool IsDeploymentItemSourceADirectory(DeploymentItem deploymentItem, string testSource, out string resultDirectory) + { + resultDirectory = null; + + string directory = this.GetFullPathToDeploymentItemSource(deploymentItem.SourcePath, testSource); + directory = directory.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + + if (this.FileUtility.DoesDirectoryExist(directory)) + { + resultDirectory = directory; + return true; + } + + return false; + } + + /// + /// Get the parent test results directory where deployment will be done. + /// + /// The run context. + /// The test results directory. + private string GetTestResultsDirectory(IRunContext runContext) + { + var resultsDirectory = (!string.IsNullOrEmpty(runContext?.TestRunDirectory)) ? + runContext.TestRunDirectory : null; + + if (string.IsNullOrEmpty(resultsDirectory)) + { + resultsDirectory = Path.GetFullPath(Path.Combine(Path.GetTempPath(), TestRunDirectories.DefaultDeploymentRootDirectory)); + } + + return resultsDirectory; + } + } +} diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/FileUtility.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs similarity index 99% rename from src/Adapter/PlatformServices.Desktop/Utilities/FileUtility.cs rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs index 9a4826293e..3530aa3523 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/FileUtility.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs @@ -13,6 +13,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; using Microsoft.VisualStudio.TestPlatform.ObjectModel; + #pragma warning disable SA1649 // File name must match first type name + internal class FileUtility { private AssemblyUtility assemblyUtility; diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/Validate.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13Validate.cs similarity index 94% rename from src/Adapter/PlatformServices.Desktop/Utilities/Validate.cs rename to src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13Validate.cs index c7602e7f1f..b6d29d2749 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/Validate.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13Validate.cs @@ -5,6 +5,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti { using System; + #pragma warning disable SA1649 // File name must match first type name + internal class Validate { /// diff --git a/src/Adapter/PlatformServices.Desktop/Deployment/DeploymentItem.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs similarity index 98% rename from src/Adapter/PlatformServices.Desktop/Deployment/DeploymentItem.cs rename to src/Adapter/PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs index d5713dc543..06391729ae 100644 --- a/src/Adapter/PlatformServices.Desktop/Deployment/DeploymentItem.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs @@ -7,6 +7,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Dep using System.Diagnostics; using System.Globalization; +#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName + /// /// Specifies type of deployment item origin, where the item comes from. /// diff --git a/src/Adapter/PlatformServices.Desktop/Deployment/TestRunDirectories.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13TestRunDirectories.cs similarity index 97% rename from src/Adapter/PlatformServices.Desktop/Deployment/TestRunDirectories.cs rename to src/Adapter/PlatformServices.Shared/netstandard1.3/ns13TestRunDirectories.cs index 1643fc8527..377c2e2b2f 100644 --- a/src/Adapter/PlatformServices.Desktop/Deployment/TestRunDirectories.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13TestRunDirectories.cs @@ -7,6 +7,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Dep using System.Diagnostics; using System.IO; +#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName + /// /// The test run directories. /// From 48e4b7a3b0486a6bc08953dafd76d4aa32467364 Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Tue, 12 Feb 2019 13:13:14 +0530 Subject: [PATCH 02/24] Resources file changes --- .../MSTest.CoreAdapter.csproj | 15 +- .../Deployment/AssemblyLoadWorker.cs | 1 + .../PlatformServices.Desktop.csproj | 16 +- .../DesktopTestContextImplementation.cs | 1 + .../Services/DesktopTestDataSource.cs | 2 +- .../Utilities/DeploymentUtility.cs | 2 + .../Utilities/RandomIntPermutation.cs | 1 + .../Utilities/SequentialIntPermutation.cs | 1 + .../PlatformServices.NetCore.csproj | 13 +- .../Utilities/DeploymentUtility.cs | 144 +++++++++--------- .../Resources/Resource.Designer.cs | 4 +- .../Services/ns13MSTestAdapterSettings.cs | 2 + .../ns13TestContextPropertyStrings.cs | 6 +- .../Utilities/ns13DeploymentItemUtility.cs | 2 +- .../Utilities/ns13DeploymentUtilityBase.cs | 2 + .../Utilities/ns13FileUtility.cs | 3 +- .../netstandard1.3/ns13DeploymentItem.cs | 1 + .../Deployment/DeploymentItemTests.cs | 1 + .../Services/DesktopTestContextImplTests.cs | 1 + .../Utilities/DeploymentItemUtilityTests.cs | 1 + .../Utilities/DeploymentUtilityTests.cs | 5 +- 21 files changed, 119 insertions(+), 105 deletions(-) diff --git a/src/Adapter/MSTest.CoreAdapter/MSTest.CoreAdapter.csproj b/src/Adapter/MSTest.CoreAdapter/MSTest.CoreAdapter.csproj index cdbac5552b..33567b9e2f 100644 --- a/src/Adapter/MSTest.CoreAdapter/MSTest.CoreAdapter.csproj +++ b/src/Adapter/MSTest.CoreAdapter/MSTest.CoreAdapter.csproj @@ -111,20 +111,6 @@ - - - - - - - - - - - - - - @@ -139,6 +125,7 @@ ResXFileCodeGenerator Resource.Designer.cs + Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter diff --git a/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs b/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs index 7be9285bc2..c5f7139a0c 100644 --- a/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs +++ b/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs @@ -9,6 +9,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Dep using System.Globalization; using System.IO; using System.Reflection; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; using Microsoft.VisualStudio.TestPlatform.ObjectModel; diff --git a/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj b/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj index 0ca5217a84..6aac0be8c1 100644 --- a/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj +++ b/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj @@ -55,6 +55,9 @@ Resources\Resource.Designer.cs + True + True + Resource.resx Services\ns13MSTestAdapterSettings.cs @@ -133,6 +136,13 @@ False + + + Resources\Resource.resx + ResXFileCodeGenerator + Resource.Designer.cs + + Resources\xlf\Resource.cs.xlf @@ -176,12 +186,6 @@ Resources\xlf\Resource.zh-Hant.xlf - - - - - Resources\Resource.resx - \ No newline at end of file diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs index 4bb97b58ce..2167b37137 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs @@ -16,6 +16,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using UTF = Microsoft.VisualStudio.TestTools.UnitTesting; #pragma warning disable SA1649 // File name must match first type name diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs index 0019d0b5ca..7b7392e26e 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs @@ -13,7 +13,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Data; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; - + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using UTF = Microsoft.VisualStudio.TestTools.UnitTesting; #pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtility.cs b/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtility.cs index 6d8766b671..ce02ed3841 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtility.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtility.cs @@ -14,6 +14,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/RandomIntPermutation.cs b/src/Adapter/PlatformServices.Desktop/Utilities/RandomIntPermutation.cs index 56b2ffd83b..1f3f0aaea4 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/RandomIntPermutation.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/RandomIntPermutation.cs @@ -6,6 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using System; using System.Collections; using System.Collections.Generic; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; /// /// Permutation of integers from 0 to (numberOfObjects - 1), in random order and in the end all values are returned. diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/SequentialIntPermutation.cs b/src/Adapter/PlatformServices.Desktop/Utilities/SequentialIntPermutation.cs index 7d345e7e0b..576c34bc14 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/SequentialIntPermutation.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/SequentialIntPermutation.cs @@ -6,6 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using System; using System.Collections; using System.Collections.Generic; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; /// /// Permutation of integers from 0 to (numberOfObjects - 1) returned by increment of 1. diff --git a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj index 60df0d1581..4f35f34eea 100644 --- a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj +++ b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj @@ -28,7 +28,6 @@ - @@ -45,10 +44,20 @@ + + Resources\Resource.Designer.cs + True + True + Resource.resx + - + + Resources\Resource.resx + ResXFileCodeGenerator + Resource.Designer.cs + diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtility.cs b/src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtility.cs index 4a96d32bfa..648908b219 100644 --- a/src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtility.cs +++ b/src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtility.cs @@ -14,6 +14,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; @@ -49,8 +50,16 @@ public override IEnumerable Deploy(IList deploymentItems testSource = Path.GetFullPath(testSource); var warnings = new List(); - EqtTrace.Info("Adding the test source directory to the deploymentitems list"); - this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(Path.GetDirectoryName(testSource))); + string errorMessage; + if (!this.DeploymentItemUtility.IsValidDeploymentItem(testSource, string.Empty, out errorMessage)) + { + warnings.Add(errorMessage); + } + else + { + EqtTrace.Info("Adding the test source directory to the deploymentitems list"); + this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(Path.GetDirectoryName(testSource))); + } // Maps relative to Out dir destination -> source and used to determine if there are conflicted items. var destToSource = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -76,88 +85,81 @@ public override IEnumerable Deploy(IList deploymentItems var fullPathToDeploymentItemSource = this.GetFullPathToDeploymentItemSource(deploymentItem.SourcePath, testSource); // Note: source is already rooted. - foreach (var deploymentItemFile in deploymentItemFiles) + foreach (var fileToDeploy in deploymentItemFiles) { - Debug.Assert(Path.IsPathRooted(deploymentItemFile), "File " + deploymentItemFile + " is not rooted"); + Debug.Assert(Path.IsPathRooted(fileToDeploy), "File " + fileToDeploy + " is not rooted"); - // List of files to deploy, by default, just itemFile. - var filesToDeploy = new List(1); - filesToDeploy.Add(deploymentItemFile); + Debug.Assert(Path.IsPathRooted(fileToDeploy), "File " + fileToDeploy + " is not rooted"); - foreach (var fileToDeploy in filesToDeploy) + // Ignore the test platform files. + var tempFile = Path.GetFileName(fileToDeploy); + var assemblyName = Path.GetFileName(this.GetType().GetTypeInfo().Assembly.Location); + if (tempFile.Equals(assemblyName, StringComparison.OrdinalIgnoreCase)) { - Debug.Assert(Path.IsPathRooted(fileToDeploy), "File " + fileToDeploy + " is not rooted"); + continue; + } - // Ignore the test platform files. - var tempFile = Path.GetFileName(fileToDeploy); - var assemblyName = Path.GetFileName(this.GetType().GetTypeInfo().Assembly.Location); - if (tempFile.Equals(assemblyName, StringComparison.OrdinalIgnoreCase)) - { - continue; - } + string relativeDestination; + if (itemIsDirectory) + { + // Deploy into subdirectory of deployment (Out) dir. + Debug.Assert(fileToDeploy.StartsWith(fullPathToDeploymentItemSource, StringComparison.Ordinal), "Somehow source is outside original dir."); + relativeDestination = this.FileUtility.TryConvertPathToRelative(fileToDeploy, fullPathToDeploymentItemSource); + } + else + { + // Deploy just to the deployment (Out) dir. + relativeDestination = Path.GetFileName(fileToDeploy); + } - string relativeDestination; - if (itemIsDirectory) - { - // Deploy into subdirectory of deployment (Out) dir. - Debug.Assert(fileToDeploy.StartsWith(fullPathToDeploymentItemSource, StringComparison.Ordinal), "Somehow source is outside original dir."); - relativeDestination = this.FileUtility.TryConvertPathToRelative(fileToDeploy, fullPathToDeploymentItemSource); - } - else - { - // Deploy just to the deployment (Out) dir. - relativeDestination = Path.GetFileName(fileToDeploy); - } + relativeDestination = Path.Combine(deploymentItem.RelativeOutputDirectory, relativeDestination); // Ignores empty arg1. + var destination = Path.Combine(deploymentDirectory, relativeDestination); + try + { + destination = Path.GetFullPath(destination); + } + catch (Exception e) + { + var warning = string.Format(CultureInfo.CurrentCulture, Resource.DeploymentErrorFailedToAccessFile, destination, e.GetType(), e.Message); + warnings.Add(warning); - relativeDestination = Path.Combine(deploymentItem.RelativeOutputDirectory, relativeDestination); // Ignores empty arg1. - var destination = Path.Combine(deploymentDirectory, relativeDestination); - try - { - destination = Path.GetFullPath(destination); - } - catch (Exception e) - { - var warning = string.Format(CultureInfo.CurrentCulture, Resource.DeploymentErrorFailedToAccessFile, destination, e.GetType(), e.Message); - warnings.Add(warning); + continue; + } - continue; - } + if (!destToSource.ContainsKey(relativeDestination)) + { + destToSource.Add(relativeDestination, fileToDeploy); - if (!destToSource.ContainsKey(relativeDestination)) + // Now, finally we can copy the file... + destination = this.FileUtility.CopyFileOverwrite(fileToDeploy, destination, out string warning); + if (!string.IsNullOrEmpty(warning)) { - destToSource.Add(relativeDestination, fileToDeploy); - - // Now, finally we can copy the file... - destination = this.FileUtility.CopyFileOverwrite(fileToDeploy, destination, out string warning); - if (!string.IsNullOrEmpty(warning)) - { - warnings.Add(warning); - } - - if (string.IsNullOrEmpty(destination)) - { - continue; - } - - // We clear the attributes so that e.g. you can write to the copies of files originally under SCC. - this.FileUtility.SetAttributes(destination, FileAttributes.Normal); - - // Deploy PDB for line number info in stack trace. - this.FileUtility.FindAndDeployPdb(destination, relativeDestination, fileToDeploy, destToSource); + warnings.Add(warning); } - else if ( - !string.Equals( - fileToDeploy, - destToSource[relativeDestination], - StringComparison.OrdinalIgnoreCase)) + + if (string.IsNullOrEmpty(destination)) { - EqtTrace.WarningIf( - EqtTrace.IsWarningEnabled, - "Conflict during copiyng file: '{0}' and '{1}' are from different origins although they might be the same.", - fileToDeploy, - destToSource[relativeDestination]); + continue; } - } // foreach fileToDeploy. + + // We clear the attributes so that e.g. you can write to the copies of files originally under SCC. + this.FileUtility.SetAttributes(destination, FileAttributes.Normal); + + // Deploy PDB for line number info in stack trace. + this.FileUtility.FindAndDeployPdb(destination, relativeDestination, fileToDeploy, destToSource); + } + else if ( + !string.Equals( + fileToDeploy, + destToSource[relativeDestination], + StringComparison.OrdinalIgnoreCase)) + { + EqtTrace.WarningIf( + EqtTrace.IsWarningEnabled, + "Conflict during copiyng file: '{0}' and '{1}' are from different origins although they might be the same.", + fileToDeploy, + destToSource[relativeDestination]); + } } // foreach itemFile. } diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/Resource.Designer.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/Resource.Designer.cs index fd65a3f5d4..5756c4cd12 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/Resource.Designer.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/Resource.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices { +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources { using System; using System.Reflection; @@ -20,7 +20,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class Resource { diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs index 67c1015039..6df0ac2447 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs @@ -8,6 +8,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using System.Globalization; using System.IO; using System.Xml; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestContextPropertyStrings.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestContextPropertyStrings.cs index b379eed2ac..c12bc8d49a 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestContextPropertyStrings.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestContextPropertyStrings.cs @@ -5,11 +5,11 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices { #pragma warning disable SA1649 // File name must match first type name + /// + /// Test Context Property Names. + /// internal static class TestContextPropertyStrings { - /// - /// Test Context Property Names. - /// public static readonly string TestRunDirectory = "TestRunDirectory"; public static readonly string DeploymentDirectory = "DeploymentDirectory"; public static readonly string ResultsDirectory = "ResultsDirectory"; diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs index cabc054564..69757d40df 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs @@ -10,8 +10,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using System.IO; using System.Linq; using System.Reflection; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs index d60742f848..998b7062c6 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs @@ -14,6 +14,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs index 3530aa3523..08dc4bb28f 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs @@ -11,9 +11,10 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using System.Linq; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Microsoft.VisualStudio.TestPlatform.ObjectModel; - #pragma warning disable SA1649 // File name must match first type name +#pragma warning disable SA1649 // File name must match first type name internal class FileUtility { diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs index 06391729ae..1d47800a83 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs @@ -6,6 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Dep using System; using System.Diagnostics; using System.Globalization; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; #pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/DeploymentItemTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/DeploymentItemTests.cs index aa2be3801f..b9074583f0 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/DeploymentItemTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/DeploymentItemTests.cs @@ -7,6 +7,7 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Deployment using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Assert = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.Assert; using TestClass = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestContextImplTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestContextImplTests.cs index beb84028a2..ae9f40cc33 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestContextImplTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestContextImplTests.cs @@ -14,6 +14,7 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Services using System.Linq; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Moq; using MSTestAdapter.TestUtilities; using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentItemUtilityTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentItemUtilityTests.cs index 59bd405eef..0c3d2d4fc6 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentItemUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentItemUtilityTests.cs @@ -13,6 +13,7 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Utilities using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; using Microsoft.VisualStudio.TestPlatform.ObjectModel; diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentUtilityTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentUtilityTests.cs index 6e41edd409..a3592b1519 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentUtilityTests.cs @@ -10,16 +10,13 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Utilities using System.Collections.Generic; using System.IO; using System.Reflection; - using System.Xml; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; using Moq; - using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute; From 928d8c674df0216bc45c24f9f05bdea14f9a1ac3 Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Wed, 13 Feb 2019 17:49:46 +0530 Subject: [PATCH 03/24] Resources handling and renaming files --- scripts/build/TestFx.Loc.targets | 29 ++++++++- .../Deployment/AssemblyLoadWorker.cs | 1 - .../PlatformServices.Desktop.csproj | 21 ++++--- ...th.cs => RecursiveDirectoryPathDesktop.cs} | 2 + .../DesktopTestContextImplementation.cs | 1 - .../Services/DesktopTestDataSource.cs | 1 - ...lyUtility.cs => AssemblyUtilityDesktop.cs} | 2 + ...Utility.cs => DeploymentUtilityDesktop.cs} | 3 +- .../Utilities/RandomIntPermutation.cs | 1 - ...Utility.cs => ReflectionUtilityDesktop.cs} | 2 + .../Utilities/SequentialIntPermutation.cs | 1 - .../Deployment/AssemblyLoadWorker.cs | 43 ------------- .../PlatformServices.NetCore.csproj | 16 +++-- .../RecursiveDirectoryPathNetCore.cs | 62 +++++++++++++++++++ ...lyUtility.cs => AssemblyUtilityNetCore.cs} | 2 + ...Utility.cs => DeploymentUtilityNetCore.cs} | 3 +- ...Utility.cs => ReflectionUtilityNetCore.cs} | 2 + ...rings.cs => TestContextPropertyStrings.cs} | 7 ++- .../Resources/Resource.Designer.cs | 2 +- .../Services/ns13MSTestAdapterSettings.cs | 1 - .../Utilities/ns13DeploymentItemUtility.cs | 1 - .../Utilities/ns13DeploymentUtilityBase.cs | 9 ++- .../Utilities/ns13FileUtility.cs | 1 - .../netstandard1.3/ns13DeploymentItem.cs | 1 - src/Package/MSTest.TestAdapter.nuspec | 14 +++++ .../Deployment/DeploymentItemTests.cs | 1 - .../Services/DesktopTestContextImplTests.cs | 1 - .../Utilities/DeploymentItemUtilityTests.cs | 1 - .../Utilities/DeploymentUtilityTests.cs | 2 +- 29 files changed, 156 insertions(+), 77 deletions(-) rename src/Adapter/PlatformServices.Desktop/{RecursiveDirectoryPath.cs => RecursiveDirectoryPathDesktop.cs} (96%) rename src/Adapter/PlatformServices.Desktop/Utilities/{AssemblyUtility.cs => AssemblyUtilityDesktop.cs} (99%) rename src/Adapter/PlatformServices.Desktop/Utilities/{DeploymentUtility.cs => DeploymentUtilityDesktop.cs} (99%) rename src/Adapter/PlatformServices.Desktop/Utilities/{ReflectionUtility.cs => ReflectionUtilityDesktop.cs} (99%) delete mode 100644 src/Adapter/PlatformServices.NetCore/Deployment/AssemblyLoadWorker.cs create mode 100644 src/Adapter/PlatformServices.NetCore/RecursiveDirectoryPathNetCore.cs rename src/Adapter/PlatformServices.NetCore/Utilities/{AssemblyUtility.cs => AssemblyUtilityNetCore.cs} (95%) rename src/Adapter/PlatformServices.NetCore/Utilities/{DeploymentUtility.cs => DeploymentUtilityNetCore.cs} (99%) rename src/Adapter/PlatformServices.NetCore/Utilities/{ReflectionUtility.cs => ReflectionUtilityNetCore.cs} (94%) rename src/Adapter/PlatformServices.Shared/netstandard1.0/Services/{ns10TestContextPropertyStrings.cs => TestContextPropertyStrings.cs} (88%) diff --git a/scripts/build/TestFx.Loc.targets b/scripts/build/TestFx.Loc.targets index 00f80d1036..bd2481f37d 100644 --- a/scripts/build/TestFx.Loc.targets +++ b/scripts/build/TestFx.Loc.targets @@ -9,6 +9,7 @@ $(ProjectDir)Resources + $(ProjectDir)..\PlatformServices.Shared\netstandard1.3\Resources @@ -20,11 +21,14 @@ - + - + + + @@ -33,6 +37,16 @@ + + + + + + + + + + @@ -42,6 +56,17 @@ + + + + + + + + + + + diff --git a/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs b/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs index c5f7139a0c..7be9285bc2 100644 --- a/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs +++ b/src/Adapter/PlatformServices.Desktop/Deployment/AssemblyLoadWorker.cs @@ -9,7 +9,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Dep using System.Globalization; using System.IO; using System.Reflection; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; using Microsoft.VisualStudio.TestPlatform.ObjectModel; diff --git a/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj b/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj index 72724fd485..4d117c9632 100644 --- a/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj +++ b/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj @@ -11,6 +11,7 @@ Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices v4.5 + true true @@ -44,6 +45,9 @@ + + Services\TestContextPropertyStrings.cs + Extensions\ns13ExceptionExtensions.cs @@ -62,9 +66,6 @@ Services\ns13MSTestAdapterSettings.cs - - Services\ns13TestContextPropertyStrings.cs - Utilities\ns13DeploymentItemUtility.cs @@ -108,14 +109,14 @@ - + - - + + - + @@ -136,12 +137,18 @@ False + + + Resources\Resource.resx ResXFileCodeGenerator Resource.Designer.cs + Designer + Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices + \ No newline at end of file diff --git a/src/Adapter/PlatformServices.Desktop/RecursiveDirectoryPath.cs b/src/Adapter/PlatformServices.Desktop/RecursiveDirectoryPathDesktop.cs similarity index 96% rename from src/Adapter/PlatformServices.Desktop/RecursiveDirectoryPath.cs rename to src/Adapter/PlatformServices.Desktop/RecursiveDirectoryPathDesktop.cs index 0046980b87..52da3e51e0 100644 --- a/src/Adapter/PlatformServices.Desktop/RecursiveDirectoryPath.cs +++ b/src/Adapter/PlatformServices.Desktop/RecursiveDirectoryPathDesktop.cs @@ -6,6 +6,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using System; using System.Diagnostics.CodeAnalysis; +#pragma warning disable SA1649 // File name must match first type name + /// /// Mstest settings in runsettings look like this /// diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs index c800e884af..46e7641eed 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs @@ -16,7 +16,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using UTF = Microsoft.VisualStudio.TestTools.UnitTesting; #pragma warning disable SA1649 // File name must match first type name diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs index 7b7392e26e..773dcd85c0 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs @@ -13,7 +13,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Data; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using UTF = Microsoft.VisualStudio.TestTools.UnitTesting; #pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/AssemblyUtility.cs b/src/Adapter/PlatformServices.Desktop/Utilities/AssemblyUtilityDesktop.cs similarity index 99% rename from src/Adapter/PlatformServices.Desktop/Utilities/AssemblyUtility.cs rename to src/Adapter/PlatformServices.Desktop/Utilities/AssemblyUtilityDesktop.cs index 006849bce7..c5b4931c15 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/AssemblyUtility.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/AssemblyUtilityDesktop.cs @@ -13,6 +13,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; using Microsoft.VisualStudio.TestPlatform.ObjectModel; +#pragma warning disable SA1649 // File name must match first type name + /// /// Utility for assembly specific functionality. /// diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtility.cs b/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtilityDesktop.cs similarity index 99% rename from src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtility.cs rename to src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtilityDesktop.cs index ce02ed3841..de56f94c21 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtility.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtilityDesktop.cs @@ -14,12 +14,13 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; +#pragma warning disable SA1649 // File name must match first type name + internal class DeploymentUtility : DeploymentUtilityBase { public DeploymentUtility() diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/RandomIntPermutation.cs b/src/Adapter/PlatformServices.Desktop/Utilities/RandomIntPermutation.cs index 1f3f0aaea4..56b2ffd83b 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/RandomIntPermutation.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/RandomIntPermutation.cs @@ -6,7 +6,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using System; using System.Collections; using System.Collections.Generic; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; /// /// Permutation of integers from 0 to (numberOfObjects - 1), in random order and in the end all values are returned. diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/ReflectionUtility.cs b/src/Adapter/PlatformServices.Desktop/Utilities/ReflectionUtilityDesktop.cs similarity index 99% rename from src/Adapter/PlatformServices.Desktop/Utilities/ReflectionUtility.cs rename to src/Adapter/PlatformServices.Desktop/Utilities/ReflectionUtilityDesktop.cs index 4b3127f89f..ea00146e3b 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/ReflectionUtility.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/ReflectionUtilityDesktop.cs @@ -10,6 +10,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using System.Linq; using System.Reflection; +#pragma warning disable SA1649 // File name must match first type name + /// /// Utility for reflection API's /// diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/SequentialIntPermutation.cs b/src/Adapter/PlatformServices.Desktop/Utilities/SequentialIntPermutation.cs index 576c34bc14..7d345e7e0b 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/SequentialIntPermutation.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/SequentialIntPermutation.cs @@ -6,7 +6,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using System; using System.Collections; using System.Collections.Generic; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; /// /// Permutation of integers from 0 to (numberOfObjects - 1) returned by increment of 1. diff --git a/src/Adapter/PlatformServices.NetCore/Deployment/AssemblyLoadWorker.cs b/src/Adapter/PlatformServices.NetCore/Deployment/AssemblyLoadWorker.cs deleted file mode 100644 index 5bebdff7b2..0000000000 --- a/src/Adapter/PlatformServices.NetCore/Deployment/AssemblyLoadWorker.cs +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment -{ - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.Globalization; - using System.IO; - using System.Reflection; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; - using Microsoft.VisualStudio.TestPlatform.ObjectModel; - - /// - /// Utility function for Assembly related info - /// The caller is supposed to create AppDomain and create instance of given class in there. - /// - internal class AssemblyLoadWorker : MarshalByRefObject - { - private AssemblyUtility assemblyUtility; - - public AssemblyLoadWorker() - : this(new AssemblyUtility()) - { - } - - internal AssemblyLoadWorker(AssemblyUtility assemblyUtility) - { - this.assemblyUtility = assemblyUtility; - } - - /// - /// initialize the lifetime service. - /// - /// The . - public override object InitializeLifetimeService() - { - // Infinite. - return null; - } - } -} diff --git a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj index df38924a26..7e17546009 100644 --- a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj +++ b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj @@ -10,6 +10,8 @@ netstandard1.5 $(PackageTargetFallback);portable-net45+win8+wpa81+wp8 false + true + false @@ -25,12 +27,12 @@ + - @@ -38,12 +40,11 @@ - - - - - + + + + Resources\Resource.Designer.cs True @@ -57,6 +58,8 @@ Resources\Resource.resx ResXFileCodeGenerator Resource.Designer.cs + Designer + Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices @@ -71,6 +74,7 @@ + \ No newline at end of file diff --git a/src/Adapter/PlatformServices.NetCore/RecursiveDirectoryPathNetCore.cs b/src/Adapter/PlatformServices.NetCore/RecursiveDirectoryPathNetCore.cs new file mode 100644 index 0000000000..1671dcec8f --- /dev/null +++ b/src/Adapter/PlatformServices.NetCore/RecursiveDirectoryPathNetCore.cs @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices +{ + using System; + using System.Diagnostics.CodeAnalysis; + using System.Security; + + /// + /// Mstest settings in runsettings look like this + /// + /// + /// + /// + /// ...// by default includeSubDirectories is false + /// + /// + /// + /// For each directory we need to have two info 1) path 2) includeSubDirectories + /// + [Serializable] + [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1603:DocumentationMustContainValidXml", Justification = "Reviewed. Suppression is OK here.")] +#pragma warning disable SA1649 // File name must match first type name + public class RecursiveDirectoryPath : MarshalByRefObject + { + /// + /// Initializes a new instance of the class. + /// + /// The directory path. + /// + /// True if to include subdirectory else false + /// + public RecursiveDirectoryPath(string dirPath, bool includeSubDirectories) + { + this.DirectoryPath = dirPath; + this.IncludeSubDirectories = includeSubDirectories; + } + + /// + /// Gets the directory path. + /// + public string DirectoryPath { get; private set; } + + /// + /// Gets a value indicating whether to include sub directories. + /// + public bool IncludeSubDirectories { get; private set; } + + /// + /// Returns object to be used for controlling lifetime, null means infinite lifetime. + /// + /// + /// The . + /// + [SecurityCritical] + public override object InitializeLifetimeService() + { + return null; + } + } +} diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/AssemblyUtility.cs b/src/Adapter/PlatformServices.NetCore/Utilities/AssemblyUtilityNetCore.cs similarity index 95% rename from src/Adapter/PlatformServices.NetCore/Utilities/AssemblyUtility.cs rename to src/Adapter/PlatformServices.NetCore/Utilities/AssemblyUtilityNetCore.cs index 923d005162..8d34582d64 100644 --- a/src/Adapter/PlatformServices.NetCore/Utilities/AssemblyUtility.cs +++ b/src/Adapter/PlatformServices.NetCore/Utilities/AssemblyUtilityNetCore.cs @@ -13,6 +13,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; using Microsoft.VisualStudio.TestPlatform.ObjectModel; +#pragma warning disable SA1649 // File name must match first type name + /// /// Utility for assembly specific functionality. /// diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtility.cs b/src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtilityNetCore.cs similarity index 99% rename from src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtility.cs rename to src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtilityNetCore.cs index 648908b219..fa4b74aa05 100644 --- a/src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtility.cs +++ b/src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtilityNetCore.cs @@ -14,11 +14,12 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; +#pragma warning disable SA1649 // File name must match first type name + internal class DeploymentUtility : DeploymentUtilityBase { public DeploymentUtility() diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtility.cs b/src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtilityNetCore.cs similarity index 94% rename from src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtility.cs rename to src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtilityNetCore.cs index 09c34c6fe1..6258ee56b8 100644 --- a/src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtility.cs +++ b/src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtilityNetCore.cs @@ -11,6 +11,8 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using System.Linq; using System.Reflection; +#pragma warning disable SA1649 // File name must match first type name + /// /// Utility for reflection API's /// diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextPropertyStrings.cs b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/TestContextPropertyStrings.cs similarity index 88% rename from src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextPropertyStrings.cs rename to src/Adapter/PlatformServices.Shared/netstandard1.0/Services/TestContextPropertyStrings.cs index 1a303a998c..f794d6f902 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextPropertyStrings.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/TestContextPropertyStrings.cs @@ -3,8 +3,11 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices { - #pragma warning disable SA1649 // File name must match first type name - +#pragma warning disable SA1649 // File name must match first type name + + /// + /// Test Context Property Names. + /// internal static class TestContextPropertyStrings { public static readonly string TestRunDirectory = "TestRunDirectory"; diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/Resource.Designer.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/Resource.Designer.cs index 5756c4cd12..faa1361b99 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/Resource.Designer.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Resources/Resource.Designer.cs @@ -8,7 +8,7 @@ // //------------------------------------------------------------------------------ -namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources { +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices { using System; using System.Reflection; diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs index 6df0ac2447..3e5746a79c 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs @@ -8,7 +8,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using System.Globalization; using System.IO; using System.Xml; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs index 69757d40df..d272f919a5 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs @@ -11,7 +11,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using System.Linq; using System.Reflection; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestTools.UnitTesting; diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs index 998b7062c6..e20676a186 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs @@ -14,7 +14,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; @@ -81,6 +80,14 @@ public TestRunDirectories CreateDeploymentDirectories(IRunContext runContext) return result; } + /// + /// Does the deployment of parameter deployment items & the testSource to the parameter directory. + /// + /// The deployment item. + /// The test source. + /// The deployment directory. + /// Root results directory + /// Returns a list of deployment warnings public abstract IEnumerable Deploy(IList deploymentItems, string testSource, string deploymentDirectory, string resultsDirectory); internal string GetConfigFile(string testSource) diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs index 08dc4bb28f..b150fd5054 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs @@ -11,7 +11,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using System.Linq; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Microsoft.VisualStudio.TestPlatform.ObjectModel; #pragma warning disable SA1649 // File name must match first type name diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs index 1d47800a83..06391729ae 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs @@ -6,7 +6,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Dep using System; using System.Diagnostics; using System.Globalization; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; #pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName diff --git a/src/Package/MSTest.TestAdapter.nuspec b/src/Package/MSTest.TestAdapter.nuspec index 8ef68ec7f8..bc6e7fc79e 100644 --- a/src/Package/MSTest.TestAdapter.nuspec +++ b/src/Package/MSTest.TestAdapter.nuspec @@ -79,6 +79,20 @@ + + + + + + + + + + + + + + diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/DeploymentItemTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/DeploymentItemTests.cs index b9074583f0..aa2be3801f 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/DeploymentItemTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/DeploymentItemTests.cs @@ -7,7 +7,6 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Deployment using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Assert = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.Assert; using TestClass = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestContextImplTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestContextImplTests.cs index 78171dae57..005b9c1c3d 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestContextImplTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestContextImplTests.cs @@ -14,7 +14,6 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Services using System.Linq; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Moq; using MSTestAdapter.TestUtilities; using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentItemUtilityTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentItemUtilityTests.cs index 0c3d2d4fc6..59bd405eef 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentItemUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentItemUtilityTests.cs @@ -13,7 +13,6 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Utilities using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; using Microsoft.VisualStudio.TestPlatform.ObjectModel; diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentUtilityTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentUtilityTests.cs index a3592b1519..328765b108 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentUtilityTests.cs @@ -10,8 +10,8 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Utilities using System.Collections.Generic; using System.IO; using System.Reflection; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; From 42d3a8173f5accea2829e0df27c6c3b1b7ebad0c Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Wed, 20 Feb 2019 01:52:26 +0530 Subject: [PATCH 04/24] Adding UT's --- .../PlatformServices.Desktop.csproj | 2 +- .../PlatformServices.NetCore/Friends.cs | 1 + .../Utilities/ReflectionUtilityNetCore.cs | 16 + .../Attributes/DeploymentItemAttribute.cs | 3 - ...PlatformServices.Desktop.Unit.Tests.csproj | 16 +- .../AssemblyAttribute.cs | 11 + ...PlatformServices.NetCore.Unit.Tests.csproj | 10 +- .../Services/MSTestAdapterSettingsTests.cs | 336 +++++++++++++ .../DeploymentItemUtilityNetCoreTests.cs | 461 ++++++++++++++++++ .../DeploymentUtilityNetCoreTests.cs | 338 +++++++++++++ .../ReflectionUtilityTestsNetCore.cs | 276 +++++++++++ .../Deployment/ns10DeploymentItemTests.cs} | 13 +- .../ns10TestRunDirectoriesTests.cs} | 14 +- .../ns10ExceptionExtensionsTests.cs} | 13 +- .../Utilities/ns10FileUtilityTests.cs} | 23 +- .../ns10SettingsProviderTests.cs | 4 +- 16 files changed, 1501 insertions(+), 36 deletions(-) create mode 100644 test/UnitTests/PlatformServices.NetCore.Unit.Tests/AssemblyAttribute.cs create mode 100644 test/UnitTests/PlatformServices.NetCore.Unit.Tests/Services/MSTestAdapterSettingsTests.cs create mode 100644 test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/DeploymentItemUtilityNetCoreTests.cs create mode 100644 test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/DeploymentUtilityNetCoreTests.cs create mode 100644 test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/ReflectionUtilityTestsNetCore.cs rename test/UnitTests/{PlatformServices.Desktop.Unit.Tests/Deployment/DeploymentItemTests.cs => PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs} (95%) rename test/UnitTests/{PlatformServices.Desktop.Unit.Tests/Deployment/TestRunDirectoriesTests.cs => PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs} (83%) rename test/UnitTests/{PlatformServices.Desktop.Unit.Tests/Extensions/ExceptionExtensionsTests.cs => PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs} (87%) rename test/UnitTests/{PlatformServices.Desktop.Unit.Tests/Utilities/FileUtilityTests.cs => PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs} (97%) diff --git a/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj b/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj index 4d117c9632..70e1710cc7 100644 --- a/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj +++ b/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj @@ -52,7 +52,7 @@ Extensions\ns13ExceptionExtensions.cs - Utilities\ns13DeploymentItem.cs + Deployment\ns13DeploymentItem.cs Deployment\ns13TestRunDirectories.cs diff --git a/src/Adapter/PlatformServices.NetCore/Friends.cs b/src/Adapter/PlatformServices.NetCore/Friends.cs index a1a19f0530..0878c09cbf 100644 --- a/src/Adapter/PlatformServices.NetCore/Friends.cs +++ b/src/Adapter/PlatformServices.NetCore/Friends.cs @@ -5,3 +5,4 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("MSTestAdapter.PlatformServices.NetCore.UnitTests, PublicKey=002400000480000094000000060200000024000052534131000400000100010007d1fa57c4aed9f0a32e84aa0faefd0de9e8fd6aec8f87fb03766c834c99921eb23be79ad9d5dcc1dd9ad236132102900b723cf980957fc4e177108fc607774f29e8320e92ea05ece4e821c0a5efe8f1645c4c0c93c1ab99285d622caa652c1dfad63d745d6f2de5f17e5eaf0fc4963d261c8a12436518206dc093344d5ad293")] +[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] \ No newline at end of file diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtilityNetCore.cs b/src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtilityNetCore.cs index 6258ee56b8..03dfdfa89c 100644 --- a/src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtilityNetCore.cs +++ b/src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtilityNetCore.cs @@ -23,6 +23,17 @@ internal virtual object[] GetCustomAttributes(MemberInfo attributeProvider, Type return this.GetCustomAttributes(attributeProvider, type, true); } + /// + /// Gets all the custom attributes adorned on a member. + /// + /// The member. + /// True to inspect the ancestors of element; otherwise, false. + /// The list of attributes on the member. Empty list if none found. + internal object[] GetCustomAttributes(MemberInfo memberInfo, bool inherit) + { + return this.GetCustomAttributes(memberInfo, type: null, inherit: inherit); + } + internal object[] GetCustomAttributes(MemberInfo memberInfo, Type type, bool inherit) { if (memberInfo == null) @@ -41,5 +52,10 @@ internal object[] GetCustomAttributes(MemberInfo memberInfo, Type type, bool inh return memberInfo.GetCustomAttributes(type, inherit).ToArray(); } } + + internal object[] GetCustomAttributes(Assembly assembly, Type type) + { + return assembly.GetCustomAttributes(type).ToArray(); + } } } diff --git a/src/TestFramework/Extension.Core/Attributes/DeploymentItemAttribute.cs b/src/TestFramework/Extension.Core/Attributes/DeploymentItemAttribute.cs index c84260967f..8a7308d248 100644 --- a/src/TestFramework/Extension.Core/Attributes/DeploymentItemAttribute.cs +++ b/src/TestFramework/Extension.Core/Attributes/DeploymentItemAttribute.cs @@ -16,9 +16,6 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting /// [DeploymentItem("file2.xml", "DataFiles")] /// [DeploymentItem("bin\Debug")] /// - /// - /// DeploymentItemAttribute is currently not supported in .Net Core. This is just a placehodler for support in the future. - /// [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = true)] public sealed class DeploymentItemAttribute : Attribute { diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/PlatformServices.Desktop.Unit.Tests.csproj b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/PlatformServices.Desktop.Unit.Tests.csproj index a650c183c6..a323bac277 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/PlatformServices.Desktop.Unit.Tests.csproj +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/PlatformServices.Desktop.Unit.Tests.csproj @@ -55,6 +55,18 @@ + + Deployment\ns10DeploymentItemTests.cs + + + Deployment\ns10TestRunDirectoriesTests.cs + + + Extensions\ns10ExceptionExtensionsTests.cs + + + Utilities\ns10FileUtilityTests.cs + Services\ns13TraceListenerManagerTests.cs @@ -63,9 +75,6 @@ - - - @@ -80,7 +89,6 @@ - diff --git a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/AssemblyAttribute.cs b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/AssemblyAttribute.cs new file mode 100644 index 0000000000..e2e8aa5233 --- /dev/null +++ b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/AssemblyAttribute.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using MSTestAdapter.PlatformServices.Tests.Services; +using MSTestAdapter.PlatformServices.Tests.Utilities; + +[assembly: ReflectionUtilityTests.DummyAAttribute("a1")] +[assembly: ReflectionUtilityTests.DummyAAttribute("a2")] + +[assembly: ReflectionOperationsTests.DummyAAttribute("a1")] +[assembly: ReflectionOperationsTests.DummyAAttribute("a2")] \ No newline at end of file diff --git a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj index d5d807f123..3297217eb8 100644 --- a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj +++ b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj @@ -13,7 +13,9 @@ - + + + @@ -22,6 +24,7 @@ + @@ -33,21 +36,18 @@ - true - true - true - true + diff --git a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Services/MSTestAdapterSettingsTests.cs b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Services/MSTestAdapterSettingsTests.cs new file mode 100644 index 0000000000..dd74057afd --- /dev/null +++ b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Services/MSTestAdapterSettingsTests.cs @@ -0,0 +1,336 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace MSTestAdapter.PlatformServices.Tests.Services +{ + + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Xml; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + using TestUtilities; + + using Microsoft.VisualStudio.TestTools.UnitTesting; + using System.Reflection; + + [TestClass] + public class MSTestAdapterSettingsTests + { + [TestCleanup] + public void Cleanup() + { + MSTestSettingsProvider.Reset(); + } + + #region ResolveEnvironmentVariableAndReturnFullPathIfExist tests. + + [TestMethod] + public void ResolveEnvironmentVariableShouldResolvePathWhenPassedAbsolutePath() + { + string path = @"C:\unitTesting\..\MsTest\Adapter"; + string baseDirectory = null; + string expectedResult = @"C:\MsTest\Adapter"; + + var adapterSettings = new TestableMSTestAdapterSettings(); + adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; + + string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); + + Assert.IsNotNull(result); + Assert.AreEqual(string.Compare(result, expectedResult, true), 0); + } + + [TestMethod] + public void ResolveEnvironmentVariableShouldResolvePathWithAnEnvironmentVariable() + { + string path = @"%temp%\unitTesting\MsTest\Adapter"; + string baseDirectory = null; + string expectedResult = @"C:\foo\unitTesting\MsTest\Adapter"; + + var adapterSettings = new TestableMSTestAdapterSettings(); + adapterSettings.ExpandEnvironmentVariablesSetter = (str) => { return str.Replace("%temp%", "C:\\foo"); }; + adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; + + string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); + + Assert.IsNotNull(result); + Assert.AreEqual(string.Compare(result, expectedResult, true), 0); + } + + /* [TestMethod] + public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePathWithoutDot() + { + string path = @"MsTest\Adapter"; + string baseDirectory = @"C:\unitTesting"; + string expectedResult = @"C:\unitTesting\MsTest\Adapter"; + + var adapterSettings = new TestableMSTestAdapterSettings(); + adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; + + string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); + + Assert.IsNotNull(result); + Assert.AreEqual(string.Compare(result, expectedResult, true), 0); + } */ + + [TestMethod] + public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePathWithDot() + { + string path = @".\MsTest\Adapter"; + string baseDirectory = @"C:\unitTesting"; + string expectedResult = @"C:\unitTesting\MsTest\Adapter"; + + var adapterSettings = new TestableMSTestAdapterSettings(); + adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; + + string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); + + Assert.IsNotNull(result); + Assert.AreEqual(string.Compare(result, expectedResult, true), 0); + } + + /* [TestMethod] + public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePath() + { + //System.Diagnostics.Debugger.Launch(); + string path = @"\MsTest\Adapter"; + string baseDirectory = @"C:\unitTesting"; + + // instead of returning "C:\unitTesting\MsTest\Adapter", it will return "(Drive from where test is running):\MsTest\Adapter", + // because path is starting with "\" + // this is how Path.GetFullPath works + string currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); + string currentDrive = currentDirectory.Split('\\').First() + "\\"; + string expectedResult = Path.Combine(currentDrive, @"MsTest\Adapter"); + + var adapterSettings = new TestableMSTestAdapterSettings(); + adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; + + string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); + + Assert.IsNotNull(result); + Assert.AreEqual(string.Compare(result, expectedResult, true), 0); + } */ + + [TestMethod] + public void ResolveEnvironmentVariableShouldResolvePathWhenPassedNetworkPath() + { + string path = @"\\MsTest\Adapter"; + string baseDirectory = @"C:\unitTesting"; + + string expectedResult = path; + + var adapterSettings = new TestableMSTestAdapterSettings(); + adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; + + string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); + + Assert.IsNotNull(result); + Assert.AreEqual(string.Compare(result, expectedResult, true), 0); + } + + [TestMethod] + public void ResolveEnvironmentVariableShouldReturnFalseForInvalidPath() + { + string path = @"Z:\Program Files (x86)\MsTest\Adapter"; + string baseDirectory = @"C:\unitTesting"; + + string result = new TestableMSTestAdapterSettings().ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); + + Assert.IsNull(result); + } + + #endregion + + #region GetDirectoryListWithRecursiveProperty tests. + + [TestMethod] + public void GetDirectoryListWithRecursivePropertyShouldReadRunSettingCorrectly() + { + string baseDirectory = @"C:\unitTesting"; + + List expectedResult = new List(); + expectedResult.Add(new RecursiveDirectoryPath(@"C:\MsTest\Adapter", true)); + expectedResult.Add(new RecursiveDirectoryPath(@"C:\foo\unitTesting\MsTest\Adapter", false)); + + var adapterSettings = new TestableMSTestAdapterSettings(expectedResult); + adapterSettings.ExpandEnvironmentVariablesSetter = (str) => { return str.Replace("%temp%", "C:\\foo"); }; + adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; + + IList result = adapterSettings.GetDirectoryListWithRecursiveProperty(baseDirectory); + Assert.IsNotNull(result); + Assert.AreEqual(result.Count, 2); + + for (int i = 0; i < 2; i++) + { + Assert.AreEqual(string.Compare(result[i].DirectoryPath, expectedResult[i].DirectoryPath, StringComparison.OrdinalIgnoreCase), 0); + Assert.AreEqual(result[i].IncludeSubDirectories, expectedResult[i].IncludeSubDirectories); + } + } + + #endregion + + #region ToSettings tests. + + [TestMethod] + public void ToSettingsShouldNotThrowExceptionWhenRunSettingsXmlUnderTagMSTestv2IsWrong() + { + string runSettingxml = + @" + true + + + + + + true + false + "; + + StringReader stringReader = new StringReader(runSettingxml); + XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); + reader.Read(); + + MSTestAdapterSettings.ToSettings(reader); + } + + [TestMethod] + public void ToSettingsShouldThrowExceptionWhenRunSettingsXmlIsWrong() + { + string runSettingxml = + @" + + + + + + "; + + StringReader stringReader = new StringReader(runSettingxml); + XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); + reader.Read(); + + Action shouldThrowException = () => MSTestAdapterSettings.ToSettings(reader); + + ActionUtility.ActionShouldThrowExceptionOfType(shouldThrowException, typeof(SettingsException)); + } + + #endregion + + #region DeploymentEnabled tests. + + [TestMethod] + public void DeploymentEnabledIsByDefaultTrueWhenNotSpecified() + { + string runSettingxml = + @" + "; + StringReader stringReader = new StringReader(runSettingxml); + XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); + reader.Read(); + MSTestAdapterSettings adapterSettings = MSTestAdapterSettings.ToSettings(reader); + Assert.AreEqual(true, adapterSettings.DeploymentEnabled); + } + + [TestMethod] + public void DeploymentEnabledShouldBeConsumedFromRunSettingsWhenSpecified() + { + string runSettingxml = + @" + False + "; + StringReader stringReader = new StringReader(runSettingxml); + XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); + reader.Read(); + MSTestAdapterSettings adapterSettings = MSTestAdapterSettings.ToSettings(reader); + Assert.AreEqual(false, adapterSettings.DeploymentEnabled); + } + + #endregion + + #region DeployTestSourceDependencies tests + + [TestMethod] + public void DeployTestSourceDependenciesIsEnabledByDefault() + { + string runSettingxml = + @" + "; + StringReader stringReader = new StringReader(runSettingxml); + XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); + reader.Read(); + MSTestAdapterSettings adapterSettings = MSTestAdapterSettings.ToSettings(reader); + Assert.AreEqual(true, adapterSettings.DeployTestSourceDependencies); + } + + [TestMethod] + public void DeployTestSourceDependenciesWhenFalse() + { + string runSettingxml = + @" + False + "; + StringReader stringReader = new StringReader(runSettingxml); + XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); + reader.Read(); + MSTestAdapterSettings adapterSettings = MSTestAdapterSettings.ToSettings(reader); + Assert.AreEqual(false, adapterSettings.DeployTestSourceDependencies); + } + + [TestMethod] + public void DeployTestSourceDependenciesWhenTrue() + { + string runSettingxml = + @" + True + "; + StringReader stringReader = new StringReader(runSettingxml); + XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); + reader.Read(); + MSTestAdapterSettings adapterSettings = MSTestAdapterSettings.ToSettings(reader); + Assert.AreEqual(true, adapterSettings.DeployTestSourceDependencies); + } + + #endregion + } + + public class TestableMSTestAdapterSettings : MSTestAdapterSettings + { + public TestableMSTestAdapterSettings() + { + } + + public TestableMSTestAdapterSettings(List expectedResult) + { + this.SearchDirectories.AddRange(expectedResult); + } + + public Func DoesDirectoryExistSetter { get; set; } + + public Func ExpandEnvironmentVariablesSetter { get; set; } + + protected override bool DoesDirectoryExist(string path) + { + if (this.DoesDirectoryExistSetter == null) + { + return base.DoesDirectoryExist(path); + } + + return this.DoesDirectoryExistSetter(path); + } + + protected override string ExpandEnvironmentVariables(string path) + { + if (this.ExpandEnvironmentVariablesSetter == null) + { + return base.ExpandEnvironmentVariables(path); + } + + return this.ExpandEnvironmentVariablesSetter(path); + } + } +} diff --git a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/DeploymentItemUtilityNetCoreTests.cs b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/DeploymentItemUtilityNetCoreTests.cs new file mode 100644 index 0000000000..a56182be29 --- /dev/null +++ b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/DeploymentItemUtilityNetCoreTests.cs @@ -0,0 +1,461 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace MSTestAdapter.PlatformServices.Tests.Utilities +{ + using System.Collections.Generic; + using System.Linq; + using System.Reflection; + + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + + using Moq; + + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class DeploymentItemUtilityTests + { + internal static readonly TestProperty DeploymentItemsProperty = TestProperty.Register( + "MSTestDiscoverer.DeploymentItems", + "DeploymentItems", + typeof(KeyValuePair[]), + TestPropertyAttributes.Hidden, + typeof(TestCase)); + + private Mock mockReflectionUtility; + private DeploymentItemUtility deploymentItemUtility; + private ICollection warnings; + + private string defaultDeploymentItemPath = @"c:\temp"; + private string defaultDeploymentItemOutputDirectory = "out"; + + [TestInitialize] + public void TestInit() + { + this.mockReflectionUtility = new Mock(); + this.deploymentItemUtility = new DeploymentItemUtility(this.mockReflectionUtility.Object); + this.warnings = new List(); + } + + #region GetClassLevelDeploymentItems tests + + [TestMethod] + public void GetClassLevelDeploymentItemsShouldReturnEmptyListWhenNoDeploymentItems() + { + var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems(typeof(DeploymentItemUtilityTests), this.warnings); + + Assert.IsNotNull(deploymentItems); + Assert.AreEqual(0, deploymentItems.Count); + } + + [TestMethod] + public void GetClassLevelDeploymentItemsShouldReturnADeploymentItem() + { + var kvpArray = new[] + { + new KeyValuePair( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory) + }; + this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), kvpArray); + + var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems(typeof(DeploymentItemUtilityTests), this.warnings); + var expectedDeploymentItems = new DeploymentItem[] + { + new DeploymentItem( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory) + }; + CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); + } + + [TestMethod] + public void GetClassLevelDeploymentItemsShouldReturnMoreThanOneDeploymentItems() + { + var deploymentItemAttributes = new[] + { + new KeyValuePair( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory), + new KeyValuePair( + this.defaultDeploymentItemPath + "\\temp2", + this.defaultDeploymentItemOutputDirectory) + }; + this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), deploymentItemAttributes); + + var deploymentItems = + this.deploymentItemUtility.GetClassLevelDeploymentItems( + typeof(DeploymentItemUtilityTests), + this.warnings); + + var expectedDeploymentItems = new DeploymentItem[] + { + new DeploymentItem( + deploymentItemAttributes[0].Key, + deploymentItemAttributes[0].Value), + new DeploymentItem( + deploymentItemAttributes[1].Key, + deploymentItemAttributes[1].Value) + }; + + CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); + } + + [TestMethod] + public void GetClassLevelDeploymentItemsShouldNotReturnDuplicateDeploymentItemEntries() + { + var deploymentItemAttributes = new[] + { + new KeyValuePair( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory), + new KeyValuePair( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory) + }; + this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), deploymentItemAttributes); + + var deploymentItems = + this.deploymentItemUtility.GetClassLevelDeploymentItems( + typeof(DeploymentItemUtilityTests), + this.warnings); + + var expectedDeploymentItems = new[] + { + new DeploymentItem( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory) + }; + + CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); + } + + [TestMethod] + public void GetClassLevelDeploymentItemsShouldReportWarningsForInvalidDeploymentItems() + { + var deploymentItemAttributes = new[] + { + new KeyValuePair( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory), + new KeyValuePair( + null, + this.defaultDeploymentItemOutputDirectory) + }; + this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), deploymentItemAttributes); + + var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems(typeof(DeploymentItemUtilityTests), this.warnings); + + var expectedDeploymentItems = new DeploymentItem[] + { + new DeploymentItem( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory) + }; + + CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); + Assert.AreEqual(1, this.warnings.Count); + StringAssert.Contains(this.warnings.ToArray()[0], Resource.DeploymentItemPathCannotBeNullOrEmpty); + } + +#endregion + + #region GetDeploymentItems tests + + [TestMethod] + public void GetDeploymentItemsShouldReturnNullOnNoDeploymentItems() + { + Assert.IsNull(this.deploymentItemUtility.GetDeploymentItems( + typeof(DeploymentItemUtilityTests).GetMethod("GetDeploymentItemsShouldReturnNullOnNoDeploymentItems"), + null, + this.warnings)); + } + + [TestMethod] + public void GetDeploymentItemsShouldReturnMethodLevelDeploymentItemsOnly() + { + var deploymentItemAttributes = new[] + { + new KeyValuePair( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory), + new KeyValuePair( + this.defaultDeploymentItemPath + "\\temp2", + this.defaultDeploymentItemOutputDirectory) + }; + var memberInfo = + typeof(DeploymentItemUtilityTests).GetMethod( + "GetDeploymentItemsShouldReturnNullOnNoDeploymentItems"); + + this.SetupDeploymentItems(memberInfo, deploymentItemAttributes); + + var deploymentItems = this.deploymentItemUtility.GetDeploymentItems( + memberInfo, + null, + this.warnings); + + CollectionAssert.AreEqual(deploymentItemAttributes, deploymentItems.ToArray()); + } + + [TestMethod] + public void GetDeploymentItemsShouldReturnClassLevelDeploymentItemsOnly() + { + // Arrange. + var classLevelDeploymentItems = new DeploymentItem[] + { + new DeploymentItem( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory), + new DeploymentItem( + this.defaultDeploymentItemPath + "\\temp2", + this.defaultDeploymentItemOutputDirectory) + }; + + // Act. + var deploymentItems = this.deploymentItemUtility.GetDeploymentItems( + typeof(DeploymentItemUtilityTests).GetMethod("GetDeploymentItemsShouldReturnNullOnNoDeploymentItems"), + classLevelDeploymentItems, + this.warnings); + + // Assert. + var expectedDeploymentItems = new[] + { + new KeyValuePair( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory), + new KeyValuePair( + this.defaultDeploymentItemPath + "\\temp2", + this.defaultDeploymentItemOutputDirectory) + }; + + CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); + } + + [TestMethod] + public void GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItems() + { + // Arrange. + var deploymentItemAttributes = new[] + { + new KeyValuePair( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory) + }; + var memberInfo = + typeof(DeploymentItemUtilityTests).GetMethod( + "GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItems"); + this.SetupDeploymentItems(memberInfo, deploymentItemAttributes); + + var classLevelDeploymentItems = new[] + { + new DeploymentItem( + this.defaultDeploymentItemPath + "\\temp2", + this.defaultDeploymentItemOutputDirectory) + }; + + // Act. + var deploymentItems = this.deploymentItemUtility.GetDeploymentItems( + memberInfo, + classLevelDeploymentItems, + this.warnings); + + // Assert. + var expectedDeploymentItems = new KeyValuePair[] + { + new KeyValuePair( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory), + new KeyValuePair( + this.defaultDeploymentItemPath + "\\temp2", + this.defaultDeploymentItemOutputDirectory) + }; + + CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); + } + + [TestMethod] + public void GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItemsWithoutDuplicates() + { + // Arrange. + var deploymentItemAttributes = new[] + { + new KeyValuePair( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory), + new KeyValuePair( + this.defaultDeploymentItemPath + "\\temp2", + this.defaultDeploymentItemOutputDirectory) + }; + var memberInfo = + typeof(DeploymentItemUtilityTests).GetMethod( + "GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItems"); + this.SetupDeploymentItems(memberInfo, deploymentItemAttributes); + + var classLevelDeploymentItems = new DeploymentItem[] + { + new DeploymentItem( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory), + new DeploymentItem( + this.defaultDeploymentItemPath + "\\temp1", + this.defaultDeploymentItemOutputDirectory) + }; + + // Act. + var deploymentItems = this.deploymentItemUtility.GetDeploymentItems( + memberInfo, + classLevelDeploymentItems, + this.warnings); + + // Assert. + var expectedDeploymentItems = new KeyValuePair[] + { + new KeyValuePair( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory), + new KeyValuePair( + this.defaultDeploymentItemPath + "\\temp2", + this.defaultDeploymentItemOutputDirectory), + new KeyValuePair( + this.defaultDeploymentItemPath + "\\temp1", + this.defaultDeploymentItemOutputDirectory) + }; + + CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); + } + + #endregion + + #region IsValidDeploymentItem tests + + [TestMethod] + public void IsValidDeploymentItemShouldReportWarningIfSourcePathIsNull() + { + string warning; + Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(null, this.defaultDeploymentItemOutputDirectory, out warning)); + + StringAssert.Contains(Resource.DeploymentItemPathCannotBeNullOrEmpty, warning); + } + + [TestMethod] + public void IsValidDeploymentItemShouldReportWarningIfSourcePathIsEmpty() + { + string warning; + Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(string.Empty, this.defaultDeploymentItemOutputDirectory, out warning)); + + StringAssert.Contains(Resource.DeploymentItemPathCannotBeNullOrEmpty, warning); + } + + [TestMethod] + public void IsValidDeploymentItemShouldReportWarningIfDeploymentOutputDirectoryIsNull() + { + string warning; + Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(this.defaultDeploymentItemPath, null, out warning)); + + StringAssert.Contains(Resource.DeploymentItemOutputDirectoryCannotBeNull, warning); + } + + [TestMethod] + public void IsValidDeploymentItemShouldReportWarningIfSourcePathHasInvalidCharacters() + { + string warning; + Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem("C:<>", this.defaultDeploymentItemOutputDirectory, out warning)); + + StringAssert.Contains( + string.Format( + Resource.DeploymentItemContainsInvalidCharacters, + "C:<>", + this.defaultDeploymentItemOutputDirectory), + warning); + } + + [TestMethod] + public void IsValidDeploymentItemShouldReportWarningIfOutputDirectoryHasInvalidCharacters() + { + string warning; + Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(this.defaultDeploymentItemPath, "<>", out warning)); + + StringAssert.Contains( + string.Format( + Resource.DeploymentItemContainsInvalidCharacters, + this.defaultDeploymentItemPath, + "<>"), + warning); + } + + [TestMethod] + public void IsValidDeploymentItemShouldReportWarningIfDeploymentOutputDirectoryIsRooted() + { + string warning; + Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(this.defaultDeploymentItemPath, "C:\\temp", out warning)); + + StringAssert.Contains( + string.Format( + Resource.DeploymentItemOutputDirectoryMustBeRelative, + "C:\\temp"), + warning); + } + + [TestMethod] + public void IsValidDeploymentItemShouldReturnTrueForAValidDeploymentItem() + { + string warning; + Assert.IsTrue(this.deploymentItemUtility.IsValidDeploymentItem(this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory, out warning)); + + Assert.IsTrue(string.Empty.Equals(warning)); + } + #endregion + + #region HasDeployItems tests + + [TestMethod] + public void HasDeployItemsShouldReturnFalseForNoDeploymentItems() + { + TestCase testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A"); + testCase.SetPropertyValue(DeploymentItemsProperty, null); + + Assert.IsFalse(this.deploymentItemUtility.HasDeploymentItems(testCase)); + } + + [TestMethod] + public void HasDeployItemsShouldReturnTrueWhenDeploymentItemsArePresent() + { + TestCase testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A"); + var kvpArray = new[] + { + new KeyValuePair( + this.defaultDeploymentItemPath, + this.defaultDeploymentItemOutputDirectory) + }; + testCase.SetPropertyValue(DeploymentItemsProperty, kvpArray); + + Assert.IsTrue(this.deploymentItemUtility.HasDeploymentItems(testCase)); + } + + #endregion + + #region private methods + + private void SetupDeploymentItems(MemberInfo memberInfo, KeyValuePair[] deploymentItems) + { + var deploymentItemAttributes = new List(); + + foreach (var deploymentItem in deploymentItems) + { + deploymentItemAttributes.Add(new DeploymentItemAttribute(deploymentItem.Key, deploymentItem.Value)); + } + + this.mockReflectionUtility.Setup( + ru => + ru.GetCustomAttributes( + memberInfo, + typeof(DeploymentItemAttribute))).Returns((object[])deploymentItemAttributes.ToArray()); + } + + #endregion + } +} diff --git a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/DeploymentUtilityNetCoreTests.cs b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/DeploymentUtilityNetCoreTests.cs new file mode 100644 index 0000000000..1113ca745d --- /dev/null +++ b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/DeploymentUtilityNetCoreTests.cs @@ -0,0 +1,338 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace MSTestAdapter.PlatformServices.Tests.Utilities +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Reflection; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Moq; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class DeploymentUtilityTests + { + private const string TestRunDirectory = "C:\\temp\\testRunDirectory"; + private const string RootDeploymentDirectory = "C:\\temp\\testRunDirectory\\Deploy"; + private const string DefaultDeploymentItemPath = @"c:\temp"; + private const string DefaultDeploymentItemOutputDirectory = "out"; + + private Mock mockReflectionUtility; + private Mock mockFileUtility; + + private Mock mockAssemblyUtility; + + private DeploymentUtility deploymentUtility; + + private Mock mockRunContext; + private Mock mocktestExecutionRecorder; + + private IList warnings; + + [TestInitialize] + public void TestInit() + { + this.mockReflectionUtility = new Mock(); + this.mockFileUtility = new Mock(); + this.mockAssemblyUtility = new Mock(); + this.warnings = new List(); + + this.deploymentUtility = new DeploymentUtility( + new DeploymentItemUtility(this.mockReflectionUtility.Object), + this.mockAssemblyUtility.Object, + this.mockFileUtility.Object); + + this.mockRunContext = new Mock(); + this.mocktestExecutionRecorder = new Mock(); + } + + #region CreateDeploymentDirectories tests + + [TestMethod] + public void CreateDeploymentDirectoriesShouldCreateDeploymentDirectoryFromRunContext() + { + // Setup mocks + this.mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(TestRunDirectory); + this.mockFileUtility.Setup(fu => fu.GetNextIterationDirectoryName(TestRunDirectory, It.IsAny())) + .Returns(RootDeploymentDirectory); + + // Act. + this.deploymentUtility.CreateDeploymentDirectories(this.mockRunContext.Object); + + // Assert. + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(RootDeploymentDirectory), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix)), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentOutDirectorySuffix)), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix), Environment.MachineName)), Times.Once); + } + + [TestMethod] + public void CreateDeploymentDirectoriesShouldCreateDefaultDeploymentDirectoryIfTestRunDirectoryIsNull() + { + // Setup mocks + this.mockRunContext.Setup(rc => rc.TestRunDirectory).Returns((string)null); + this.mockFileUtility.Setup(fu => fu.GetNextIterationDirectoryName(It.Is(s => s.Contains(TestRunDirectories.DefaultDeploymentRootDirectory)), It.IsAny())) + .Returns(RootDeploymentDirectory); + + // Act. + this.deploymentUtility.CreateDeploymentDirectories(this.mockRunContext.Object); + + // Assert. + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(RootDeploymentDirectory), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix)), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentOutDirectorySuffix)), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix), Environment.MachineName)), Times.Once); + } + + [TestMethod] + public void CreateDeploymentDirectoriesShouldCreateDefaultDeploymentDirectoryIfRunContextIsNull() + { + // Setup mocks + this.mockFileUtility.Setup(fu => fu.GetNextIterationDirectoryName(It.Is(s => s.Contains(TestRunDirectories.DefaultDeploymentRootDirectory)), It.IsAny())) + .Returns(RootDeploymentDirectory); + + // Act. + this.deploymentUtility.CreateDeploymentDirectories(null); + + // Assert. + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(RootDeploymentDirectory), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix)), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentOutDirectorySuffix)), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix), Environment.MachineName)), Times.Once); + } + + #endregion + + #region Deploy tests + + [TestMethod] + public void DeployShouldReturnFalseWhenNoDeploymentItemsOnTestCase() + { + var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A"); + testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, null); + var testRunDirectories = new TestRunDirectories(RootDeploymentDirectory); + + this.mockFileUtility.Setup(fu => fu.DoesDirectoryExist(It.Is(s => !(s.EndsWith(".dll") || s.EndsWith(".config"))))).Returns(true); + this.mockFileUtility.Setup(fu => fu.DoesFileExist(It.IsAny())).Returns(true); + + Assert.IsFalse( + this.deploymentUtility.Deploy( + new List { testCase }, + testCase.Source, + this.mockRunContext.Object, + this.mocktestExecutionRecorder.Object, + testRunDirectories)); + } + + [TestMethod] + public void DeployShouldNotDeployIfOutputDirectoryIsInvalid() + { + TestRunDirectories testRunDirectories; + var assemblyFullPath = Assembly.GetEntryAssembly().Location; + var deploymentItemPath = "C:\\temp\\sample.dll"; + var deploymentItemOutputDirectory = "..\\..\\out"; + + var testCase = this.GetTestCaseAndTestRunDirectories(deploymentItemPath, deploymentItemOutputDirectory, out testRunDirectories); + + // Setup mocks. + this.mockFileUtility.Setup(fu => fu.DoesDirectoryExist(It.Is(s => !(s.EndsWith(".dll") || s.EndsWith(".config"))))).Returns(true); + this.mockFileUtility.Setup(fu => fu.DoesFileExist(It.IsAny())).Returns(true); + + // Act. + Assert.IsTrue( + this.deploymentUtility.Deploy( + new List { testCase }, + testCase.Source, + this.mockRunContext.Object, + this.mocktestExecutionRecorder.Object, + testRunDirectories)); + + // Assert. + string warning; + + this.mockFileUtility.Verify( + fu => + fu.CopyFileOverwrite( + It.Is(s => s.Contains(deploymentItemPath)), + It.IsAny(), + out warning), + Times.Never); + + // Verify the warning. + this.mocktestExecutionRecorder.Verify( + ter => + ter.SendMessage( + TestMessageLevel.Warning, + string.Format( + Resource.DeploymentErrorBadDeploymentItem, + deploymentItemPath, + deploymentItemOutputDirectory)), + Times.Once); + } + + [TestMethod] + public void DeployShouldDeployContentsOfADirectoryIfSpecified() + { + TestRunDirectories testRunDirectories; + var assemblyFullPath = Assembly.GetEntryAssembly().Location; + + var testCase = this.GetTestCaseAndTestRunDirectories(DefaultDeploymentItemPath, DefaultDeploymentItemOutputDirectory, out testRunDirectories); + var content1 = Path.Combine(DefaultDeploymentItemPath, "directoryContents.dll"); + var directoryContentFiles = new List { content1 }; + + // Setup mocks. + this.mockFileUtility.Setup(fu => fu.DoesDirectoryExist(It.Is(s => !(s.EndsWith(".dll") || s.EndsWith(".config"))))).Returns(true); + this.mockFileUtility.Setup(fu => fu.DoesFileExist(It.IsAny())).Returns(true); + this.mockFileUtility.Setup( + fu => fu.AddFilesFromDirectory(DefaultDeploymentItemPath, It.IsAny())).Returns(directoryContentFiles); + this.mockFileUtility.Setup( + fu => fu.AddFilesFromDirectory(DefaultDeploymentItemPath, It.IsAny>(), It.IsAny())).Returns(directoryContentFiles); + + // Act. + Assert.IsTrue( + this.deploymentUtility.Deploy( + new List { testCase }, + testCase.Source, + this.mockRunContext.Object, + this.mocktestExecutionRecorder.Object, + testRunDirectories)); + + // Assert. + string warning; + + this.mockFileUtility.Verify( + fu => + fu.CopyFileOverwrite( + It.Is(s => s.Contains(content1)), + It.IsAny(), + out warning), + Times.Once); + } + + /* [TestMethod] + public void DeployShouldDeployPdbWithSourceIfPdbFileIsPresentInSourceDirectory() + { + TestRunDirectories testRunDirectories; + var testCase = this.GetTestCaseAndTestRunDirectories(DefaultDeploymentItemPath, DefaultDeploymentItemOutputDirectory, out testRunDirectories); + + // Setup mocks. + this.mockFileUtility.Setup(fu => fu.DoesDirectoryExist(It.Is(s => !s.EndsWith(".dll")))).Returns(true); + this.mockFileUtility.Setup(fu => fu.DoesFileExist(It.IsAny())).Returns(true); + string warning; + this.mockFileUtility.Setup(fu => fu.CopyFileOverwrite(It.IsAny(), It.IsAny(), out warning)) + .Returns( + (string x, string y, string z) => + { + z = string.Empty; + return y; + }); + + // Act. + Assert.IsTrue( + this.deploymentUtility.Deploy( + new List { testCase }, + testCase.Source, + this.mockRunContext.Object, + this.mocktestExecutionRecorder.Object, + testRunDirectories)); + + // Assert. + var sourceFile = Assembly.GetEntryAssembly().GetName().Name + ".dll"; + var pdbFile = Assembly.GetEntryAssembly().GetName().Name + ".pdb"; + this.mockFileUtility.Verify( + fu => + fu.CopyFileOverwrite( + It.Is(s => s.Contains(sourceFile)), + Path.Combine(testRunDirectories.OutDirectory, sourceFile), + out warning), + Times.Once); + this.mockFileUtility.Verify( + fu => + fu.CopyFileOverwrite( + It.Is(s => s.Contains(pdbFile)), + Path.Combine(testRunDirectories.OutDirectory, pdbFile), + out warning), + Times.Once); + } + + [TestMethod] + public void DeployShouldNotDeployPdbFileOfAssemblyIfPdbFileIsNotPresentInAssemblyDirectory() + { + var dependencyFile = "C:\\temp\\dependency.dll"; + + // Path for pdb file of dependent assembly if pdb file is present. + var pdbFile = Path.ChangeExtension(dependencyFile, "pdb"); + + TestRunDirectories testRunDirectories; + var testCase = this.GetTestCaseAndTestRunDirectories(DefaultDeploymentItemPath, DefaultDeploymentItemOutputDirectory, out testRunDirectories); + + // Setup mocks. + this.mockFileUtility.Setup(fu => fu.DoesDirectoryExist(It.Is(s => !s.EndsWith(".dll")))).Returns(true); + this.mockFileUtility.Setup(fu => fu.DoesFileExist(It.IsAny())).Returns(true); + string warning; + this.mockFileUtility.Setup(fu => fu.CopyFileOverwrite(It.IsAny(), It.IsAny(), out warning)) + .Returns( + (string x, string y, string z) => + { + z = string.Empty; + return y; + }); + + // Act. + Assert.IsTrue( + this.deploymentUtility.Deploy( + new List { testCase }, + testCase.Source, + this.mockRunContext.Object, + this.mocktestExecutionRecorder.Object, + testRunDirectories)); + + // Assert. + this.mockFileUtility.Verify( + fu => + fu.CopyFileOverwrite( + It.Is(s => s.Contains(dependencyFile)), + Path.Combine(testRunDirectories.OutDirectory, Path.GetFileName(dependencyFile)), + out warning), + Times.Once); + + this.mockFileUtility.Verify( + fu => + fu.CopyFileOverwrite( + It.Is(s => s.Contains(pdbFile)), + Path.Combine(testRunDirectories.OutDirectory, Path.GetFileName(pdbFile)), + out warning), + Times.Never); + } */ + + #endregion + + #region private methods + + private TestCase GetTestCaseAndTestRunDirectories(string deploymentItemPath, string defaultDeploymentItemOutputDirectoryout, out TestRunDirectories testRunDirectories) + { + var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), Assembly.GetEntryAssembly().Location); + var kvpArray = new[] + { + new KeyValuePair( + deploymentItemPath, + defaultDeploymentItemOutputDirectoryout) + }; + testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, kvpArray); + var currentExecutingFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); + + testRunDirectories = new TestRunDirectories(currentExecutingFolder); + + return testCase; + } + + #endregion + } +} diff --git a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/ReflectionUtilityTestsNetCore.cs b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/ReflectionUtilityTestsNetCore.cs new file mode 100644 index 0000000000..83b3e49b46 --- /dev/null +++ b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/ReflectionUtilityTestsNetCore.cs @@ -0,0 +1,276 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace MSTestAdapter.PlatformServices.Tests.Utilities +{ + using System; + using System.Collections.Generic; + using System.Reflection; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class ReflectionUtilityTests + { + private ReflectionUtility reflectionUtility; + + public ReflectionUtilityTests() + { + this.reflectionUtility = new ReflectionUtility(); + } + + [TestMethod] + public void GetCustomAttributesShouldReturnAllAttributes() + { + var minfo = typeof(DummyBaseTestClass).GetMethod("DummyVTestMethod1"); + + var attribs = this.reflectionUtility.GetCustomAttributes(minfo, false); + + Assert.IsNotNull(attribs); + Assert.AreEqual(2, attribs.Length); + + var expectedAttribs = new string[] { "DummyA : base", "DummySingleA : base" }; + CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); + } + + [TestMethod] + public void GetCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance() + { + var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1"); + + var attribs = this.reflectionUtility.GetCustomAttributes(minfo, false); + + Assert.IsNotNull(attribs); + Assert.AreEqual(2, attribs.Length); + + var expectedAttribs = new string[] { "DummyA : derived", "DummySingleA : derived" }; + CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); + } + + [TestMethod] + public void GetCustomAttributesShouldReturnAllAttributesWithBaseInheritance() + { + var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1"); + + var attribs = this.reflectionUtility.GetCustomAttributes(minfo, true); + + Assert.IsNotNull(attribs); + Assert.AreEqual(3, attribs.Length); + + // Notice that the DummySingleA on the base method does not show up since it can only be defined once. + var expectedAttribs = new string[] { "DummyA : derived", "DummySingleA : derived", "DummyA : base", }; + CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); + } + + [TestMethod] + public void GetCustomAttributesOnTypeShouldReturnAllAttributes() + { + var tinfo = typeof(DummyBaseTestClass).GetTypeInfo(); + + var attribs = this.reflectionUtility.GetCustomAttributes(tinfo, false); + + Assert.IsNotNull(attribs); + Assert.AreEqual(1, attribs.Length); + + var expectedAttribs = new string[] { "DummyA : ba" }; + CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); + } + + [TestMethod] + public void GetCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBaseInheritance() + { + var tinfo = typeof(DummyTestClass).GetTypeInfo(); + + var attribs = this.reflectionUtility.GetCustomAttributes(tinfo, false); + + Assert.IsNotNull(attribs); + Assert.AreEqual(1, attribs.Length); + + var expectedAttribs = new string[] { "DummyA : a" }; + CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); + } + + [TestMethod] + public void GetCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritance() + { + var minfo = typeof(DummyTestClass).GetTypeInfo(); + + var attribs = this.reflectionUtility.GetCustomAttributes(minfo, true); + + Assert.IsNotNull(attribs); + Assert.AreEqual(2, attribs.Length); + + var expectedAttribs = new string[] { "DummyA : a", "DummyA : ba" }; + CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); + } + + [TestMethod] + public void GetSpecificCustomAttributesShouldReturnAllAttributes() + { + var minfo = typeof(DummyBaseTestClass).GetMethod("DummyVTestMethod1"); + + var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), false); + + Assert.IsNotNull(attribs); + Assert.AreEqual(1, attribs.Length); + + var expectedAttribs = new string[] { "DummyA : base" }; + CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); + } + + [TestMethod] + public void GetSpecificCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance() + { + var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1"); + + var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), false); + + Assert.IsNotNull(attribs); + Assert.AreEqual(1, attribs.Length); + + var expectedAttribs = new string[] { "DummyA : derived" }; + CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); + } + + [TestMethod] + public void GetSpecificCustomAttributesShouldReturnAllAttributesWithBaseInheritance() + { + var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1"); + + var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), true); + + Assert.IsNotNull(attribs); + Assert.AreEqual(2, attribs.Length); + + var expectedAttribs = new string[] { "DummyA : derived", "DummyA : base", }; + CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); + } + + [TestMethod] + public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributes() + { + var tinfo = typeof(DummyBaseTestClass).GetTypeInfo(); + + var attribs = this.reflectionUtility.GetCustomAttributes(tinfo, typeof(DummyAAttribute), false); + + Assert.IsNotNull(attribs); + Assert.AreEqual(1, attribs.Length); + + var expectedAttribs = new string[] { "DummyA : ba" }; + CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); + } + + [TestMethod] + public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBaseInheritance() + { + var tinfo = typeof(DummyTestClass).GetTypeInfo(); + + var attribs = this.reflectionUtility.GetCustomAttributes(tinfo, typeof(DummyAAttribute), false); + + Assert.IsNotNull(attribs); + Assert.AreEqual(1, attribs.Length); + + var expectedAttribs = new string[] { "DummyA : a" }; + CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); + } + + [TestMethod] + public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritance() + { + var minfo = typeof(DummyTestClass).GetTypeInfo(); + + var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), true); + + Assert.IsNotNull(attribs); + Assert.AreEqual(2, attribs.Length); + + var expectedAttribs = new string[] { "DummyA : a", "DummyA : ba" }; + CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); + } + + [TestMethod] + public void GetSpecificCustomAttributesOnAssemblyShouldReturnAllAttributes() + { + var asm = typeof(DummyTestClass).GetTypeInfo().Assembly; + + var attribs = this.reflectionUtility.GetCustomAttributes(asm, typeof(DummyAAttribute)); + + Assert.IsNotNull(attribs); + Assert.AreEqual(2, attribs.Length); + + var expectedAttribs = new string[] { "DummyA : a1", "DummyA : a2" }; + CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); + } + + internal static string[] GetAttributeValuePairs(object[] attributes) + { + var attribValuePairs = new List(); + foreach (var attrib in attributes) + { + if (attrib is DummySingleAAttribute) + { + var a = attrib as DummySingleAAttribute; + attribValuePairs.Add("DummySingleA : " + a.Value); + } + else if (attrib is DummyAAttribute) + { + var a = attrib as DummyAAttribute; + attribValuePairs.Add("DummyA : " + a.Value); + } + } + + return attribValuePairs.ToArray(); + } + + [DummyA("ba")] + public class DummyBaseTestClass + { + [DummyA("base")] + [DummySingleA("base")] + public virtual void DummyVTestMethod1() + { + } + + public void DummyBTestMethod2() + { + } + } + + [DummyA("a")] + public class DummyTestClass : DummyBaseTestClass + { + [DummyA("derived")] + [DummySingleA("derived")] + public override void DummyVTestMethod1() + { + } + + [DummySingleA("derived")] + public void DummyTestMethod2() + { + } + } + + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class DummyAAttribute : Attribute + { + public DummyAAttribute(string foo) + { + this.Value = foo; + } + + public string Value { get; set; } + } + + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = false)] + public class DummySingleAAttribute : Attribute + { + public DummySingleAAttribute(string foo) + { + this.Value = foo; + } + + public string Value { get; set; } + } + } +} diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/DeploymentItemTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs similarity index 95% rename from test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/DeploymentItemTests.cs rename to test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs index aa2be3801f..36acbd7f47 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/DeploymentItemTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs @@ -1,16 +1,21 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Deployment +namespace MSTestAdapter.PlatformServices.Tests.Deployment { +#if NETCOREAPP1_0 + using Microsoft.VisualStudio.TestTools.UnitTesting; +#else extern alias FrameworkV1; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; - using Assert = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.Assert; using TestClass = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; using TestMethod = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; +#endif + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; + +#pragma warning disable SA1649 // File name must match first type name [TestClass] public class DeploymentItemTests diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/TestRunDirectoriesTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs similarity index 83% rename from test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/TestRunDirectoriesTests.cs rename to test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs index fa7eaaac33..19672ba589 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Deployment/TestRunDirectoriesTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs @@ -1,18 +1,22 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Deployment +namespace MSTestAdapter.PlatformServices.Tests.Deployment { +#if NETCOREAPP1_0 + using Microsoft.VisualStudio.TestTools.UnitTesting; +#else extern alias FrameworkV1; + using Assert = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.Assert; + using TestClass = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; + using TestMethod = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; +#endif using System; using System.IO; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; - using Assert = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.Assert; - using TestClass = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; - using TestMethod = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; +#pragma warning disable SA1649 // File name must match first type name [TestClass] public class TestRunDirectoriesTests diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Extensions/ExceptionExtensionsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs similarity index 87% rename from test/UnitTests/PlatformServices.Desktop.Unit.Tests/Extensions/ExceptionExtensionsTests.cs rename to test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs index 987ce0053f..bc53bdb8df 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Extensions/ExceptionExtensionsTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs @@ -1,17 +1,22 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Extensions +namespace MSTestAdapter.PlatformServices.Tests.Extensions { +#if NETCOREAPP1_0 + using Microsoft.VisualStudio.TestTools.UnitTesting; +#else extern alias FrameworkV1; + using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; + using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; + using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; +#endif using System; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; - using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; - using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; - using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; +#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName [TestClass] public class ExceptionExtensionsTests diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/FileUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs similarity index 97% rename from test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/FileUtilityTests.cs rename to test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs index 45efa6f766..9b5262647b 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/FileUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs @@ -1,20 +1,27 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Utilities +namespace MSTestAdapter.PlatformServices.Tests.Utilities { +#if NETCOREAPP1_0 + using Microsoft.VisualStudio.TestTools.UnitTesting; +#else extern alias FrameworkV1; - using System; - using System.IO; - using System.Linq; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; - using Moq; using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert; using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute; using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; +#endif + + using System; + using System.IO; + using System.Linq; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; + using Moq; + +#pragma warning disable SA1649 // File name must match first type name [TestClass] public class FileUtilityTests @@ -42,7 +49,7 @@ public void ReplaceInvalidFileNameCharactersShouldReplaceInvalidChars() Assert.AreEqual("galaxy__far_far_away", this.fileUtility.Object.ReplaceInvalidFileNameCharacters(fileName)); } - #region AddFilesFromDirectory tests +#region AddFilesFromDirectory tests [TestMethod] public void AddFilesInADirectoryShouldReturnAllTopLevelFilesInADirectory() @@ -201,6 +208,6 @@ private void SetupMockFileAPIs(string[] files) }); } - #endregion +#endregion } } diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs index 04704db378..e1a2b5ee4b 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs @@ -21,13 +21,13 @@ namespace MSTestAdapter.PlatformServices.Tests.Services [TestClass] public class SettingsProviderTests { - [TestMethod] + /* [TestMethod] public void GetPropertiesShouldReturnEmptyDictionary() { MSTestSettingsProvider settings = new MSTestSettingsProvider(); Assert.AreEqual(0, settings.GetProperties(It.IsAny()).Count); - } + } */ } #pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName From cfa90b8fbf5380c5e7e615ae04ad579973d8e29e Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Mon, 4 Mar 2019 16:02:54 +0530 Subject: [PATCH 05/24] PR comments --- .../PlatformServices.Desktop.csproj | 28 +- .../RecursiveDirectoryPathDesktop.cs | 50 ---- .../Services/DesktopTestDeployment.cs | 230 -------------- .../Services/MSTestSettingsProvider.cs | 61 ---- ...tyDesktop.cs => DesktopAssemblyUtility.cs} | 0 ...Desktop.cs => DesktopDeploymentUtility.cs} | 280 ++++-------------- ...Desktop.cs => DesktopReflectionUtility.cs} | 0 .../PlatformServices.NetCore.csproj | 14 +- .../Utilities/DeploymentUtilityNetCore.cs | 200 ------------- ...tyNetCore.cs => NetCoreAssemblyUtility.cs} | 0 .../Utilities/NetCoreDeploymentUtility.cs | 78 +++++ ...NetCore.cs => NetCoreReflectionUtility.cs} | 6 +- .../Utilities/RecursiveDirectoryPath.cs | 61 ---- .../Services/ns10MSTestSettingsProvider.cs} | 0 ...s.cs => ns10TestContextPropertyStrings.cs} | 0 .../Utilities/ns10Validate.cs} | 0 .../ns10RecursiveDirectoryPath.cs} | 0 .../Services/ns13TestDeployment.cs | 31 +- .../Utilities/ns13DeploymentUtilityBase.cs | 173 ++++++++++- 19 files changed, 347 insertions(+), 865 deletions(-) delete mode 100644 src/Adapter/PlatformServices.Desktop/RecursiveDirectoryPathDesktop.cs delete mode 100644 src/Adapter/PlatformServices.Desktop/Services/DesktopTestDeployment.cs delete mode 100644 src/Adapter/PlatformServices.Desktop/Services/MSTestSettingsProvider.cs rename src/Adapter/PlatformServices.Desktop/Utilities/{AssemblyUtilityDesktop.cs => DesktopAssemblyUtility.cs} (100%) rename src/Adapter/PlatformServices.Desktop/Utilities/{DeploymentUtilityDesktop.cs => DesktopDeploymentUtility.cs} (55%) rename src/Adapter/PlatformServices.Desktop/Utilities/{ReflectionUtilityDesktop.cs => DesktopReflectionUtility.cs} (100%) delete mode 100644 src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtilityNetCore.cs rename src/Adapter/PlatformServices.NetCore/Utilities/{AssemblyUtilityNetCore.cs => NetCoreAssemblyUtility.cs} (100%) create mode 100644 src/Adapter/PlatformServices.NetCore/Utilities/NetCoreDeploymentUtility.cs rename src/Adapter/PlatformServices.NetCore/Utilities/{ReflectionUtilityNetCore.cs => NetCoreReflectionUtility.cs} (91%) delete mode 100644 src/Adapter/PlatformServices.NetCore/Utilities/RecursiveDirectoryPath.cs rename src/Adapter/PlatformServices.Shared/{netstandard1.3/Services/ns13SettingsProvider.cs => netstandard1.0/Services/ns10MSTestSettingsProvider.cs} (100%) rename src/Adapter/PlatformServices.Shared/netstandard1.0/Services/{TestContextPropertyStrings.cs => ns10TestContextPropertyStrings.cs} (100%) rename src/Adapter/PlatformServices.Shared/{netstandard1.3/Utilities/ns13Validate.cs => netstandard1.0/Utilities/ns10Validate.cs} (100%) rename src/Adapter/{PlatformServices.NetCore/RecursiveDirectoryPathNetCore.cs => PlatformServices.Shared/netstandard1.0/ns10RecursiveDirectoryPath.cs} (100%) diff --git a/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj b/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj index 70e1710cc7..1009487a7e 100644 --- a/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj +++ b/src/Adapter/PlatformServices.Desktop/PlatformServices.Desktop.csproj @@ -45,8 +45,17 @@ - - Services\TestContextPropertyStrings.cs + + ns10RecursiveDirectoryPath.cs + + + Services\ns10MSTestSettingsProvider.cs + + + Services\ns10TestContextPropertyStrings.cs + + + Utilities\ns10Validate.cs Extensions\ns13ExceptionExtensions.cs @@ -66,6 +75,9 @@ Services\ns13MSTestAdapterSettings.cs + + Services\ns13TestDeployment.cs + Utilities\ns13DeploymentItemUtility.cs @@ -75,9 +87,6 @@ Utilities\ns13FileUtility.cs - - Utilities\ns13Validate.cs - @@ -103,20 +112,17 @@ - - - - - + + - + diff --git a/src/Adapter/PlatformServices.Desktop/RecursiveDirectoryPathDesktop.cs b/src/Adapter/PlatformServices.Desktop/RecursiveDirectoryPathDesktop.cs deleted file mode 100644 index 52da3e51e0..0000000000 --- a/src/Adapter/PlatformServices.Desktop/RecursiveDirectoryPathDesktop.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices -{ - using System; - using System.Diagnostics.CodeAnalysis; - -#pragma warning disable SA1649 // File name must match first type name - - /// - /// Mstest settings in runsettings look like this - /// - /// - /// - /// - /// ...// by default includeSubDirectories is false - /// - /// - /// - /// For each directory we need to have two info 1) path 2) includeSubDirectories - /// - [Serializable] - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1603:DocumentationMustContainValidXml", Justification = "Reviewed. Suppression is OK here.")] - public class RecursiveDirectoryPath : MarshalByRefObject - { - /// - /// Initializes a new instance of the class. - /// - /// The directory path. - /// - /// True if to include subdirectory else false - /// - public RecursiveDirectoryPath(string dirPath, bool includeSubDirectories) - { - this.DirectoryPath = dirPath; - this.IncludeSubDirectories = includeSubDirectories; - } - - /// - /// Gets the directory path. - /// - public string DirectoryPath { get; private set; } - - /// - /// Gets a value indicating whether to include sub directories. - /// - public bool IncludeSubDirectories { get; private set; } - } -} diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDeployment.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDeployment.cs deleted file mode 100644 index 85aa229103..0000000000 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDeployment.cs +++ /dev/null @@ -1,230 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices -{ - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.IO; - using System.Linq; - using System.Reflection; - - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; - using Microsoft.VisualStudio.TestPlatform.ObjectModel; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; - -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - - /// - /// The test deployment. - /// - public class TestDeployment : ITestDeployment - { - #region Service Utility Variables - - private DeploymentItemUtility deploymentItemUtility; - private DeploymentUtility deploymentUtility; - private FileUtility fileUtility; - private MSTestAdapterSettings adapterSettings; - - #endregion - - /// - /// Initializes a new instance of the class. - /// - public TestDeployment() - : this(new DeploymentItemUtility(new ReflectionUtility()), new DeploymentUtility(), new FileUtility()) - { - } - - /// - /// Initializes a new instance of the class. Used for unit tests. - /// - /// The deployment item utility. - /// The deployment utility. - /// The file utility. - internal TestDeployment(DeploymentItemUtility deploymentItemUtility, DeploymentUtility deploymentUtility, FileUtility fileUtility) - { - this.deploymentItemUtility = deploymentItemUtility; - this.deploymentUtility = deploymentUtility; - this.fileUtility = fileUtility; - this.adapterSettings = null; - RunDirectories = null; - } - - /// - /// Gets the current run directories for this session. - /// - /// - /// This is intialized at the beginning of a run session when Deploy is called. - /// Leaving this as a static varaible since the testContext needs to be filled in with this information. - /// - internal static TestRunDirectories RunDirectories - { - get; - private set; - } - - /// - /// The get deployment items. - /// - /// The method. - /// The type. - /// The warnings. - /// A string of deployment items. - public KeyValuePair[] GetDeploymentItems(MethodInfo method, Type type, ICollection warnings) - { - return this.deploymentItemUtility.GetDeploymentItems(method, this.deploymentItemUtility.GetClassLevelDeploymentItems(type, warnings), warnings); - } - - /// - /// The cleanup. - /// - public void Cleanup() - { - // Delete the deployment directory - if (RunDirectories != null && this.adapterSettings.DeleteDeploymentDirectoryAfterTestRunIsComplete) - { - EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "Deleting deployment directory {0}", RunDirectories.RootDeploymentDirectory); - - this.fileUtility.DeleteDirectories(RunDirectories.RootDeploymentDirectory); - - EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "Deleted deployment directory {0}", RunDirectories.RootDeploymentDirectory); - } - } - - /// - /// Gets the deployment output directory where the source file along with all its dependencies is dropped. - /// - /// The deployment output directory. - public string GetDeploymentDirectory() - { - return RunDirectories?.OutDirectory; - } - - /// - /// Deploy files related to the list of tests specified. - /// - /// The tests. - /// The run context. - /// The framework handle. - /// Return true if deployment is done. - public bool Deploy(IEnumerable tests, IRunContext runContext, IFrameworkHandle frameworkHandle) - { - Debug.Assert(tests != null, "tests"); - - // Reset runDirectories before doing deployment, so that older values of runDirectories is not picked - // even if test host is kept alive. - RunDirectories = null; - - this.adapterSettings = MSTestSettingsProvider.Settings; - bool canDeploy = this.CanDeploy(); - var hasDeploymentItems = tests.Any(test => this.deploymentItemUtility.HasDeploymentItems(test)); - - // deployment directories should not be created in this case,simply return - if (!canDeploy && hasDeploymentItems) - { - return false; - } - - RunDirectories = this.deploymentUtility.CreateDeploymentDirectories(runContext); - - // Deployment directories are created but deployment will not happen. - // This is added just to keep consistency with MSTestv1 behaviour. - if (!hasDeploymentItems) - { - return false; - } - - using (new SuspendCodeCoverage()) - { - // Group the tests by source - var testsBySource = from test in tests - group test by test.Source into testGroup - select new { Source = testGroup.Key, Tests = testGroup }; - - var runDirectories = RunDirectories; - foreach (var group in testsBySource) - { - // do the deployment - this.deploymentUtility.Deploy(@group.Tests, @group.Source, runContext, frameworkHandle, RunDirectories); - } - - // Update the runDirectories - RunDirectories = runDirectories; - } - - return true; - } - - internal static IDictionary GetDeploymentInformation(string source) - { - var properties = new Dictionary(); - - var applicationBaseDirectory = string.Empty; - - // Run directories can be null in win8. - if (RunDirectories == null && !string.IsNullOrEmpty(source)) - { - // applicationBaseDirectory is set at source level - applicationBaseDirectory = Path.GetDirectoryName(source); - } - - properties[TestContextPropertyStrings.TestRunDirectory] = RunDirectories != null - ? RunDirectories.RootDeploymentDirectory - : applicationBaseDirectory; - properties[TestContextPropertyStrings.DeploymentDirectory] = RunDirectories != null - ? RunDirectories.OutDirectory - : applicationBaseDirectory; - properties[TestContextPropertyStrings.ResultsDirectory] = RunDirectories != null - ? RunDirectories.InDirectory - : applicationBaseDirectory; - properties[TestContextPropertyStrings.TestRunResultsDirectory] = RunDirectories != null - ? RunDirectories.InMachineNameDirectory - : applicationBaseDirectory; - properties[TestContextPropertyStrings.TestResultsDirectory] = RunDirectories != null - ? RunDirectories.InDirectory - : applicationBaseDirectory; - properties[TestContextPropertyStrings.TestDir] = RunDirectories != null - ? RunDirectories.RootDeploymentDirectory - : applicationBaseDirectory; - properties[TestContextPropertyStrings.TestDeploymentDir] = RunDirectories != null - ? RunDirectories.OutDirectory - : applicationBaseDirectory; - properties[TestContextPropertyStrings.TestLogsDir] = RunDirectories != null - ? RunDirectories.InMachineNameDirectory - : applicationBaseDirectory; - - return properties; - } - - /// - /// Reset the static varaible to default values. Used only for testing purposes. - /// - internal static void Reset() - { - RunDirectories = null; - } - - /// - /// Returns whether deployment can happen or not - /// - /// True if deployment can be done. - private bool CanDeploy() - { - if (!this.adapterSettings.DeploymentEnabled) - { - EqtTrace.InfoIf(EqtTrace.IsInfoEnabled, "MSTestExecutor: CanDeploy is false."); - return false; - } - - return true; - } - } - -#pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName -} diff --git a/src/Adapter/PlatformServices.Desktop/Services/MSTestSettingsProvider.cs b/src/Adapter/PlatformServices.Desktop/Services/MSTestSettingsProvider.cs deleted file mode 100644 index e35849e700..0000000000 --- a/src/Adapter/PlatformServices.Desktop/Services/MSTestSettingsProvider.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices -{ - using System.Collections.Generic; - using System.Xml; - using Microsoft.VisualStudio.TestPlatform.ObjectModel; - - using ISettingsProvider = Interface.ISettingsProvider; - - /// - /// Class to read settings from the runsettings xml for the desktop. - /// - public class MSTestSettingsProvider : ISettingsProvider - { - /// - /// Member variable for Adapter settings - /// - private static MSTestAdapterSettings settings; - - /// - /// Gets settings provided to the adapter. - /// - public static MSTestAdapterSettings Settings - { - get - { - if (settings == null) - { - settings = new MSTestAdapterSettings(); - } - - return settings; - } - } - - /// - /// Reset the settings to its default. - /// - public static void Reset() - { - settings = null; - } - - /// - /// Load the settings from the reader. - /// - /// Reader to load the settings from. - public void Load(XmlReader reader) - { - ValidateArg.NotNull(reader, "reader"); - settings = MSTestAdapterSettings.ToSettings(reader); - } - - public IDictionary GetProperties(string source) - { - return TestDeployment.GetDeploymentInformation(source); - } - } -} diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/AssemblyUtilityDesktop.cs b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopAssemblyUtility.cs similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Utilities/AssemblyUtilityDesktop.cs rename to src/Adapter/PlatformServices.Desktop/Utilities/DesktopAssemblyUtility.cs diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtilityDesktop.cs b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopDeploymentUtility.cs similarity index 55% rename from src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtilityDesktop.cs rename to src/Adapter/PlatformServices.Desktop/Utilities/DesktopDeploymentUtility.cs index de56f94c21..68b6af0235 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/DeploymentUtilityDesktop.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopDeploymentUtility.cs @@ -34,178 +34,54 @@ public DeploymentUtility(DeploymentItemUtility deploymentItemUtility, AssemblyUt } /// - /// Does the deployment of parameter deployment items & the testSource to the parameter directory. + /// Get root deployment directory /// - /// The deployment item. - /// The test source. - /// The deployment directory. - /// Root results directory - /// Returns a list of deployment warnings - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] - public override IEnumerable Deploy(IList deploymentItems, string testSource, string deploymentDirectory, string resultsDirectory) + /// The base directory. + /// Root deployment directory. + protected override string GetRootDeploymentDirectory(string baseDirectory) { - Validate.IsFalse(string.IsNullOrWhiteSpace(deploymentDirectory), "Deployment directory is null or empty"); - Validate.IsTrue(this.FileUtility.DoesDirectoryExist(deploymentDirectory), $"Deployment directory {deploymentDirectory} does not exist"); - Validate.IsFalse(string.IsNullOrWhiteSpace(testSource), "TestSource directory is null/empty"); - Validate.IsTrue(this.FileUtility.DoesFileExist(testSource), $"TestSource {testSource} does not exist."); - - testSource = Path.GetFullPath(testSource); - var warnings = new List(); - - if (MSTestSettingsProvider.Settings.DeployTestSourceDependencies) - { - EqtTrace.Info("Adding the references and satellite assemblies to the deploymentitems list"); + string dateTimeSufix = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo); + string directoryName = string.Format(CultureInfo.CurrentCulture, Resource.TestRunName, DeploymentFolderPrefix, Environment.UserName, dateTimeSufix); + directoryName = this.FileUtility.ReplaceInvalidFileNameCharacters(directoryName); - // Get the referenced assemblies. - this.ProcessNewStorage(testSource, deploymentItems, warnings); + return this.FileUtility.GetNextIterationDirectoryName(baseDirectory, directoryName); + } - // Get the satellite assemblies - var satelliteItems = this.GetSatellites(deploymentItems, testSource, warnings); - foreach (var satelliteItem in satelliteItems) - { - this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, satelliteItem); - } - } - else + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] + protected override void ProcessNewStorage(string testSource, IList deploymentItems, IList warnings) + { + // Add deployment items and process .config files only for storages we have not processed before. + string errorMessage; + if (!this.DeploymentItemUtility.IsValidDeploymentItem(testSource, string.Empty, out errorMessage)) { - EqtTrace.Info("Adding the test source directory to the deploymentitems list"); - this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(Path.GetDirectoryName(testSource))); + warnings.Add(errorMessage); + return; } - // Maps relative to Out dir destination -> source and used to determine if there are conflicted items. - var destToSource = new Dictionary(StringComparer.OrdinalIgnoreCase); + this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(testSource, string.Empty, DeploymentItemOriginType.TestStorage)); - // Copy the deployment items. (As deployment item can correspond to directories as well, so each deployment item may map to n files) - foreach (var deploymentItem in deploymentItems) + // Deploy .config file if exists, only for assemlbies, i.e. DLL and EXE. + // First check .config, then if not found check for App.Config + // and deploy AppConfig to .config. + if (this.AssemblyUtility.IsAssemblyExtension(Path.GetExtension(testSource))) { - ValidateArg.NotNull(deploymentItem, "deploymentItem should not be null."); + var configFile = this.AddTestSourceConfigFileIfExists(testSource, deploymentItems); - // Validate the output directory. - if (!this.IsOutputDirectoryValid(deploymentItem, deploymentDirectory, warnings)) + // Deal with test dependencies: update dependencyDeploymentItems and missingDependentAssemblies. + try { - continue; + // We look for dependent assemblies only for DLL and EXE's. + this.AddDependencies(testSource, configFile, deploymentItems, warnings); } - - // Get the files corresponding to this deployment item - var deploymentItemFiles = this.GetFullPathToFilesCorrespondingToDeploymentItem(deploymentItem, testSource, resultsDirectory, warnings, out bool itemIsDirectory); - if (deploymentItemFiles == null) + catch (Exception e) { - continue; + string warning = string.Format(CultureInfo.CurrentCulture, Resource.DeploymentErrorFailedToDeployDependencies, testSource, e); + warnings.Add(warning); } - - var fullPathToDeploymentItemSource = this.GetFullPathToDeploymentItemSource(deploymentItem.SourcePath, testSource); - - // Note: source is already rooted. - foreach (var deploymentItemFile in deploymentItemFiles) - { - Debug.Assert(Path.IsPathRooted(deploymentItemFile), "File " + deploymentItemFile + " is not rooted"); - - // List of files to deploy, by default, just itemFile. - var filesToDeploy = new List(1); - filesToDeploy.Add(deploymentItemFile); - - // Find dependencies of test deployment items and deploy them at the same time as master file. - if (deploymentItem.OriginType == DeploymentItemOriginType.PerTestDeployment && - this.AssemblyUtility.IsAssemblyExtension(Path.GetExtension(deploymentItemFile))) - { - this.AddDependenciesOfDeploymentItem(deploymentItemFile, filesToDeploy, warnings); - } - - foreach (var fileToDeploy in filesToDeploy) - { - Debug.Assert(Path.IsPathRooted(fileToDeploy), "File " + fileToDeploy + " is not rooted"); - - // Ignore the test platform files. - var tempFile = Path.GetFileName(fileToDeploy); - var assemblyName = Path.GetFileName(Assembly.GetExecutingAssembly().Location); - if (tempFile.Equals(assemblyName, StringComparison.OrdinalIgnoreCase)) - { - continue; - } - - string relativeDestination; - if (itemIsDirectory) - { - // Deploy into subdirectory of deployment (Out) dir. - Debug.Assert(fileToDeploy.StartsWith(fullPathToDeploymentItemSource, StringComparison.Ordinal), "Somehow source is outside original dir."); - relativeDestination = this.FileUtility.TryConvertPathToRelative(fileToDeploy, fullPathToDeploymentItemSource); - } - else - { - // Deploy just to the deployment (Out) dir. - relativeDestination = Path.GetFileName(fileToDeploy); - } - - relativeDestination = Path.Combine(deploymentItem.RelativeOutputDirectory, relativeDestination); // Ignores empty arg1. - var destination = Path.Combine(deploymentDirectory, relativeDestination); - try - { - destination = Path.GetFullPath(destination); - } - catch (Exception e) - { - var warning = string.Format(CultureInfo.CurrentCulture, Resource.DeploymentErrorFailedToAccessFile, destination, e.GetType(), e.Message); - warnings.Add(warning); - - continue; - } - - if (!destToSource.ContainsKey(relativeDestination)) - { - destToSource.Add(relativeDestination, fileToDeploy); - - // Now, finally we can copy the file... - destination = this.FileUtility.CopyFileOverwrite(fileToDeploy, destination, out string warning); - if (!string.IsNullOrEmpty(warning)) - { - warnings.Add(warning); - } - - if (string.IsNullOrEmpty(destination)) - { - continue; - } - - // We clear the attributes so that e.g. you can write to the copies of files originally under SCC. - this.FileUtility.SetAttributes(destination, FileAttributes.Normal); - - // Deploy PDB for line number info in stack trace. - this.FileUtility.FindAndDeployPdb(destination, relativeDestination, fileToDeploy, destToSource); - } - else if ( - !string.Equals( - fileToDeploy, - destToSource[relativeDestination], - StringComparison.OrdinalIgnoreCase)) - { - EqtTrace.WarningIf( - EqtTrace.IsWarningEnabled, - "Conflict during copiyng file: '{0}' and '{1}' are from different origins although they might be the same.", - fileToDeploy, - destToSource[relativeDestination]); - } - } // foreach fileToDeploy. - } // foreach itemFile. } - - return warnings; - } - - /// - /// Get root deployment directory - /// - /// The base directory. - /// Root deployment directory. - protected override string GetRootDeploymentDirectory(string baseDirectory) - { - string dateTimeSufix = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo); - string directoryName = string.Format(CultureInfo.CurrentCulture, Resource.TestRunName, DeploymentFolderPrefix, Environment.UserName, dateTimeSufix); - directoryName = this.FileUtility.ReplaceInvalidFileNameCharacters(directoryName); - - return this.FileUtility.GetNextIterationDirectoryName(baseDirectory, directoryName); } - private void AddDependenciesOfDeploymentItem(string deploymentItemFile, IList filesToDeploy, IList warnings) + protected override void AddDependenciesOfDeploymentItem(string deploymentItemFile, IList filesToDeploy, IList warnings) { var dependencies = new List(); @@ -220,48 +96,7 @@ private void AddDependenciesOfDeploymentItem(string deploymentItemFile, IList - /// Process test storage and add dependant assemblies to dependencyDeploymentItems. - /// - /// The test source. - /// The config file. - /// Deployment items. - /// Warnigns. - private void AddDependencies(string testSource, string configFile, IList deploymentItems, IList warnings) - { - Debug.Assert(!string.IsNullOrEmpty(testSource), "testSource should not be null or empty."); - - // config file can be null. - Debug.Assert(deploymentItems != null, "deploymentItems should not be null."); - Debug.Assert(Path.IsPathRooted(testSource), "path should be rooted."); - - // Note: if this is not an assembly we simply return empty array, also: - // we do recursive search and report missing. - IList warningList; - string[] references = this.AssemblyUtility.GetFullPathToDependentAssemblies(testSource, configFile, out warningList); - if (warningList != null && warningList.Count > 0) - { - warnings = warnings.Concat(warningList).ToList(); - } - - if (EqtTrace.IsInfoEnabled) - { - EqtTrace.Info("DeploymentManager: Source:{0} has following references", testSource); - } - - foreach (string reference in references) - { - DeploymentItem deploymentItem = new DeploymentItem(reference, string.Empty, DeploymentItemOriginType.Dependency); - this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, deploymentItem); - - if (EqtTrace.IsInfoEnabled) - { - EqtTrace.Info("DeploymentManager: Reference:{0} ", reference); - } - } - } - - private IEnumerable GetSatellites(IEnumerable deploymentItems, string testSource, IList warnings) + protected override IEnumerable GetSatellites(IEnumerable deploymentItems, string testSource, IList warnings) { List satellites = new List(); foreach (DeploymentItem item in deploymentItems) @@ -353,36 +188,43 @@ private IEnumerable GetSatellites(IEnumerable de return satellites; } - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] - private void ProcessNewStorage(string testSource, IList deploymentItems, IList warnings) + /// + /// Process test storage and add dependant assemblies to dependencyDeploymentItems. + /// + /// The test source. + /// The config file. + /// Deployment items. + /// Warnigns. + private void AddDependencies(string testSource, string configFile, IList deploymentItems, IList warnings) { - // Add deployment items and process .config files only for storages we have not processed before. - string errorMessage; - if (!this.DeploymentItemUtility.IsValidDeploymentItem(testSource, string.Empty, out errorMessage)) + Debug.Assert(!string.IsNullOrEmpty(testSource), "testSource should not be null or empty."); + + // config file can be null. + Debug.Assert(deploymentItems != null, "deploymentItems should not be null."); + Debug.Assert(Path.IsPathRooted(testSource), "path should be rooted."); + + // Note: if this is not an assembly we simply return empty array, also: + // we do recursive search and report missing. + IList warningList; + string[] references = this.AssemblyUtility.GetFullPathToDependentAssemblies(testSource, configFile, out warningList); + if (warningList != null && warningList.Count > 0) { - warnings.Add(errorMessage); - return; + warnings = warnings.Concat(warningList).ToList(); } - this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(testSource, string.Empty, DeploymentItemOriginType.TestStorage)); + if (EqtTrace.IsInfoEnabled) + { + EqtTrace.Info("DeploymentManager: Source:{0} has following references", testSource); + } - // Deploy .config file if exists, only for assemlbies, i.e. DLL and EXE. - // First check .config, then if not found check for App.Config - // and deploy AppConfig to .config. - if (this.AssemblyUtility.IsAssemblyExtension(Path.GetExtension(testSource))) + foreach (string reference in references) { - var configFile = this.AddTestSourceConfigFileIfExists(testSource, deploymentItems); + DeploymentItem deploymentItem = new DeploymentItem(reference, string.Empty, DeploymentItemOriginType.Dependency); + this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, deploymentItem); - // Deal with test dependencies: update dependencyDeploymentItems and missingDependentAssemblies. - try - { - // We look for dependent assemblies only for DLL and EXE's. - this.AddDependencies(testSource, configFile, deploymentItems, warnings); - } - catch (Exception e) + if (EqtTrace.IsInfoEnabled) { - string warning = string.Format(CultureInfo.CurrentCulture, Resource.DeploymentErrorFailedToDeployDependencies, testSource, e); - warnings.Add(warning); + EqtTrace.Info("DeploymentManager: Reference:{0} ", reference); } } } diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/ReflectionUtilityDesktop.cs b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopReflectionUtility.cs similarity index 100% rename from src/Adapter/PlatformServices.Desktop/Utilities/ReflectionUtilityDesktop.cs rename to src/Adapter/PlatformServices.Desktop/Utilities/DesktopReflectionUtility.cs diff --git a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj index 7e17546009..2647d02572 100644 --- a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj +++ b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj @@ -17,9 +17,11 @@ + + @@ -27,24 +29,22 @@ - + + - - - - - - + + + Resources\Resource.Designer.cs True diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtilityNetCore.cs b/src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtilityNetCore.cs deleted file mode 100644 index fa4b74aa05..0000000000 --- a/src/Adapter/PlatformServices.NetCore/Utilities/DeploymentUtilityNetCore.cs +++ /dev/null @@ -1,200 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities -{ - using System; - using System.Collections.Generic; - using System.Diagnostics; - using System.Globalization; - using System.IO; - using System.Linq; - using System.Reflection; - using System.Security; - - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; - using Microsoft.VisualStudio.TestPlatform.ObjectModel; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; - -#pragma warning disable SA1649 // File name must match first type name - - internal class DeploymentUtility : DeploymentUtilityBase - { - public DeploymentUtility() - : base() - { - } - - public DeploymentUtility(DeploymentItemUtility deploymentItemUtility, AssemblyUtility assemblyUtility, FileUtility fileUtility) - : base(deploymentItemUtility, assemblyUtility, fileUtility) - { - } - - /// - /// Does the deployment of parameter deployment items & the testSource to the parameter directory. - /// - /// The deployment item. - /// The test source. - /// The deployment directory. - /// Root results directory - /// Returns a list of deployment warnings - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] - public override IEnumerable Deploy(IList deploymentItems, string testSource, string deploymentDirectory, string resultsDirectory) - { - Validate.IsFalse(string.IsNullOrWhiteSpace(deploymentDirectory), "Deployment directory is null or empty"); - Validate.IsTrue(this.FileUtility.DoesDirectoryExist(deploymentDirectory), $"Deployment directory {deploymentDirectory} does not exist"); - Validate.IsFalse(string.IsNullOrWhiteSpace(testSource), "TestSource directory is null/empty"); - Validate.IsTrue(this.FileUtility.DoesFileExist(testSource), $"TestSource {testSource} does not exist."); - - testSource = Path.GetFullPath(testSource); - var warnings = new List(); - - string errorMessage; - if (!this.DeploymentItemUtility.IsValidDeploymentItem(testSource, string.Empty, out errorMessage)) - { - warnings.Add(errorMessage); - } - else - { - EqtTrace.Info("Adding the test source directory to the deploymentitems list"); - this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(Path.GetDirectoryName(testSource))); - } - - // Maps relative to Out dir destination -> source and used to determine if there are conflicted items. - var destToSource = new Dictionary(StringComparer.OrdinalIgnoreCase); - - // Copy the deployment items. (As deployment item can correspond to directories as well, so each deployment item may map to n files) - foreach (var deploymentItem in deploymentItems) - { - ValidateArg.NotNull(deploymentItem, "deploymentItem should not be null."); - - // Validate the output directory. - if (!this.IsOutputDirectoryValid(deploymentItem, deploymentDirectory, warnings)) - { - continue; - } - - // Get the files corresponding to this deployment item - var deploymentItemFiles = this.GetFullPathToFilesCorrespondingToDeploymentItem(deploymentItem, testSource, resultsDirectory, warnings, out bool itemIsDirectory); - if (deploymentItemFiles == null) - { - continue; - } - - var fullPathToDeploymentItemSource = this.GetFullPathToDeploymentItemSource(deploymentItem.SourcePath, testSource); - - // Note: source is already rooted. - foreach (var fileToDeploy in deploymentItemFiles) - { - Debug.Assert(Path.IsPathRooted(fileToDeploy), "File " + fileToDeploy + " is not rooted"); - - Debug.Assert(Path.IsPathRooted(fileToDeploy), "File " + fileToDeploy + " is not rooted"); - - // Ignore the test platform files. - var tempFile = Path.GetFileName(fileToDeploy); - var assemblyName = Path.GetFileName(this.GetType().GetTypeInfo().Assembly.Location); - if (tempFile.Equals(assemblyName, StringComparison.OrdinalIgnoreCase)) - { - continue; - } - - string relativeDestination; - if (itemIsDirectory) - { - // Deploy into subdirectory of deployment (Out) dir. - Debug.Assert(fileToDeploy.StartsWith(fullPathToDeploymentItemSource, StringComparison.Ordinal), "Somehow source is outside original dir."); - relativeDestination = this.FileUtility.TryConvertPathToRelative(fileToDeploy, fullPathToDeploymentItemSource); - } - else - { - // Deploy just to the deployment (Out) dir. - relativeDestination = Path.GetFileName(fileToDeploy); - } - - relativeDestination = Path.Combine(deploymentItem.RelativeOutputDirectory, relativeDestination); // Ignores empty arg1. - var destination = Path.Combine(deploymentDirectory, relativeDestination); - try - { - destination = Path.GetFullPath(destination); - } - catch (Exception e) - { - var warning = string.Format(CultureInfo.CurrentCulture, Resource.DeploymentErrorFailedToAccessFile, destination, e.GetType(), e.Message); - warnings.Add(warning); - - continue; - } - - if (!destToSource.ContainsKey(relativeDestination)) - { - destToSource.Add(relativeDestination, fileToDeploy); - - // Now, finally we can copy the file... - destination = this.FileUtility.CopyFileOverwrite(fileToDeploy, destination, out string warning); - if (!string.IsNullOrEmpty(warning)) - { - warnings.Add(warning); - } - - if (string.IsNullOrEmpty(destination)) - { - continue; - } - - // We clear the attributes so that e.g. you can write to the copies of files originally under SCC. - this.FileUtility.SetAttributes(destination, FileAttributes.Normal); - - // Deploy PDB for line number info in stack trace. - this.FileUtility.FindAndDeployPdb(destination, relativeDestination, fileToDeploy, destToSource); - } - else if ( - !string.Equals( - fileToDeploy, - destToSource[relativeDestination], - StringComparison.OrdinalIgnoreCase)) - { - EqtTrace.WarningIf( - EqtTrace.IsWarningEnabled, - "Conflict during copiyng file: '{0}' and '{1}' are from different origins although they might be the same.", - fileToDeploy, - destToSource[relativeDestination]); - } - } // foreach itemFile. - } - - return warnings; - } - - /// - /// Get root deployment directory - /// - /// The base directory. - /// Root deployment directory. - protected override string GetRootDeploymentDirectory(string baseDirectory) - { - string dateTimeSufix = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo); - string directoryName = string.Format(CultureInfo.CurrentCulture, Resource.TestRunName, DeploymentFolderPrefix, Environment.GetEnvironmentVariable("USERNAME") ?? Environment.GetEnvironmentVariable("USER"), dateTimeSufix); - directoryName = this.FileUtility.ReplaceInvalidFileNameCharacters(directoryName); - - return this.FileUtility.GetNextIterationDirectoryName(baseDirectory, directoryName); - } - - private bool IsDeploymentItemSourceADirectory(DeploymentItem deploymentItem, string testSource, out string resultDirectory) - { - resultDirectory = null; - - string directory = this.GetFullPathToDeploymentItemSource(deploymentItem.SourcePath, testSource); - directory = directory.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); - - if (this.FileUtility.DoesDirectoryExist(directory)) - { - resultDirectory = directory; - return true; - } - - return false; - } - } -} diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/AssemblyUtilityNetCore.cs b/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreAssemblyUtility.cs similarity index 100% rename from src/Adapter/PlatformServices.NetCore/Utilities/AssemblyUtilityNetCore.cs rename to src/Adapter/PlatformServices.NetCore/Utilities/NetCoreAssemblyUtility.cs diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreDeploymentUtility.cs b/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreDeploymentUtility.cs new file mode 100644 index 0000000000..eb89d3a993 --- /dev/null +++ b/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreDeploymentUtility.cs @@ -0,0 +1,78 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities +{ + using System; + using System.Collections.Generic; + using System.Diagnostics; + using System.Globalization; + using System.IO; + using System.Linq; + using System.Reflection; + using System.Security; + + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + +#pragma warning disable SA1649 // File name must match first type name + + internal class DeploymentUtility : DeploymentUtilityBase + { + public DeploymentUtility() + : base() + { + } + + public DeploymentUtility(DeploymentItemUtility deploymentItemUtility, AssemblyUtility assemblyUtility, FileUtility fileUtility) + : base(deploymentItemUtility, assemblyUtility, fileUtility) + { + } + + /// + /// Get root deployment directory + /// + /// The base directory. + /// Root deployment directory. + protected override string GetRootDeploymentDirectory(string baseDirectory) + { + string dateTimeSufix = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", DateTimeFormatInfo.InvariantInfo); + string directoryName = string.Format(CultureInfo.CurrentCulture, Resource.TestRunName, DeploymentFolderPrefix, Environment.GetEnvironmentVariable("USERNAME") ?? Environment.GetEnvironmentVariable("USER"), dateTimeSufix); + directoryName = this.FileUtility.ReplaceInvalidFileNameCharacters(directoryName); + + return this.FileUtility.GetNextIterationDirectoryName(baseDirectory, directoryName); + } + + protected override void ProcessNewStorage(string testSource, IList deploymentItems, IList warnings) + { + } + + protected override IEnumerable GetSatellites(IEnumerable deploymentItems, string testSource, IList warnings) + { + return null; + } + + protected override void AddDependenciesOfDeploymentItem(string deploymentItemFile, IList filesToDeploy, IList warnings) + { + } + + private bool IsDeploymentItemSourceADirectory(DeploymentItem deploymentItem, string testSource, out string resultDirectory) + { + resultDirectory = null; + + string directory = this.GetFullPathToDeploymentItemSource(deploymentItem.SourcePath, testSource); + directory = directory.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); + + if (this.FileUtility.DoesDirectoryExist(directory)) + { + resultDirectory = directory; + return true; + } + + return false; + } + } +} diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtilityNetCore.cs b/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreReflectionUtility.cs similarity index 91% rename from src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtilityNetCore.cs rename to src/Adapter/PlatformServices.NetCore/Utilities/NetCoreReflectionUtility.cs index 03dfdfa89c..8e07c3101f 100644 --- a/src/Adapter/PlatformServices.NetCore/Utilities/ReflectionUtilityNetCore.cs +++ b/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreReflectionUtility.cs @@ -41,9 +41,7 @@ internal object[] GetCustomAttributes(MemberInfo memberInfo, Type type, bool inh return null; } - bool shouldGetAllAttributes = type == null; - - if (shouldGetAllAttributes) + if (type == null) { return memberInfo.GetCustomAttributes(inherit).ToArray(); } @@ -55,7 +53,7 @@ internal object[] GetCustomAttributes(MemberInfo memberInfo, Type type, bool inh internal object[] GetCustomAttributes(Assembly assembly, Type type) { - return assembly.GetCustomAttributes(type).ToArray(); + return assembly.GetCustomAttributes(type).ToArray(); } } } diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/RecursiveDirectoryPath.cs b/src/Adapter/PlatformServices.NetCore/Utilities/RecursiveDirectoryPath.cs deleted file mode 100644 index 8fade77d98..0000000000 --- a/src/Adapter/PlatformServices.NetCore/Utilities/RecursiveDirectoryPath.cs +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices -{ - using System; - using System.Diagnostics.CodeAnalysis; - using System.Security; - - /// - /// Mstest settings in runsettings look like this - /// - /// - /// - /// - /// ...// by default includeSubDirectories is false - /// - /// - /// - /// For each directory we need to have two info 1) path 2) includeSubDirectories - /// - [Serializable] - [SuppressMessage("StyleCop.CSharp.DocumentationRules", "SA1603:DocumentationMustContainValidXml", Justification = "Reviewed. Suppression is OK here.")] - public class RecursiveDirectoryPath : MarshalByRefObject - { - /// - /// Initializes a new instance of the class. - /// - /// The directory path. - /// - /// True if to include subdirectory else false - /// - public RecursiveDirectoryPath(string dirPath, bool includeSubDirectories) - { - this.DirectoryPath = dirPath; - this.IncludeSubDirectories = includeSubDirectories; - } - - /// - /// Gets the directory path. - /// - public string DirectoryPath { get; private set; } - - /// - /// Gets a value indicating whether to include sub directories. - /// - public bool IncludeSubDirectories { get; private set; } - - /// - /// Returns object to be used for controlling lifetime, null means infinite lifetime. - /// - /// - /// The . - /// - [SecurityCritical] - public override object InitializeLifetimeService() - { - return null; - } - } -} diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13SettingsProvider.cs b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10MSTestSettingsProvider.cs similarity index 100% rename from src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13SettingsProvider.cs rename to src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10MSTestSettingsProvider.cs diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/TestContextPropertyStrings.cs b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextPropertyStrings.cs similarity index 100% rename from src/Adapter/PlatformServices.Shared/netstandard1.0/Services/TestContextPropertyStrings.cs rename to src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextPropertyStrings.cs diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13Validate.cs b/src/Adapter/PlatformServices.Shared/netstandard1.0/Utilities/ns10Validate.cs similarity index 100% rename from src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13Validate.cs rename to src/Adapter/PlatformServices.Shared/netstandard1.0/Utilities/ns10Validate.cs diff --git a/src/Adapter/PlatformServices.NetCore/RecursiveDirectoryPathNetCore.cs b/src/Adapter/PlatformServices.Shared/netstandard1.0/ns10RecursiveDirectoryPath.cs similarity index 100% rename from src/Adapter/PlatformServices.NetCore/RecursiveDirectoryPathNetCore.cs rename to src/Adapter/PlatformServices.Shared/netstandard1.0/ns10RecursiveDirectoryPath.cs diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs index 2d27f4f87e..e090360567 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs @@ -140,21 +140,26 @@ public bool Deploy(IEnumerable tests, IRunContext runContext, IFramewo return false; } - // Group the tests by source - var testsBySource = from test in tests - group test by test.Source into testGroup - select new { Source = testGroup.Key, Tests = testGroup }; - - var runDirectories = RunDirectories; - foreach (var group in testsBySource) +#if !NETSTANDARD1_5 + using (new SuspendCodeCoverage()) +#endif { - // do the deployment - this.deploymentUtility.Deploy(@group.Tests, @group.Source, runContext, frameworkHandle, RunDirectories); + // Group the tests by source + var testsBySource = from test in tests + group test by test.Source into testGroup + select new { Source = testGroup.Key, Tests = testGroup }; + + var runDirectories = RunDirectories; + foreach (var group in testsBySource) + { + // do the deployment + this.deploymentUtility.Deploy(@group.Tests, @group.Source, runContext, frameworkHandle, RunDirectories); + } + + // Update the runDirectories + RunDirectories = runDirectories; } - // Update the runDirectories - RunDirectories = runDirectories; - return true; } @@ -222,4 +227,6 @@ private bool CanDeploy() return true; } } + +#pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName } diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs index e20676a186..cae3ac7c40 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs @@ -80,16 +80,6 @@ public TestRunDirectories CreateDeploymentDirectories(IRunContext runContext) return result; } - /// - /// Does the deployment of parameter deployment items & the testSource to the parameter directory. - /// - /// The deployment item. - /// The test source. - /// The deployment directory. - /// Root results directory - /// Returns a list of deployment warnings - public abstract IEnumerable Deploy(IList deploymentItems, string testSource, string deploymentDirectory, string resultsDirectory); - internal string GetConfigFile(string testSource) { string configFile = null; @@ -111,8 +101,171 @@ internal string GetConfigFile(string testSource) return configFile; } + /// + /// Does the deployment of parameter deployment items & the testSource to the parameter directory. + /// + /// The deployment item. + /// The test source. + /// The deployment directory. + /// Root results directory + /// Returns a list of deployment warnings + protected IEnumerable Deploy(IList deploymentItems, string testSource, string deploymentDirectory, string resultsDirectory) + { + Validate.IsFalse(string.IsNullOrWhiteSpace(deploymentDirectory), "Deployment directory is null or empty"); + Validate.IsTrue(this.FileUtility.DoesDirectoryExist(deploymentDirectory), $"Deployment directory {deploymentDirectory} does not exist"); + Validate.IsFalse(string.IsNullOrWhiteSpace(testSource), "TestSource directory is null/empty"); + Validate.IsTrue(this.FileUtility.DoesFileExist(testSource), $"TestSource {testSource} does not exist."); + + testSource = Path.GetFullPath(testSource); + var warnings = new List(); + + if (MSTestSettingsProvider.Settings.DeployTestSourceDependencies) + { + EqtTrace.Info("Adding the references and satellite assemblies to the deploymentitems list"); + + // Get the referenced assemblies. + this.ProcessNewStorage(testSource, deploymentItems, warnings); + + // Get the satellite assemblies + var satelliteItems = this.GetSatellites(deploymentItems, testSource, warnings); + foreach (var satelliteItem in satelliteItems) + { + this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, satelliteItem); + } + } + else + { + EqtTrace.Info("Adding the test source directory to the deploymentitems list"); + this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(Path.GetDirectoryName(testSource))); + } + + // Maps relative to Out dir destination -> source and used to determine if there are conflicted items. + var destToSource = new Dictionary(StringComparer.OrdinalIgnoreCase); + + // Copy the deployment items. (As deployment item can correspond to directories as well, so each deployment item may map to n files) + foreach (var deploymentItem in deploymentItems) + { + ValidateArg.NotNull(deploymentItem, "deploymentItem should not be null."); + + // Validate the output directory. + if (!this.IsOutputDirectoryValid(deploymentItem, deploymentDirectory, warnings)) + { + continue; + } + + // Get the files corresponding to this deployment item + var deploymentItemFiles = this.GetFullPathToFilesCorrespondingToDeploymentItem(deploymentItem, testSource, resultsDirectory, warnings, out bool itemIsDirectory); + if (deploymentItemFiles == null) + { + continue; + } + + var fullPathToDeploymentItemSource = this.GetFullPathToDeploymentItemSource(deploymentItem.SourcePath, testSource); + + // Note: source is already rooted. + foreach (var deploymentItemFile in deploymentItemFiles) + { + Debug.Assert(Path.IsPathRooted(deploymentItemFile), "File " + deploymentItemFile + " is not rooted"); + + // List of files to deploy, by default, just itemFile. + var filesToDeploy = new List(1); + filesToDeploy.Add(deploymentItemFile); + + // Find dependencies of test deployment items and deploy them at the same time as master file. + if (deploymentItem.OriginType == DeploymentItemOriginType.PerTestDeployment && + this.AssemblyUtility.IsAssemblyExtension(Path.GetExtension(deploymentItemFile))) + { + this.AddDependenciesOfDeploymentItem(deploymentItemFile, filesToDeploy, warnings); + } + + foreach (var fileToDeploy in filesToDeploy) + { + Debug.Assert(Path.IsPathRooted(fileToDeploy), "File " + fileToDeploy + " is not rooted"); + + // Ignore the test platform files. + var tempFile = Path.GetFileName(fileToDeploy); + var assemblyName = Path.GetFileName(this.GetType().GetTypeInfo().Assembly.Location); + if (tempFile.Equals(assemblyName, StringComparison.OrdinalIgnoreCase)) + { + continue; + } + + string relativeDestination; + if (itemIsDirectory) + { + // Deploy into subdirectory of deployment (Out) dir. + Debug.Assert(fileToDeploy.StartsWith(fullPathToDeploymentItemSource, StringComparison.Ordinal), "Somehow source is outside original dir."); + relativeDestination = this.FileUtility.TryConvertPathToRelative(fileToDeploy, fullPathToDeploymentItemSource); + } + else + { + // Deploy just to the deployment (Out) dir. + relativeDestination = Path.GetFileName(fileToDeploy); + } + + relativeDestination = Path.Combine(deploymentItem.RelativeOutputDirectory, relativeDestination); // Ignores empty arg1. + var destination = Path.Combine(deploymentDirectory, relativeDestination); + try + { + destination = Path.GetFullPath(destination); + } + catch (Exception e) + { + var warning = string.Format(CultureInfo.CurrentCulture, Resource.DeploymentErrorFailedToAccessFile, destination, e.GetType(), e.Message); + warnings.Add(warning); + + continue; + } + + if (!destToSource.ContainsKey(relativeDestination)) + { + destToSource.Add(relativeDestination, fileToDeploy); + + // Now, finally we can copy the file... + destination = this.FileUtility.CopyFileOverwrite(fileToDeploy, destination, out string warning); + if (!string.IsNullOrEmpty(warning)) + { + warnings.Add(warning); + } + + if (string.IsNullOrEmpty(destination)) + { + continue; + } + + // We clear the attributes so that e.g. you can write to the copies of files originally under SCC. + this.FileUtility.SetAttributes(destination, FileAttributes.Normal); + + // Deploy PDB for line number info in stack trace. + this.FileUtility.FindAndDeployPdb(destination, relativeDestination, fileToDeploy, destToSource); + } + else if ( + !string.Equals( + fileToDeploy, + destToSource[relativeDestination], + StringComparison.OrdinalIgnoreCase)) + { + EqtTrace.WarningIf( + EqtTrace.IsWarningEnabled, + "Conflict during copiyng file: '{0}' and '{1}' are from different origins although they might be the same.", + fileToDeploy, + destToSource[relativeDestination]); + } + } // foreach fileToDeploy. + } // foreach itemFile. + } + + return warnings; + } + protected abstract string GetRootDeploymentDirectory(string baseDirectory); + protected abstract void ProcessNewStorage(string testSource, IList deploymentItems, IList warnings); + + protected abstract IEnumerable GetSatellites(IEnumerable deploymentItems, string testSource, IList warnings); + + protected abstract void AddDependenciesOfDeploymentItem(string deploymentItemFile, IList filesToDeploy, IList warnings); + /// /// Get files corresponding to parameter deployment item. /// From f40b3469dcf0eee681d3a6b602ecf7f2211ff317 Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Mon, 4 Mar 2019 17:00:10 +0530 Subject: [PATCH 06/24] PR comment variable assign --- .../netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs index cae3ac7c40..a95ee84a5a 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs @@ -84,7 +84,8 @@ internal string GetConfigFile(string testSource) { string configFile = null; - if (this.FileUtility.DoesFileExist(testSource + TestAssemblyConfigFileExtension)) + var assemblyConfigFile = testSource + TestAssemblyConfigFileExtension; + if (this.FileUtility.DoesFileExist(assemblyConfigFile)) { // Path to config file cannot be bad: storage is already checked, and extension is valid. configFile = testSource + TestAssemblyConfigFileExtension; From 707ef008101a170b1dab327e6062058b4a841063 Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Thu, 7 Mar 2019 20:47:37 +0530 Subject: [PATCH 07/24] Test Cases restructuring --- .../Utilities/DesktopDeploymentUtility.cs | 27 +- .../Utilities/NetCoreDeploymentUtility.cs | 16 +- .../Utilities/NetCoreReflectionUtility.cs | 5 - .../Utilities/ns13DeploymentUtilityBase.cs | 38 +- ...PlatformServices.Desktop.Unit.Tests.csproj | 24 +- .../Services/DesktopTestDataSourceTests.cs | 4 +- .../Services/DesktopTestDeploymentTests.cs | 6 +- ...ts.cs => DesktopDeploymentUtilityTests.cs} | 60 +-- .../DesktopReflectionUtilityTests.cs | 116 +++++ ...PlatformServices.NetCore.Unit.Tests.csproj | 7 +- .../Services/MSTestAdapterSettingsTests.cs | 336 ------------- .../DeploymentItemUtilityNetCoreTests.cs | 461 ------------------ ...ts.cs => NetCoreDeploymentUtilityTests.cs} | 127 +---- .../ReflectionUtilityTestsNetCore.cs | 276 ----------- .../ns10MSTestAdapterSettingsTests.cs} | 41 +- .../Utilities/ns10DeploymentUtilityTests.cs | 126 +++++ .../netstandard1.0/ns10FileOperationsTests.cs | 2 +- .../ns10SettingsProviderTests.cs | 6 +- .../ns13MSTestSettingsProviderTests.cs} | 16 +- .../ns13DeploymentItemUtilityTests.cs} | 58 ++- .../Utilities/ns13ReflectionUtilityTests.cs} | 31 +- 21 files changed, 418 insertions(+), 1365 deletions(-) rename test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/{DeploymentUtilityTests.cs => DesktopDeploymentUtilityTests.cs} (84%) create mode 100644 test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DesktopReflectionUtilityTests.cs delete mode 100644 test/UnitTests/PlatformServices.NetCore.Unit.Tests/Services/MSTestAdapterSettingsTests.cs delete mode 100644 test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/DeploymentItemUtilityNetCoreTests.cs rename test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/{DeploymentUtilityNetCoreTests.cs => NetCoreDeploymentUtilityTests.cs} (60%) delete mode 100644 test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/ReflectionUtilityTestsNetCore.cs rename test/UnitTests/{PlatformServices.Desktop.Unit.Tests/Services/MSTestAdapterSettingsTests.cs => PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs} (96%) create mode 100644 test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10DeploymentUtilityTests.cs rename test/UnitTests/{PlatformServices.Desktop.Unit.Tests/Services/DesktopSettingsProviderTests.cs => PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13MSTestSettingsProviderTests.cs} (93%) rename test/UnitTests/{PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentItemUtilityTests.cs => PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs} (95%) rename test/UnitTests/{PlatformServices.Desktop.Unit.Tests/Utilities/ReflectionUtilityTests.cs => PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13ReflectionUtilityTests.cs} (94%) diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/DesktopDeploymentUtility.cs b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopDeploymentUtility.cs index 68b6af0235..0db68fe834 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/DesktopDeploymentUtility.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopDeploymentUtility.cs @@ -33,6 +33,29 @@ public DeploymentUtility(DeploymentItemUtility deploymentItemUtility, AssemblyUt { } + public override void AddDeploymentItemsBasedOnMsTestSetting(string testSource, IList deploymentItems, List warnings) + { + if (MSTestSettingsProvider.Settings.DeployTestSourceDependencies) + { + EqtTrace.Info("Adding the references and satellite assemblies to the deploymentitems list"); + + // Get the referenced assemblies. + this.ProcessNewStorage(testSource, deploymentItems, warnings); + + // Get the satellite assemblies + var satelliteItems = this.GetSatellites(deploymentItems, testSource, warnings); + foreach (var satelliteItem in satelliteItems) + { + this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, satelliteItem); + } + } + else + { + EqtTrace.Info("Adding the test source directory to the deploymentitems list"); + this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(Path.GetDirectoryName(testSource))); + } + } + /// /// Get root deployment directory /// @@ -48,7 +71,7 @@ protected override string GetRootDeploymentDirectory(string baseDirectory) } [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")] - protected override void ProcessNewStorage(string testSource, IList deploymentItems, IList warnings) + protected void ProcessNewStorage(string testSource, IList deploymentItems, IList warnings) { // Add deployment items and process .config files only for storages we have not processed before. string errorMessage; @@ -96,7 +119,7 @@ protected override void AddDependenciesOfDeploymentItem(string deploymentItemFil } } - protected override IEnumerable GetSatellites(IEnumerable deploymentItems, string testSource, IList warnings) + protected IEnumerable GetSatellites(IEnumerable deploymentItems, string testSource, IList warnings) { List satellites = new List(); foreach (DeploymentItem item in deploymentItems) diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreDeploymentUtility.cs b/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreDeploymentUtility.cs index eb89d3a993..a7ab62e02c 100644 --- a/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreDeploymentUtility.cs +++ b/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreDeploymentUtility.cs @@ -32,6 +32,12 @@ public DeploymentUtility(DeploymentItemUtility deploymentItemUtility, AssemblyUt { } + public override void AddDeploymentItemsBasedOnMsTestSetting(string testSource, IList deploymentItems, List warnings) + { + EqtTrace.Info("Adding the test source directory to the deploymentitems list"); + this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(Path.GetDirectoryName(testSource))); + } + /// /// Get root deployment directory /// @@ -46,15 +52,7 @@ protected override string GetRootDeploymentDirectory(string baseDirectory) return this.FileUtility.GetNextIterationDirectoryName(baseDirectory, directoryName); } - protected override void ProcessNewStorage(string testSource, IList deploymentItems, IList warnings) - { - } - - protected override IEnumerable GetSatellites(IEnumerable deploymentItems, string testSource, IList warnings) - { - return null; - } - + // Find dependencies of test deployment items. Its implemented only in full framework project as dependent files are not fetched in netcore. protected override void AddDependenciesOfDeploymentItem(string deploymentItemFile, IList filesToDeploy, IList warnings) { } diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreReflectionUtility.cs b/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreReflectionUtility.cs index 8e07c3101f..83c997e249 100644 --- a/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreReflectionUtility.cs +++ b/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreReflectionUtility.cs @@ -50,10 +50,5 @@ internal object[] GetCustomAttributes(MemberInfo memberInfo, Type type, bool inh return memberInfo.GetCustomAttributes(type, inherit).ToArray(); } } - - internal object[] GetCustomAttributes(Assembly assembly, Type type) - { - return assembly.GetCustomAttributes(type).ToArray(); - } } } diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs index a95ee84a5a..89302d6756 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs @@ -80,6 +80,14 @@ public TestRunDirectories CreateDeploymentDirectories(IRunContext runContext) return result; } + /// + /// add deployment items based on MSTestSettingsProvider.Settings.DeployTestSourceDependencies. This property is ignored in net core. + /// + /// The test source. + /// Deployment Items. + /// Warnings. + public abstract void AddDeploymentItemsBasedOnMsTestSetting(string testSource, IList deploymentItems, List warnings); + internal string GetConfigFile(string testSource) { string configFile = null; @@ -120,25 +128,7 @@ protected IEnumerable Deploy(IList deploymentItems, stri testSource = Path.GetFullPath(testSource); var warnings = new List(); - if (MSTestSettingsProvider.Settings.DeployTestSourceDependencies) - { - EqtTrace.Info("Adding the references and satellite assemblies to the deploymentitems list"); - - // Get the referenced assemblies. - this.ProcessNewStorage(testSource, deploymentItems, warnings); - - // Get the satellite assemblies - var satelliteItems = this.GetSatellites(deploymentItems, testSource, warnings); - foreach (var satelliteItem in satelliteItems) - { - this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, satelliteItem); - } - } - else - { - EqtTrace.Info("Adding the test source directory to the deploymentitems list"); - this.DeploymentItemUtility.AddDeploymentItem(deploymentItems, new DeploymentItem(Path.GetDirectoryName(testSource))); - } + this.AddDeploymentItemsBasedOnMsTestSetting(testSource, deploymentItems, warnings); // Maps relative to Out dir destination -> source and used to determine if there are conflicted items. var destToSource = new Dictionary(StringComparer.OrdinalIgnoreCase); @@ -259,12 +249,14 @@ protected IEnumerable Deploy(IList deploymentItems, stri return warnings; } + /// + /// Get root deployment directory + /// + /// The base directory. + /// Root deployment directory. protected abstract string GetRootDeploymentDirectory(string baseDirectory); - protected abstract void ProcessNewStorage(string testSource, IList deploymentItems, IList warnings); - - protected abstract IEnumerable GetSatellites(IEnumerable deploymentItems, string testSource, IList warnings); - + // Find dependencies of test deployment items protected abstract void AddDependenciesOfDeploymentItem(string deploymentItemFile, IList filesToDeploy, IList warnings); /// diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/PlatformServices.Desktop.Unit.Tests.csproj b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/PlatformServices.Desktop.Unit.Tests.csproj index a323bac277..991f4b1897 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/PlatformServices.Desktop.Unit.Tests.csproj +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/PlatformServices.Desktop.Unit.Tests.csproj @@ -64,6 +64,12 @@ Extensions\ns10ExceptionExtensionsTests.cs + + Services\ns10MSTestAdapterSettingsTests.cs + + + Utilities\ns10DeploymentUtilityTests.cs + Utilities\ns10FileUtilityTests.cs @@ -73,23 +79,29 @@ Services\ns13TraceListenerTests.cs + + Services\ns13MSTestSettingsProviderTests.cs + + + Utilities\ns13DeploymentItemUtilityTests.cs + + + Utilities\ns13ReflectionUtilityTests.cs + - - - - - + + @@ -117,7 +129,7 @@ {a7ea583b-a2b0-47da-a058-458f247c7575} Extension.Desktop - FrameworkV2DesktopExtension + FrameworkV2Extension {7252d9e3-267d-442c-96bc-c73aef3241d6} diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDataSourceTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDataSourceTests.cs index d1abc9444c..e69e75cbf2 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDataSourceTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDataSourceTests.cs @@ -5,7 +5,7 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Services { extern alias FrameworkV1; extern alias FrameworkV2; - extern alias FrameworkV2DesktopExtension; + extern alias FrameworkV2Extension; using System.Collections.Generic; using System.Data; @@ -14,7 +14,7 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Services using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel; using Moq; using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; - using DesktopTestFrameworkV2 = FrameworkV2DesktopExtension::Microsoft.VisualStudio.TestTools.UnitTesting; + using DesktopTestFrameworkV2 = FrameworkV2Extension::Microsoft.VisualStudio.TestTools.UnitTesting; using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; using TestFrameworkV2 = FrameworkV2::Microsoft.VisualStudio.TestTools.UnitTesting; using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute; diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDeploymentTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDeploymentTests.cs index 4449b5568c..2634654b9d 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDeploymentTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDeploymentTests.cs @@ -5,7 +5,7 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Services { extern alias FrameworkV1; extern alias FrameworkV2; - extern alias FrameworkV2DesktopExtension; + extern alias FrameworkV2Extension; using System.Collections.Generic; using System.IO; @@ -20,13 +20,13 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Services using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; using Moq; - using Utilities; + using MSTestAdapter.PlatformServices.Tests.Utilities; using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert; using Ignore = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.IgnoreAttribute; using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; - using TestFrameworkV2Extension = FrameworkV2DesktopExtension::Microsoft.VisualStudio.TestTools.UnitTesting; + using TestFrameworkV2Extension = FrameworkV2Extension::Microsoft.VisualStudio.TestTools.UnitTesting; using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute; using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentUtilityTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DesktopDeploymentUtilityTests.cs similarity index 84% rename from test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentUtilityTests.cs rename to test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DesktopDeploymentUtilityTests.cs index 328765b108..c80f7a8d18 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DesktopDeploymentUtilityTests.cs @@ -17,13 +17,16 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Utilities using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Moq; + using MSTestAdapter.PlatformServices.Tests.Utilities; using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute; using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; [TestClass] +#pragma warning disable SA1649 // File name must match first type name public class DeploymentUtilityTests +#pragma warning restore SA1649 // File name must match first type name { private const string TestRunDirectory = "C:\\temp\\testRunDirectory"; private const string RootDeploymentDirectory = "C:\\temp\\testRunDirectory\\Deploy"; @@ -59,63 +62,6 @@ public void TestInit() this.mocktestExecutionRecorder = new Mock(); } - #region CreateDeploymentDirectories tests - - [TestMethod] - public void CreateDeploymentDirectoriesShouldCreateDeploymentDirectoryFromRunContext() - { - // Setup mocks - this.mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(TestRunDirectory); - this.mockFileUtility.Setup(fu => fu.GetNextIterationDirectoryName(TestRunDirectory, It.IsAny())) - .Returns(RootDeploymentDirectory); - - // Act. - this.deploymentUtility.CreateDeploymentDirectories(this.mockRunContext.Object); - - // Assert. - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(RootDeploymentDirectory), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix)), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentOutDirectorySuffix)), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix), Environment.MachineName)), Times.Once); - } - - [TestMethod] - public void CreateDeploymentDirectoriesShouldCreateDefaultDeploymentDirectoryIfTestRunDirectoryIsNull() - { - // Setup mocks - this.mockRunContext.Setup(rc => rc.TestRunDirectory).Returns((string)null); - this.mockFileUtility.Setup(fu => fu.GetNextIterationDirectoryName(It.Is(s => s.Contains(TestRunDirectories.DefaultDeploymentRootDirectory)), It.IsAny())) - .Returns(RootDeploymentDirectory); - - // Act. - this.deploymentUtility.CreateDeploymentDirectories(this.mockRunContext.Object); - - // Assert. - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(RootDeploymentDirectory), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix)), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentOutDirectorySuffix)), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix), Environment.MachineName)), Times.Once); - } - - [TestMethod] - public void CreateDeploymentDirectoriesShouldCreateDefaultDeploymentDirectoryIfRunContextIsNull() - { - // Setup mocks - this.mockFileUtility.Setup(fu => fu.GetNextIterationDirectoryName(It.Is(s => s.Contains(TestRunDirectories.DefaultDeploymentRootDirectory)), It.IsAny())) - .Returns(RootDeploymentDirectory); - - // Act. - this.deploymentUtility.CreateDeploymentDirectories(null); - - // Assert. - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(RootDeploymentDirectory), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix)), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentOutDirectorySuffix)), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix), Environment.MachineName)), Times.Once); - } - - #endregion - #region Deploy tests [TestMethod] diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DesktopReflectionUtilityTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DesktopReflectionUtilityTests.cs new file mode 100644 index 0000000000..3986db4ebf --- /dev/null +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DesktopReflectionUtilityTests.cs @@ -0,0 +1,116 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Utilities +{ + extern alias FrameworkV1; + + using System; + using System.Collections.Generic; + using System.Reflection; + + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; + + using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; + using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert; + using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; + using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; + + [TestClass] +#pragma warning disable SA1649 // File name must match first type name + public class ReflectionUtilityTests +#pragma warning restore SA1649 // File name must match first type name + { + private ReflectionUtility reflectionUtility; + + public ReflectionUtilityTests() + { + this.reflectionUtility = new ReflectionUtility(); + } + + [TestMethod] + public void GetSpecificCustomAttributesOnAssemblyShouldReturnAllAttributes() + { + var asm = typeof(DummyTestClass).GetTypeInfo().Assembly; + + var attribs = this.reflectionUtility.GetCustomAttributes(asm, typeof(DummyAAttribute)); + + Assert.IsNotNull(attribs); + Assert.AreEqual(2, attribs.Length); + + var expectedAttribs = new string[] { "DummyA : a1", "DummyA : a2" }; + CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); + } + + internal static string[] GetAttributeValuePairs(object[] attributes) + { + var attribValuePairs = new List(); + foreach (var attrib in attributes) + { + if (attrib is DummySingleAAttribute) + { + var a = attrib as DummySingleAAttribute; + attribValuePairs.Add("DummySingleA : " + a.Value); + } + else if (attrib is DummyAAttribute) + { + var a = attrib as DummyAAttribute; + attribValuePairs.Add("DummyA : " + a.Value); + } + } + + return attribValuePairs.ToArray(); + } + + [DummyA("ba")] + public class DummyBaseTestClass + { + [DummyA("base")] + [DummySingleA("base")] + public virtual void DummyVTestMethod1() + { + } + + public void DummyBTestMethod2() + { + } + } + + [DummyA("a")] + public class DummyTestClass : DummyBaseTestClass + { + [DummyA("derived")] + [DummySingleA("derived")] + public override void DummyVTestMethod1() + { + } + + [DummySingleA("derived")] + public void DummyTestMethod2() + { + } + } + + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)] + public sealed class DummyAAttribute : Attribute + { + public DummyAAttribute(string foo) + { + this.Value = foo; + } + + public string Value { get; set; } + } + + [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = false)] + public class DummySingleAAttribute : Attribute + { + public DummySingleAAttribute(string foo) + { + this.Value = foo; + } + + public string Value { get; set; } + } + } +} diff --git a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj index 3297217eb8..cca4ca0c08 100644 --- a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj +++ b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj @@ -19,14 +19,18 @@ - + + + + + @@ -38,6 +42,7 @@ + FrameworkV2Extension diff --git a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Services/MSTestAdapterSettingsTests.cs b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Services/MSTestAdapterSettingsTests.cs deleted file mode 100644 index dd74057afd..0000000000 --- a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Services/MSTestAdapterSettingsTests.cs +++ /dev/null @@ -1,336 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace MSTestAdapter.PlatformServices.Tests.Services -{ - - using System; - using System.Collections.Generic; - using System.IO; - using System.Linq; - using System.Xml; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; - using Microsoft.VisualStudio.TestPlatform.ObjectModel; - using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; - using TestUtilities; - - using Microsoft.VisualStudio.TestTools.UnitTesting; - using System.Reflection; - - [TestClass] - public class MSTestAdapterSettingsTests - { - [TestCleanup] - public void Cleanup() - { - MSTestSettingsProvider.Reset(); - } - - #region ResolveEnvironmentVariableAndReturnFullPathIfExist tests. - - [TestMethod] - public void ResolveEnvironmentVariableShouldResolvePathWhenPassedAbsolutePath() - { - string path = @"C:\unitTesting\..\MsTest\Adapter"; - string baseDirectory = null; - string expectedResult = @"C:\MsTest\Adapter"; - - var adapterSettings = new TestableMSTestAdapterSettings(); - adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; - - string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); - - Assert.IsNotNull(result); - Assert.AreEqual(string.Compare(result, expectedResult, true), 0); - } - - [TestMethod] - public void ResolveEnvironmentVariableShouldResolvePathWithAnEnvironmentVariable() - { - string path = @"%temp%\unitTesting\MsTest\Adapter"; - string baseDirectory = null; - string expectedResult = @"C:\foo\unitTesting\MsTest\Adapter"; - - var adapterSettings = new TestableMSTestAdapterSettings(); - adapterSettings.ExpandEnvironmentVariablesSetter = (str) => { return str.Replace("%temp%", "C:\\foo"); }; - adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; - - string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); - - Assert.IsNotNull(result); - Assert.AreEqual(string.Compare(result, expectedResult, true), 0); - } - - /* [TestMethod] - public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePathWithoutDot() - { - string path = @"MsTest\Adapter"; - string baseDirectory = @"C:\unitTesting"; - string expectedResult = @"C:\unitTesting\MsTest\Adapter"; - - var adapterSettings = new TestableMSTestAdapterSettings(); - adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; - - string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); - - Assert.IsNotNull(result); - Assert.AreEqual(string.Compare(result, expectedResult, true), 0); - } */ - - [TestMethod] - public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePathWithDot() - { - string path = @".\MsTest\Adapter"; - string baseDirectory = @"C:\unitTesting"; - string expectedResult = @"C:\unitTesting\MsTest\Adapter"; - - var adapterSettings = new TestableMSTestAdapterSettings(); - adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; - - string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); - - Assert.IsNotNull(result); - Assert.AreEqual(string.Compare(result, expectedResult, true), 0); - } - - /* [TestMethod] - public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePath() - { - //System.Diagnostics.Debugger.Launch(); - string path = @"\MsTest\Adapter"; - string baseDirectory = @"C:\unitTesting"; - - // instead of returning "C:\unitTesting\MsTest\Adapter", it will return "(Drive from where test is running):\MsTest\Adapter", - // because path is starting with "\" - // this is how Path.GetFullPath works - string currentDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); - string currentDrive = currentDirectory.Split('\\').First() + "\\"; - string expectedResult = Path.Combine(currentDrive, @"MsTest\Adapter"); - - var adapterSettings = new TestableMSTestAdapterSettings(); - adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; - - string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); - - Assert.IsNotNull(result); - Assert.AreEqual(string.Compare(result, expectedResult, true), 0); - } */ - - [TestMethod] - public void ResolveEnvironmentVariableShouldResolvePathWhenPassedNetworkPath() - { - string path = @"\\MsTest\Adapter"; - string baseDirectory = @"C:\unitTesting"; - - string expectedResult = path; - - var adapterSettings = new TestableMSTestAdapterSettings(); - adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; - - string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); - - Assert.IsNotNull(result); - Assert.AreEqual(string.Compare(result, expectedResult, true), 0); - } - - [TestMethod] - public void ResolveEnvironmentVariableShouldReturnFalseForInvalidPath() - { - string path = @"Z:\Program Files (x86)\MsTest\Adapter"; - string baseDirectory = @"C:\unitTesting"; - - string result = new TestableMSTestAdapterSettings().ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory); - - Assert.IsNull(result); - } - - #endregion - - #region GetDirectoryListWithRecursiveProperty tests. - - [TestMethod] - public void GetDirectoryListWithRecursivePropertyShouldReadRunSettingCorrectly() - { - string baseDirectory = @"C:\unitTesting"; - - List expectedResult = new List(); - expectedResult.Add(new RecursiveDirectoryPath(@"C:\MsTest\Adapter", true)); - expectedResult.Add(new RecursiveDirectoryPath(@"C:\foo\unitTesting\MsTest\Adapter", false)); - - var adapterSettings = new TestableMSTestAdapterSettings(expectedResult); - adapterSettings.ExpandEnvironmentVariablesSetter = (str) => { return str.Replace("%temp%", "C:\\foo"); }; - adapterSettings.DoesDirectoryExistSetter = (str) => { return true; }; - - IList result = adapterSettings.GetDirectoryListWithRecursiveProperty(baseDirectory); - Assert.IsNotNull(result); - Assert.AreEqual(result.Count, 2); - - for (int i = 0; i < 2; i++) - { - Assert.AreEqual(string.Compare(result[i].DirectoryPath, expectedResult[i].DirectoryPath, StringComparison.OrdinalIgnoreCase), 0); - Assert.AreEqual(result[i].IncludeSubDirectories, expectedResult[i].IncludeSubDirectories); - } - } - - #endregion - - #region ToSettings tests. - - [TestMethod] - public void ToSettingsShouldNotThrowExceptionWhenRunSettingsXmlUnderTagMSTestv2IsWrong() - { - string runSettingxml = - @" - true - - - - - - true - false - "; - - StringReader stringReader = new StringReader(runSettingxml); - XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); - reader.Read(); - - MSTestAdapterSettings.ToSettings(reader); - } - - [TestMethod] - public void ToSettingsShouldThrowExceptionWhenRunSettingsXmlIsWrong() - { - string runSettingxml = - @" - - - - - - "; - - StringReader stringReader = new StringReader(runSettingxml); - XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); - reader.Read(); - - Action shouldThrowException = () => MSTestAdapterSettings.ToSettings(reader); - - ActionUtility.ActionShouldThrowExceptionOfType(shouldThrowException, typeof(SettingsException)); - } - - #endregion - - #region DeploymentEnabled tests. - - [TestMethod] - public void DeploymentEnabledIsByDefaultTrueWhenNotSpecified() - { - string runSettingxml = - @" - "; - StringReader stringReader = new StringReader(runSettingxml); - XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); - reader.Read(); - MSTestAdapterSettings adapterSettings = MSTestAdapterSettings.ToSettings(reader); - Assert.AreEqual(true, adapterSettings.DeploymentEnabled); - } - - [TestMethod] - public void DeploymentEnabledShouldBeConsumedFromRunSettingsWhenSpecified() - { - string runSettingxml = - @" - False - "; - StringReader stringReader = new StringReader(runSettingxml); - XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); - reader.Read(); - MSTestAdapterSettings adapterSettings = MSTestAdapterSettings.ToSettings(reader); - Assert.AreEqual(false, adapterSettings.DeploymentEnabled); - } - - #endregion - - #region DeployTestSourceDependencies tests - - [TestMethod] - public void DeployTestSourceDependenciesIsEnabledByDefault() - { - string runSettingxml = - @" - "; - StringReader stringReader = new StringReader(runSettingxml); - XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); - reader.Read(); - MSTestAdapterSettings adapterSettings = MSTestAdapterSettings.ToSettings(reader); - Assert.AreEqual(true, adapterSettings.DeployTestSourceDependencies); - } - - [TestMethod] - public void DeployTestSourceDependenciesWhenFalse() - { - string runSettingxml = - @" - False - "; - StringReader stringReader = new StringReader(runSettingxml); - XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); - reader.Read(); - MSTestAdapterSettings adapterSettings = MSTestAdapterSettings.ToSettings(reader); - Assert.AreEqual(false, adapterSettings.DeployTestSourceDependencies); - } - - [TestMethod] - public void DeployTestSourceDependenciesWhenTrue() - { - string runSettingxml = - @" - True - "; - StringReader stringReader = new StringReader(runSettingxml); - XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); - reader.Read(); - MSTestAdapterSettings adapterSettings = MSTestAdapterSettings.ToSettings(reader); - Assert.AreEqual(true, adapterSettings.DeployTestSourceDependencies); - } - - #endregion - } - - public class TestableMSTestAdapterSettings : MSTestAdapterSettings - { - public TestableMSTestAdapterSettings() - { - } - - public TestableMSTestAdapterSettings(List expectedResult) - { - this.SearchDirectories.AddRange(expectedResult); - } - - public Func DoesDirectoryExistSetter { get; set; } - - public Func ExpandEnvironmentVariablesSetter { get; set; } - - protected override bool DoesDirectoryExist(string path) - { - if (this.DoesDirectoryExistSetter == null) - { - return base.DoesDirectoryExist(path); - } - - return this.DoesDirectoryExistSetter(path); - } - - protected override string ExpandEnvironmentVariables(string path) - { - if (this.ExpandEnvironmentVariablesSetter == null) - { - return base.ExpandEnvironmentVariables(path); - } - - return this.ExpandEnvironmentVariablesSetter(path); - } - } -} diff --git a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/DeploymentItemUtilityNetCoreTests.cs b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/DeploymentItemUtilityNetCoreTests.cs deleted file mode 100644 index a56182be29..0000000000 --- a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/DeploymentItemUtilityNetCoreTests.cs +++ /dev/null @@ -1,461 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace MSTestAdapter.PlatformServices.Tests.Utilities -{ - using System.Collections.Generic; - using System.Linq; - using System.Reflection; - - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; - using Microsoft.VisualStudio.TestPlatform.ObjectModel; - - using Moq; - - using Microsoft.VisualStudio.TestTools.UnitTesting; - - [TestClass] - public class DeploymentItemUtilityTests - { - internal static readonly TestProperty DeploymentItemsProperty = TestProperty.Register( - "MSTestDiscoverer.DeploymentItems", - "DeploymentItems", - typeof(KeyValuePair[]), - TestPropertyAttributes.Hidden, - typeof(TestCase)); - - private Mock mockReflectionUtility; - private DeploymentItemUtility deploymentItemUtility; - private ICollection warnings; - - private string defaultDeploymentItemPath = @"c:\temp"; - private string defaultDeploymentItemOutputDirectory = "out"; - - [TestInitialize] - public void TestInit() - { - this.mockReflectionUtility = new Mock(); - this.deploymentItemUtility = new DeploymentItemUtility(this.mockReflectionUtility.Object); - this.warnings = new List(); - } - - #region GetClassLevelDeploymentItems tests - - [TestMethod] - public void GetClassLevelDeploymentItemsShouldReturnEmptyListWhenNoDeploymentItems() - { - var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems(typeof(DeploymentItemUtilityTests), this.warnings); - - Assert.IsNotNull(deploymentItems); - Assert.AreEqual(0, deploymentItems.Count); - } - - [TestMethod] - public void GetClassLevelDeploymentItemsShouldReturnADeploymentItem() - { - var kvpArray = new[] - { - new KeyValuePair( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory) - }; - this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), kvpArray); - - var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems(typeof(DeploymentItemUtilityTests), this.warnings); - var expectedDeploymentItems = new DeploymentItem[] - { - new DeploymentItem( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory) - }; - CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); - } - - [TestMethod] - public void GetClassLevelDeploymentItemsShouldReturnMoreThanOneDeploymentItems() - { - var deploymentItemAttributes = new[] - { - new KeyValuePair( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory), - new KeyValuePair( - this.defaultDeploymentItemPath + "\\temp2", - this.defaultDeploymentItemOutputDirectory) - }; - this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), deploymentItemAttributes); - - var deploymentItems = - this.deploymentItemUtility.GetClassLevelDeploymentItems( - typeof(DeploymentItemUtilityTests), - this.warnings); - - var expectedDeploymentItems = new DeploymentItem[] - { - new DeploymentItem( - deploymentItemAttributes[0].Key, - deploymentItemAttributes[0].Value), - new DeploymentItem( - deploymentItemAttributes[1].Key, - deploymentItemAttributes[1].Value) - }; - - CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); - } - - [TestMethod] - public void GetClassLevelDeploymentItemsShouldNotReturnDuplicateDeploymentItemEntries() - { - var deploymentItemAttributes = new[] - { - new KeyValuePair( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory), - new KeyValuePair( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory) - }; - this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), deploymentItemAttributes); - - var deploymentItems = - this.deploymentItemUtility.GetClassLevelDeploymentItems( - typeof(DeploymentItemUtilityTests), - this.warnings); - - var expectedDeploymentItems = new[] - { - new DeploymentItem( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory) - }; - - CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); - } - - [TestMethod] - public void GetClassLevelDeploymentItemsShouldReportWarningsForInvalidDeploymentItems() - { - var deploymentItemAttributes = new[] - { - new KeyValuePair( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory), - new KeyValuePair( - null, - this.defaultDeploymentItemOutputDirectory) - }; - this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), deploymentItemAttributes); - - var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems(typeof(DeploymentItemUtilityTests), this.warnings); - - var expectedDeploymentItems = new DeploymentItem[] - { - new DeploymentItem( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory) - }; - - CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); - Assert.AreEqual(1, this.warnings.Count); - StringAssert.Contains(this.warnings.ToArray()[0], Resource.DeploymentItemPathCannotBeNullOrEmpty); - } - -#endregion - - #region GetDeploymentItems tests - - [TestMethod] - public void GetDeploymentItemsShouldReturnNullOnNoDeploymentItems() - { - Assert.IsNull(this.deploymentItemUtility.GetDeploymentItems( - typeof(DeploymentItemUtilityTests).GetMethod("GetDeploymentItemsShouldReturnNullOnNoDeploymentItems"), - null, - this.warnings)); - } - - [TestMethod] - public void GetDeploymentItemsShouldReturnMethodLevelDeploymentItemsOnly() - { - var deploymentItemAttributes = new[] - { - new KeyValuePair( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory), - new KeyValuePair( - this.defaultDeploymentItemPath + "\\temp2", - this.defaultDeploymentItemOutputDirectory) - }; - var memberInfo = - typeof(DeploymentItemUtilityTests).GetMethod( - "GetDeploymentItemsShouldReturnNullOnNoDeploymentItems"); - - this.SetupDeploymentItems(memberInfo, deploymentItemAttributes); - - var deploymentItems = this.deploymentItemUtility.GetDeploymentItems( - memberInfo, - null, - this.warnings); - - CollectionAssert.AreEqual(deploymentItemAttributes, deploymentItems.ToArray()); - } - - [TestMethod] - public void GetDeploymentItemsShouldReturnClassLevelDeploymentItemsOnly() - { - // Arrange. - var classLevelDeploymentItems = new DeploymentItem[] - { - new DeploymentItem( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory), - new DeploymentItem( - this.defaultDeploymentItemPath + "\\temp2", - this.defaultDeploymentItemOutputDirectory) - }; - - // Act. - var deploymentItems = this.deploymentItemUtility.GetDeploymentItems( - typeof(DeploymentItemUtilityTests).GetMethod("GetDeploymentItemsShouldReturnNullOnNoDeploymentItems"), - classLevelDeploymentItems, - this.warnings); - - // Assert. - var expectedDeploymentItems = new[] - { - new KeyValuePair( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory), - new KeyValuePair( - this.defaultDeploymentItemPath + "\\temp2", - this.defaultDeploymentItemOutputDirectory) - }; - - CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); - } - - [TestMethod] - public void GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItems() - { - // Arrange. - var deploymentItemAttributes = new[] - { - new KeyValuePair( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory) - }; - var memberInfo = - typeof(DeploymentItemUtilityTests).GetMethod( - "GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItems"); - this.SetupDeploymentItems(memberInfo, deploymentItemAttributes); - - var classLevelDeploymentItems = new[] - { - new DeploymentItem( - this.defaultDeploymentItemPath + "\\temp2", - this.defaultDeploymentItemOutputDirectory) - }; - - // Act. - var deploymentItems = this.deploymentItemUtility.GetDeploymentItems( - memberInfo, - classLevelDeploymentItems, - this.warnings); - - // Assert. - var expectedDeploymentItems = new KeyValuePair[] - { - new KeyValuePair( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory), - new KeyValuePair( - this.defaultDeploymentItemPath + "\\temp2", - this.defaultDeploymentItemOutputDirectory) - }; - - CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); - } - - [TestMethod] - public void GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItemsWithoutDuplicates() - { - // Arrange. - var deploymentItemAttributes = new[] - { - new KeyValuePair( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory), - new KeyValuePair( - this.defaultDeploymentItemPath + "\\temp2", - this.defaultDeploymentItemOutputDirectory) - }; - var memberInfo = - typeof(DeploymentItemUtilityTests).GetMethod( - "GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItems"); - this.SetupDeploymentItems(memberInfo, deploymentItemAttributes); - - var classLevelDeploymentItems = new DeploymentItem[] - { - new DeploymentItem( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory), - new DeploymentItem( - this.defaultDeploymentItemPath + "\\temp1", - this.defaultDeploymentItemOutputDirectory) - }; - - // Act. - var deploymentItems = this.deploymentItemUtility.GetDeploymentItems( - memberInfo, - classLevelDeploymentItems, - this.warnings); - - // Assert. - var expectedDeploymentItems = new KeyValuePair[] - { - new KeyValuePair( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory), - new KeyValuePair( - this.defaultDeploymentItemPath + "\\temp2", - this.defaultDeploymentItemOutputDirectory), - new KeyValuePair( - this.defaultDeploymentItemPath + "\\temp1", - this.defaultDeploymentItemOutputDirectory) - }; - - CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); - } - - #endregion - - #region IsValidDeploymentItem tests - - [TestMethod] - public void IsValidDeploymentItemShouldReportWarningIfSourcePathIsNull() - { - string warning; - Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(null, this.defaultDeploymentItemOutputDirectory, out warning)); - - StringAssert.Contains(Resource.DeploymentItemPathCannotBeNullOrEmpty, warning); - } - - [TestMethod] - public void IsValidDeploymentItemShouldReportWarningIfSourcePathIsEmpty() - { - string warning; - Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(string.Empty, this.defaultDeploymentItemOutputDirectory, out warning)); - - StringAssert.Contains(Resource.DeploymentItemPathCannotBeNullOrEmpty, warning); - } - - [TestMethod] - public void IsValidDeploymentItemShouldReportWarningIfDeploymentOutputDirectoryIsNull() - { - string warning; - Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(this.defaultDeploymentItemPath, null, out warning)); - - StringAssert.Contains(Resource.DeploymentItemOutputDirectoryCannotBeNull, warning); - } - - [TestMethod] - public void IsValidDeploymentItemShouldReportWarningIfSourcePathHasInvalidCharacters() - { - string warning; - Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem("C:<>", this.defaultDeploymentItemOutputDirectory, out warning)); - - StringAssert.Contains( - string.Format( - Resource.DeploymentItemContainsInvalidCharacters, - "C:<>", - this.defaultDeploymentItemOutputDirectory), - warning); - } - - [TestMethod] - public void IsValidDeploymentItemShouldReportWarningIfOutputDirectoryHasInvalidCharacters() - { - string warning; - Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(this.defaultDeploymentItemPath, "<>", out warning)); - - StringAssert.Contains( - string.Format( - Resource.DeploymentItemContainsInvalidCharacters, - this.defaultDeploymentItemPath, - "<>"), - warning); - } - - [TestMethod] - public void IsValidDeploymentItemShouldReportWarningIfDeploymentOutputDirectoryIsRooted() - { - string warning; - Assert.IsFalse(this.deploymentItemUtility.IsValidDeploymentItem(this.defaultDeploymentItemPath, "C:\\temp", out warning)); - - StringAssert.Contains( - string.Format( - Resource.DeploymentItemOutputDirectoryMustBeRelative, - "C:\\temp"), - warning); - } - - [TestMethod] - public void IsValidDeploymentItemShouldReturnTrueForAValidDeploymentItem() - { - string warning; - Assert.IsTrue(this.deploymentItemUtility.IsValidDeploymentItem(this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory, out warning)); - - Assert.IsTrue(string.Empty.Equals(warning)); - } - #endregion - - #region HasDeployItems tests - - [TestMethod] - public void HasDeployItemsShouldReturnFalseForNoDeploymentItems() - { - TestCase testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A"); - testCase.SetPropertyValue(DeploymentItemsProperty, null); - - Assert.IsFalse(this.deploymentItemUtility.HasDeploymentItems(testCase)); - } - - [TestMethod] - public void HasDeployItemsShouldReturnTrueWhenDeploymentItemsArePresent() - { - TestCase testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A"); - var kvpArray = new[] - { - new KeyValuePair( - this.defaultDeploymentItemPath, - this.defaultDeploymentItemOutputDirectory) - }; - testCase.SetPropertyValue(DeploymentItemsProperty, kvpArray); - - Assert.IsTrue(this.deploymentItemUtility.HasDeploymentItems(testCase)); - } - - #endregion - - #region private methods - - private void SetupDeploymentItems(MemberInfo memberInfo, KeyValuePair[] deploymentItems) - { - var deploymentItemAttributes = new List(); - - foreach (var deploymentItem in deploymentItems) - { - deploymentItemAttributes.Add(new DeploymentItemAttribute(deploymentItem.Key, deploymentItem.Value)); - } - - this.mockReflectionUtility.Setup( - ru => - ru.GetCustomAttributes( - memberInfo, - typeof(DeploymentItemAttribute))).Returns((object[])deploymentItemAttributes.ToArray()); - } - - #endregion - } -} diff --git a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/DeploymentUtilityNetCoreTests.cs b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/NetCoreDeploymentUtilityTests.cs similarity index 60% rename from test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/DeploymentUtilityNetCoreTests.cs rename to test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/NetCoreDeploymentUtilityTests.cs index 1113ca745d..e72bceb2f6 100644 --- a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/DeploymentUtilityNetCoreTests.cs +++ b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/NetCoreDeploymentUtilityTests.cs @@ -15,9 +15,10 @@ namespace MSTestAdapter.PlatformServices.Tests.Utilities using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Moq; using Microsoft.VisualStudio.TestTools.UnitTesting; + using MSTestAdapter.PlatformServices.Tests.Utilities; [TestClass] - public class DeploymentUtilityTests + public class NetCoreDeploymentUtilityTests { private const string TestRunDirectory = "C:\\temp\\testRunDirectory"; private const string RootDeploymentDirectory = "C:\\temp\\testRunDirectory\\Deploy"; @@ -26,7 +27,6 @@ public class DeploymentUtilityTests private Mock mockReflectionUtility; private Mock mockFileUtility; - private Mock mockAssemblyUtility; private DeploymentUtility deploymentUtility; @@ -53,63 +53,6 @@ public void TestInit() this.mocktestExecutionRecorder = new Mock(); } - #region CreateDeploymentDirectories tests - - [TestMethod] - public void CreateDeploymentDirectoriesShouldCreateDeploymentDirectoryFromRunContext() - { - // Setup mocks - this.mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(TestRunDirectory); - this.mockFileUtility.Setup(fu => fu.GetNextIterationDirectoryName(TestRunDirectory, It.IsAny())) - .Returns(RootDeploymentDirectory); - - // Act. - this.deploymentUtility.CreateDeploymentDirectories(this.mockRunContext.Object); - - // Assert. - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(RootDeploymentDirectory), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix)), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentOutDirectorySuffix)), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix), Environment.MachineName)), Times.Once); - } - - [TestMethod] - public void CreateDeploymentDirectoriesShouldCreateDefaultDeploymentDirectoryIfTestRunDirectoryIsNull() - { - // Setup mocks - this.mockRunContext.Setup(rc => rc.TestRunDirectory).Returns((string)null); - this.mockFileUtility.Setup(fu => fu.GetNextIterationDirectoryName(It.Is(s => s.Contains(TestRunDirectories.DefaultDeploymentRootDirectory)), It.IsAny())) - .Returns(RootDeploymentDirectory); - - // Act. - this.deploymentUtility.CreateDeploymentDirectories(this.mockRunContext.Object); - - // Assert. - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(RootDeploymentDirectory), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix)), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentOutDirectorySuffix)), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix), Environment.MachineName)), Times.Once); - } - - [TestMethod] - public void CreateDeploymentDirectoriesShouldCreateDefaultDeploymentDirectoryIfRunContextIsNull() - { - // Setup mocks - this.mockFileUtility.Setup(fu => fu.GetNextIterationDirectoryName(It.Is(s => s.Contains(TestRunDirectories.DefaultDeploymentRootDirectory)), It.IsAny())) - .Returns(RootDeploymentDirectory); - - // Act. - this.deploymentUtility.CreateDeploymentDirectories(null); - - // Assert. - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(RootDeploymentDirectory), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix)), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentOutDirectorySuffix)), Times.Once); - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix), Environment.MachineName)), Times.Once); - } - - #endregion - #region Deploy tests [TestMethod] @@ -216,15 +159,20 @@ public void DeployShouldDeployContentsOfADirectoryIfSpecified() Times.Once); } - /* [TestMethod] + [TestMethod] public void DeployShouldDeployPdbWithSourceIfPdbFileIsPresentInSourceDirectory() { TestRunDirectories testRunDirectories; var testCase = this.GetTestCaseAndTestRunDirectories(DefaultDeploymentItemPath, DefaultDeploymentItemOutputDirectory, out testRunDirectories); // Setup mocks. + DeploymentItem sampleDepItem = new DeploymentItem(testCase.Source); + IList listOfFiles= new List { sampleDepItem }; + List listOfFilesInDir = new List() { testCase.Source }; + this.mockFileUtility.Setup(fu => fu.DoesDirectoryExist(It.Is(s => !s.EndsWith(".dll")))).Returns(true); this.mockFileUtility.Setup(fu => fu.DoesFileExist(It.IsAny())).Returns(true); + this.mockFileUtility.Setup(fu => fu.AddFilesFromDirectory(It.Is( s => s.Contains("netcore")), It.IsAny>(), It.IsAny())).Returns(listOfFilesInDir); string warning; this.mockFileUtility.Setup(fu => fu.CopyFileOverwrite(It.IsAny(), It.IsAny(), out warning)) .Returns( @@ -244,8 +192,8 @@ public void DeployShouldDeployPdbWithSourceIfPdbFileIsPresentInSourceDirectory() testRunDirectories)); // Assert. - var sourceFile = Assembly.GetEntryAssembly().GetName().Name + ".dll"; - var pdbFile = Assembly.GetEntryAssembly().GetName().Name + ".pdb"; + var sourceFile = typeof(DeploymentUtilityTests).GetTypeInfo().Assembly.GetName().Name + ".dll"; + var pdbFile = typeof(DeploymentUtilityTests).GetTypeInfo().Assembly.GetName().Name + ".pdb"; this.mockFileUtility.Verify( fu => fu.CopyFileOverwrite( @@ -262,63 +210,14 @@ public void DeployShouldDeployPdbWithSourceIfPdbFileIsPresentInSourceDirectory() Times.Once); } - [TestMethod] - public void DeployShouldNotDeployPdbFileOfAssemblyIfPdbFileIsNotPresentInAssemblyDirectory() - { - var dependencyFile = "C:\\temp\\dependency.dll"; - - // Path for pdb file of dependent assembly if pdb file is present. - var pdbFile = Path.ChangeExtension(dependencyFile, "pdb"); - - TestRunDirectories testRunDirectories; - var testCase = this.GetTestCaseAndTestRunDirectories(DefaultDeploymentItemPath, DefaultDeploymentItemOutputDirectory, out testRunDirectories); - - // Setup mocks. - this.mockFileUtility.Setup(fu => fu.DoesDirectoryExist(It.Is(s => !s.EndsWith(".dll")))).Returns(true); - this.mockFileUtility.Setup(fu => fu.DoesFileExist(It.IsAny())).Returns(true); - string warning; - this.mockFileUtility.Setup(fu => fu.CopyFileOverwrite(It.IsAny(), It.IsAny(), out warning)) - .Returns( - (string x, string y, string z) => - { - z = string.Empty; - return y; - }); - - // Act. - Assert.IsTrue( - this.deploymentUtility.Deploy( - new List { testCase }, - testCase.Source, - this.mockRunContext.Object, - this.mocktestExecutionRecorder.Object, - testRunDirectories)); - - // Assert. - this.mockFileUtility.Verify( - fu => - fu.CopyFileOverwrite( - It.Is(s => s.Contains(dependencyFile)), - Path.Combine(testRunDirectories.OutDirectory, Path.GetFileName(dependencyFile)), - out warning), - Times.Once); - - this.mockFileUtility.Verify( - fu => - fu.CopyFileOverwrite( - It.Is(s => s.Contains(pdbFile)), - Path.Combine(testRunDirectories.OutDirectory, Path.GetFileName(pdbFile)), - out warning), - Times.Never); - } */ - #endregion #region private methods private TestCase GetTestCaseAndTestRunDirectories(string deploymentItemPath, string defaultDeploymentItemOutputDirectoryout, out TestRunDirectories testRunDirectories) { - var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), Assembly.GetEntryAssembly().Location); + this.GetType(); + var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "D:\\testfx\\artifacts\\Debug\\PlatformServices.NetCore.Unit.Tests\\netcoreapp1.0\\MSTestAdapter.PlatformServices.NetCore.UnitTests.dll"); var kvpArray = new[] { new KeyValuePair( @@ -326,7 +225,7 @@ private TestCase GetTestCaseAndTestRunDirectories(string deploymentItemPath, str defaultDeploymentItemOutputDirectoryout) }; testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, kvpArray); - var currentExecutingFolder = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); + var currentExecutingFolder = Path.GetDirectoryName(typeof(DeploymentUtilityTests).GetTypeInfo().Assembly.Location); testRunDirectories = new TestRunDirectories(currentExecutingFolder); diff --git a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/ReflectionUtilityTestsNetCore.cs b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/ReflectionUtilityTestsNetCore.cs deleted file mode 100644 index 83b3e49b46..0000000000 --- a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/Utilities/ReflectionUtilityTestsNetCore.cs +++ /dev/null @@ -1,276 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace MSTestAdapter.PlatformServices.Tests.Utilities -{ - using System; - using System.Collections.Generic; - using System.Reflection; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; - using Microsoft.VisualStudio.TestTools.UnitTesting; - - [TestClass] - public class ReflectionUtilityTests - { - private ReflectionUtility reflectionUtility; - - public ReflectionUtilityTests() - { - this.reflectionUtility = new ReflectionUtility(); - } - - [TestMethod] - public void GetCustomAttributesShouldReturnAllAttributes() - { - var minfo = typeof(DummyBaseTestClass).GetMethod("DummyVTestMethod1"); - - var attribs = this.reflectionUtility.GetCustomAttributes(minfo, false); - - Assert.IsNotNull(attribs); - Assert.AreEqual(2, attribs.Length); - - var expectedAttribs = new string[] { "DummyA : base", "DummySingleA : base" }; - CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); - } - - [TestMethod] - public void GetCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance() - { - var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1"); - - var attribs = this.reflectionUtility.GetCustomAttributes(minfo, false); - - Assert.IsNotNull(attribs); - Assert.AreEqual(2, attribs.Length); - - var expectedAttribs = new string[] { "DummyA : derived", "DummySingleA : derived" }; - CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); - } - - [TestMethod] - public void GetCustomAttributesShouldReturnAllAttributesWithBaseInheritance() - { - var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1"); - - var attribs = this.reflectionUtility.GetCustomAttributes(minfo, true); - - Assert.IsNotNull(attribs); - Assert.AreEqual(3, attribs.Length); - - // Notice that the DummySingleA on the base method does not show up since it can only be defined once. - var expectedAttribs = new string[] { "DummyA : derived", "DummySingleA : derived", "DummyA : base", }; - CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); - } - - [TestMethod] - public void GetCustomAttributesOnTypeShouldReturnAllAttributes() - { - var tinfo = typeof(DummyBaseTestClass).GetTypeInfo(); - - var attribs = this.reflectionUtility.GetCustomAttributes(tinfo, false); - - Assert.IsNotNull(attribs); - Assert.AreEqual(1, attribs.Length); - - var expectedAttribs = new string[] { "DummyA : ba" }; - CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); - } - - [TestMethod] - public void GetCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBaseInheritance() - { - var tinfo = typeof(DummyTestClass).GetTypeInfo(); - - var attribs = this.reflectionUtility.GetCustomAttributes(tinfo, false); - - Assert.IsNotNull(attribs); - Assert.AreEqual(1, attribs.Length); - - var expectedAttribs = new string[] { "DummyA : a" }; - CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); - } - - [TestMethod] - public void GetCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritance() - { - var minfo = typeof(DummyTestClass).GetTypeInfo(); - - var attribs = this.reflectionUtility.GetCustomAttributes(minfo, true); - - Assert.IsNotNull(attribs); - Assert.AreEqual(2, attribs.Length); - - var expectedAttribs = new string[] { "DummyA : a", "DummyA : ba" }; - CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); - } - - [TestMethod] - public void GetSpecificCustomAttributesShouldReturnAllAttributes() - { - var minfo = typeof(DummyBaseTestClass).GetMethod("DummyVTestMethod1"); - - var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), false); - - Assert.IsNotNull(attribs); - Assert.AreEqual(1, attribs.Length); - - var expectedAttribs = new string[] { "DummyA : base" }; - CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); - } - - [TestMethod] - public void GetSpecificCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance() - { - var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1"); - - var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), false); - - Assert.IsNotNull(attribs); - Assert.AreEqual(1, attribs.Length); - - var expectedAttribs = new string[] { "DummyA : derived" }; - CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); - } - - [TestMethod] - public void GetSpecificCustomAttributesShouldReturnAllAttributesWithBaseInheritance() - { - var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1"); - - var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), true); - - Assert.IsNotNull(attribs); - Assert.AreEqual(2, attribs.Length); - - var expectedAttribs = new string[] { "DummyA : derived", "DummyA : base", }; - CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); - } - - [TestMethod] - public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributes() - { - var tinfo = typeof(DummyBaseTestClass).GetTypeInfo(); - - var attribs = this.reflectionUtility.GetCustomAttributes(tinfo, typeof(DummyAAttribute), false); - - Assert.IsNotNull(attribs); - Assert.AreEqual(1, attribs.Length); - - var expectedAttribs = new string[] { "DummyA : ba" }; - CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); - } - - [TestMethod] - public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBaseInheritance() - { - var tinfo = typeof(DummyTestClass).GetTypeInfo(); - - var attribs = this.reflectionUtility.GetCustomAttributes(tinfo, typeof(DummyAAttribute), false); - - Assert.IsNotNull(attribs); - Assert.AreEqual(1, attribs.Length); - - var expectedAttribs = new string[] { "DummyA : a" }; - CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); - } - - [TestMethod] - public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritance() - { - var minfo = typeof(DummyTestClass).GetTypeInfo(); - - var attribs = this.reflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), true); - - Assert.IsNotNull(attribs); - Assert.AreEqual(2, attribs.Length); - - var expectedAttribs = new string[] { "DummyA : a", "DummyA : ba" }; - CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); - } - - [TestMethod] - public void GetSpecificCustomAttributesOnAssemblyShouldReturnAllAttributes() - { - var asm = typeof(DummyTestClass).GetTypeInfo().Assembly; - - var attribs = this.reflectionUtility.GetCustomAttributes(asm, typeof(DummyAAttribute)); - - Assert.IsNotNull(attribs); - Assert.AreEqual(2, attribs.Length); - - var expectedAttribs = new string[] { "DummyA : a1", "DummyA : a2" }; - CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs)); - } - - internal static string[] GetAttributeValuePairs(object[] attributes) - { - var attribValuePairs = new List(); - foreach (var attrib in attributes) - { - if (attrib is DummySingleAAttribute) - { - var a = attrib as DummySingleAAttribute; - attribValuePairs.Add("DummySingleA : " + a.Value); - } - else if (attrib is DummyAAttribute) - { - var a = attrib as DummyAAttribute; - attribValuePairs.Add("DummyA : " + a.Value); - } - } - - return attribValuePairs.ToArray(); - } - - [DummyA("ba")] - public class DummyBaseTestClass - { - [DummyA("base")] - [DummySingleA("base")] - public virtual void DummyVTestMethod1() - { - } - - public void DummyBTestMethod2() - { - } - } - - [DummyA("a")] - public class DummyTestClass : DummyBaseTestClass - { - [DummyA("derived")] - [DummySingleA("derived")] - public override void DummyVTestMethod1() - { - } - - [DummySingleA("derived")] - public void DummyTestMethod2() - { - } - } - - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = true)] - public sealed class DummyAAttribute : Attribute - { - public DummyAAttribute(string foo) - { - this.Value = foo; - } - - public string Value { get; set; } - } - - [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class | AttributeTargets.Assembly, AllowMultiple = false)] - public class DummySingleAAttribute : Attribute - { - public DummySingleAAttribute(string foo) - { - this.Value = foo; - } - - public string Value { get; set; } - } - } -} diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/MSTestAdapterSettingsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs similarity index 96% rename from test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/MSTestAdapterSettingsTests.cs rename to test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs index e7cd44a483..087494c784 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/MSTestAdapterSettingsTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs @@ -3,9 +3,19 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests { +#if NETCOREAPP1_0 + using Microsoft.VisualStudio.TestTools.UnitTesting; +#else extern alias FrameworkV1; extern alias FrameworkV2; + using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; + using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert; + using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; + using TestCleanup = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute; + using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; +#endif + using System; using System.Collections.Generic; using System.IO; @@ -16,14 +26,11 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; using TestUtilities; - using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; - using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert; - using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; - using TestCleanup = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute; - using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; - [TestClass] +#pragma warning disable SA1649 // File name must match first type name public class MSTestAdapterSettingsTests + +#pragma warning restore SA1649 // File name must match first type name { [TestCleanup] public void Cleanup() @@ -31,7 +38,7 @@ public void Cleanup() MSTestSettingsProvider.Reset(); } - #region ResolveEnvironmentVariableAndReturnFullPathIfExist tests. +#region ResolveEnvironmentVariableAndReturnFullPathIfExist tests. [TestMethod] public void ResolveEnvironmentVariableShouldResolvePathWhenPassedAbsolutePath() @@ -107,7 +114,7 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePath() // instead of returning "C:\unitTesting\MsTest\Adapter", it will return "(Drive from where test is running):\MsTest\Adapter", // because path is starting with "\" // this is how Path.GetFullPath works - string currentDirectory = Environment.CurrentDirectory; + string currentDirectory = Directory.GetCurrentDirectory(); string currentDrive = currentDirectory.Split('\\').First() + "\\"; string expectedResult = Path.Combine(currentDrive, @"MsTest\Adapter"); @@ -148,9 +155,9 @@ public void ResolveEnvironmentVariableShouldReturnFalseForInvalidPath() Assert.IsNull(result); } - #endregion +#endregion - #region GetDirectoryListWithRecursiveProperty tests. +#region GetDirectoryListWithRecursiveProperty tests. [TestMethod] public void GetDirectoryListWithRecursivePropertyShouldReadRunSettingCorrectly() @@ -176,9 +183,9 @@ public void GetDirectoryListWithRecursivePropertyShouldReadRunSettingCorrectly() } } - #endregion +#endregion - #region ToSettings tests. +#region ToSettings tests. [TestMethod] public void ToSettingsShouldNotThrowExceptionWhenRunSettingsXmlUnderTagMSTestv2IsWrong() @@ -223,9 +230,9 @@ public void ToSettingsShouldThrowExceptionWhenRunSettingsXmlIsWrong() ActionUtility.ActionShouldThrowExceptionOfType(shouldThrowException, typeof(SettingsException)); } - #endregion +#endregion - #region DeploymentEnabled tests. +#region DeploymentEnabled tests. [TestMethod] public void DeploymentEnabledIsByDefaultTrueWhenNotSpecified() @@ -254,9 +261,9 @@ public void DeploymentEnabledShouldBeConsumedFromRunSettingsWhenSpecified() Assert.AreEqual(false, adapterSettings.DeploymentEnabled); } - #endregion +#endregion - #region DeployTestSourceDependencies tests +#region DeployTestSourceDependencies tests [TestMethod] public void DeployTestSourceDependenciesIsEnabledByDefault() @@ -299,7 +306,7 @@ public void DeployTestSourceDependenciesWhenTrue() Assert.AreEqual(true, adapterSettings.DeployTestSourceDependencies); } - #endregion +#endregion } public class TestableMSTestAdapterSettings : MSTestAdapterSettings diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10DeploymentUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10DeploymentUtilityTests.cs new file mode 100644 index 0000000000..73ac328b16 --- /dev/null +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10DeploymentUtilityTests.cs @@ -0,0 +1,126 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace MSTestAdapter.PlatformServices.Tests.Utilities +{ +#if NETCOREAPP1_0 + using Microsoft.VisualStudio.TestTools.UnitTesting; +#else + extern alias FrameworkV1; + extern alias FrameworkV2; + + using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; + using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; + using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute; + using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; +#endif + + using System; + using System.Collections.Generic; + using System.IO; + using System.Reflection; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; + using Moq; + + [TestClass] +#pragma warning disable SA1649 // File name must match first type name + public class DeploymentUtilityTests +#pragma warning restore SA1649 // File name must match first type name + { + private const string TestRunDirectory = "C:\\temp\\testRunDirectory"; + private const string RootDeploymentDirectory = "C:\\temp\\testRunDirectory\\Deploy"; + private const string DefaultDeploymentItemPath = @"c:\temp"; + private const string DefaultDeploymentItemOutputDirectory = "out"; + + private Mock mockReflectionUtility; + private Mock mockFileUtility; + + private Mock mockAssemblyUtility; + + private DeploymentUtility deploymentUtility; + + private Mock mockRunContext; + private Mock mocktestExecutionRecorder; + + private IList warnings; + + [TestInitialize] + public void TestInit() + { + this.mockReflectionUtility = new Mock(); + this.mockFileUtility = new Mock(); + this.mockAssemblyUtility = new Mock(); + this.warnings = new List(); + + this.deploymentUtility = new DeploymentUtility( + new DeploymentItemUtility(this.mockReflectionUtility.Object), + this.mockAssemblyUtility.Object, + this.mockFileUtility.Object); + + this.mockRunContext = new Mock(); + this.mocktestExecutionRecorder = new Mock(); + } + +#region CreateDeploymentDirectories tests + + [TestMethod] + public void CreateDeploymentDirectoriesShouldCreateDeploymentDirectoryFromRunContext() + { + // Setup mocks + this.mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(TestRunDirectory); + this.mockFileUtility.Setup(fu => fu.GetNextIterationDirectoryName(TestRunDirectory, It.IsAny())) + .Returns(RootDeploymentDirectory); + + // Act. + this.deploymentUtility.CreateDeploymentDirectories(this.mockRunContext.Object); + + // Assert. + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(RootDeploymentDirectory), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix)), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentOutDirectorySuffix)), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix), Environment.MachineName)), Times.Once); + } + + [TestMethod] + public void CreateDeploymentDirectoriesShouldCreateDefaultDeploymentDirectoryIfTestRunDirectoryIsNull() + { + // Setup mocks + this.mockRunContext.Setup(rc => rc.TestRunDirectory).Returns((string)null); + this.mockFileUtility.Setup(fu => fu.GetNextIterationDirectoryName(It.Is(s => s.Contains(TestRunDirectories.DefaultDeploymentRootDirectory)), It.IsAny())) + .Returns(RootDeploymentDirectory); + + // Act. + this.deploymentUtility.CreateDeploymentDirectories(this.mockRunContext.Object); + + // Assert. + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(RootDeploymentDirectory), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix)), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentOutDirectorySuffix)), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix), Environment.MachineName)), Times.Once); + } + + [TestMethod] + public void CreateDeploymentDirectoriesShouldCreateDefaultDeploymentDirectoryIfRunContextIsNull() + { + // Setup mocks + this.mockFileUtility.Setup(fu => fu.GetNextIterationDirectoryName(It.Is(s => s.Contains(TestRunDirectories.DefaultDeploymentRootDirectory)), It.IsAny())) + .Returns(RootDeploymentDirectory); + + // Act. + this.deploymentUtility.CreateDeploymentDirectories(null); + + // Assert. + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(RootDeploymentDirectory), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix)), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentOutDirectorySuffix)), Times.Once); + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix), Environment.MachineName)), Times.Once); + } + +#endregion + } +} diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs index 10987342c1..ad1f0b2ca1 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs @@ -18,7 +18,7 @@ namespace MSTestAdapter.PlatformServices.Tests.Services using System.IO; using System.Reflection; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; - using MSTestAdapter.TestUtilities; + using MSTestAdapter.TestUtilities; #pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName [TestClass] diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs index e1a2b5ee4b..e2601733fb 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs @@ -21,13 +21,13 @@ namespace MSTestAdapter.PlatformServices.Tests.Services [TestClass] public class SettingsProviderTests { - /* [TestMethod] + [TestMethod] public void GetPropertiesShouldReturnEmptyDictionary() { MSTestSettingsProvider settings = new MSTestSettingsProvider(); - Assert.AreEqual(0, settings.GetProperties(It.IsAny()).Count); - } */ + Assert.AreEqual(0, settings.GetProperties(null).Count); + } } #pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopSettingsProviderTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13MSTestSettingsProviderTests.cs similarity index 93% rename from test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopSettingsProviderTests.cs rename to test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13MSTestSettingsProviderTests.cs index a314ae8594..f8951d2621 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopSettingsProviderTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13MSTestSettingsProviderTests.cs @@ -3,9 +3,18 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Services { +#if NETCOREAPP1_0 + using Microsoft.VisualStudio.TestTools.UnitTesting; +#else extern alias FrameworkV1; extern alias FrameworkV2; + using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; + using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; + using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute; + using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; +#endif + using System; using System.IO; using System.Xml; @@ -15,13 +24,10 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Services using MSTestAdapter.TestUtilities; - using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; - using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; - using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute; - using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; - [TestClass] +#pragma warning disable SA1649 // File name must match first type name public class DesktopSettingsProviderTests +#pragma warning restore SA1649 // File name must match first type name { private MSTestSettingsProvider settingsProvider; diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentItemUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs similarity index 95% rename from test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentItemUtilityTests.cs rename to test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs index 59bd405eef..67f4480fef 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Utilities/DeploymentItemUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs @@ -1,11 +1,24 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Utilities +namespace MSTestAdapter.PlatformServices.Tests.Utilities { + extern alias FrameworkV2Extension; + +#if NETCOREAPP1_0 + using Microsoft.VisualStudio.TestTools.UnitTesting; +#else extern alias FrameworkV1; extern alias FrameworkV2; - extern alias FrameworkV2DesktopExtension; + + using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; + using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert; + using StringAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert; + using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; + using TestFrameworkV2 = FrameworkV2::Microsoft.VisualStudio.TestTools.UnitTesting; + using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute; + using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; +#endif using System.Collections.Generic; using System.Linq; @@ -18,17 +31,14 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Utilities using Moq; - using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; - using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert; - using StringAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert; - using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; - using TestFrameworkV2 = FrameworkV2::Microsoft.VisualStudio.TestTools.UnitTesting; - using TestFrameworkV2Extension = FrameworkV2DesktopExtension::Microsoft.VisualStudio.TestTools.UnitTesting; - using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute; - using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; + using TestFrameworkV2Extension = FrameworkV2Extension::Microsoft.VisualStudio.TestTools.UnitTesting; + // using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute; + // using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; [TestClass] +#pragma warning disable SA1649 // File name must match first type name public class DeploymentItemUtilityTests +#pragma warning restore SA1649 // File name must match first type name { internal static readonly TestProperty DeploymentItemsProperty = TestProperty.Register( "MSTestDiscoverer.DeploymentItems", @@ -52,7 +62,7 @@ public void TestInit() this.warnings = new List(); } - #region GetClassLevelDeploymentItems tests +#region GetClassLevelDeploymentItems tests [TestMethod] public void GetClassLevelDeploymentItemsShouldReturnEmptyListWhenNoDeploymentItems() @@ -72,7 +82,7 @@ public void GetClassLevelDeploymentItemsShouldReturnADeploymentItem() this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory) }; - this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests), kvpArray); + this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), kvpArray); var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems(typeof(DeploymentItemUtilityTests), this.warnings); var expectedDeploymentItems = new DeploymentItem[] @@ -96,7 +106,7 @@ public void GetClassLevelDeploymentItemsShouldReturnMoreThanOneDeploymentItems() this.defaultDeploymentItemPath + "\\temp2", this.defaultDeploymentItemOutputDirectory) }; - this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests), deploymentItemAttributes); + this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), deploymentItemAttributes); var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems( @@ -128,7 +138,7 @@ public void GetClassLevelDeploymentItemsShouldNotReturnDuplicateDeploymentItemEn this.defaultDeploymentItemPath, this.defaultDeploymentItemOutputDirectory) }; - this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests), deploymentItemAttributes); + this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), deploymentItemAttributes); var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems( @@ -157,7 +167,7 @@ public void GetClassLevelDeploymentItemsShouldReportWarningsForInvalidDeployment null, this.defaultDeploymentItemOutputDirectory) }; - this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests), deploymentItemAttributes); + this.SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), deploymentItemAttributes); var deploymentItems = this.deploymentItemUtility.GetClassLevelDeploymentItems(typeof(DeploymentItemUtilityTests), this.warnings); @@ -170,12 +180,12 @@ public void GetClassLevelDeploymentItemsShouldReportWarningsForInvalidDeployment CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); Assert.AreEqual(1, this.warnings.Count); - TestFrameworkV2.StringAssert.Contains(this.warnings.ToArray()[0], Resource.DeploymentItemPathCannotBeNullOrEmpty); + StringAssert.Contains(this.warnings.ToArray()[0], Resource.DeploymentItemPathCannotBeNullOrEmpty); } #endregion - #region GetDeploymentItems tests +#region GetDeploymentItems tests [TestMethod] public void GetDeploymentItemsShouldReturnNullOnNoDeploymentItems() @@ -339,9 +349,9 @@ public void GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItemsWith CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); } - #endregion +#endregion - #region IsValidDeploymentItem tests +#region IsValidDeploymentItem tests [TestMethod] public void IsValidDeploymentItemShouldReportWarningIfSourcePathIsNull() @@ -419,9 +429,9 @@ public void IsValidDeploymentItemShouldReturnTrueForAValidDeploymentItem() Assert.IsTrue(string.Empty.Equals(warning)); } - #endregion +#endregion - #region HasDeployItems tests +#region HasDeployItems tests [TestMethod] public void HasDeployItemsShouldReturnFalseForNoDeploymentItems() @@ -447,9 +457,9 @@ public void HasDeployItemsShouldReturnTrueWhenDeploymentItemsArePresent() Assert.IsTrue(this.deploymentItemUtility.HasDeploymentItems(testCase)); } - #endregion +#endregion - #region private methods +#region private methods private void SetupDeploymentItems(MemberInfo memberInfo, KeyValuePair[] deploymentItems) { @@ -467,6 +477,6 @@ private void SetupDeploymentItems(MemberInfo memberInfo, KeyValuePair(); From 62649d566767351b19be0baf279a5c751172685e Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Tue, 12 Mar 2019 15:21:06 +0530 Subject: [PATCH 08/24] E2E and test context --- .../PlatformServices.NetCore.csproj | 4 +- .../Services/ns10TestContextImplementation.cs | 5 + .../Services/ns10TestContextImplementation.cs | 285 +++++++++++++ .../Services/ns13TestContextImplementation.cs | 391 ++++++++++++++++++ .../Services/ns13TestSourceHost.cs | 134 ++++++ .../Extension.Core/Extension.Core.csproj | 2 +- .../Extension.Core/TestContext.cs | 132 ++++++ .../Automation.CLI/Automation.CLI.csproj | 27 +- .../Smoke.E2E.Tests/DeploymentTests.cs | 11 +- .../DeploymentTestProject.csproj | 2 +- .../DeploymentFile.xml | 2 + .../DeploymentTestProjectNetCore.cs | 30 ++ .../DeploymentTestProjectNetCore.csproj | 31 ++ .../EmptyDataFile.xml | 2 + .../TestCaseDeploymentFile.xml | 2 + 15 files changed, 1044 insertions(+), 16 deletions(-) create mode 100644 src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns10TestContextImplementation.cs create mode 100644 src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestContextImplementation.cs create mode 100644 src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestSourceHost.cs create mode 100644 src/TestFramework/Extension.Core/TestContext.cs create mode 100644 test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentFile.xml create mode 100644 test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.cs create mode 100644 test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj create mode 100644 test/E2ETests/TestAssets/DeploymentTestProjectNetCore/EmptyDataFile.xml create mode 100644 test/E2ETests/TestAssets/DeploymentTestProjectNetCore/TestCaseDeploymentFile.xml diff --git a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj index 2647d02572..e8d905c9ff 100644 --- a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj +++ b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj @@ -23,10 +23,8 @@ - - @@ -35,7 +33,9 @@ + + diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextImplementation.cs b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextImplementation.cs index 48d1ffd431..efe1eecf99 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextImplementation.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextImplementation.cs @@ -259,6 +259,11 @@ public void SetDataConnection(object dbConnection) #endregion + public override void AddResultFile(string fileName) + { + throw new NotImplementedException(); + } + /// /// Helper to safely fetch a property value. /// diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns10TestContextImplementation.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns10TestContextImplementation.cs new file mode 100644 index 0000000000..ed341ce37b --- /dev/null +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns10TestContextImplementation.cs @@ -0,0 +1,285 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices +{ + using System; + using System.Collections.Generic; + using System.Diagnostics; + using System.Globalization; + using System.IO; + + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel; + + using UTF = Microsoft.VisualStudio.TestTools.UnitTesting; + +#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName + + /// + /// Internal implementation of TestContext exposed to the user. + /// + /// + /// The virtual string properties of the TestContext are retreived from the property dictionary + /// like GetProperty<string>("TestName") or GetProperty<string>("FullyQualifiedTestClassName"); + /// + public class TestContextImplementation : UTF.TestContext, ITestContext + { + private static readonly string FullyQualifiedTestClassNameLabel = "FullyQualifiedTestClassName"; + private static readonly string TestNameLabel = "TestName"; + + /// + /// Properties + /// + private IDictionary properties; + + /// + /// Unit test outcome + /// + private UTF.UnitTestOutcome outcome; + + /// + /// Test Method + /// + private ITestMethod testMethod; + + private StringWriter stringWriter; + private bool stringWriterDisposed; + + /// + /// Initializes a new instance of the class. + /// + /// The test method. + /// A writer for logging. + /// The properties. + public TestContextImplementation(ITestMethod testMethod, StringWriter writer, IDictionary properties) + { + Debug.Assert(testMethod != null, "TestMethod is not null"); + Debug.Assert(properties != null, "properties is not null"); + + this.testMethod = testMethod; + this.properties = new Dictionary(properties); + this.stringWriter = writer; + this.InitializeProperties(); + } + + #region TestContext impl + + // Summary: + // You can use this property in a TestCleanup method to determine the outcome + // of a test that has run. + // + // Returns: + // A Microsoft.VisualStudio.TestTools.UnitTesting.UnitTestOutcome that states + // the outcome of a test that has run. + public override UTF.UnitTestOutcome CurrentTestOutcome + { + get + { + return this.outcome; + } + } + + /// + /// Gets fully-qualified name of the class containing the test method currently being executed + /// + /// + /// This property can be useful in attributes derived from ExpectedExceptionBaseAttribute. + /// Those attributes have access to the test context, and provide messages that are included + /// in the test results. Users can benefit from messages that include the fully-qualified + /// class name in addition to the name of the test method currently being executed. + /// + public override string FullyQualifiedTestClassName + { + get + { + return this.GetPropertyValue(FullyQualifiedTestClassNameLabel) as string; + } + } + + /// + /// Gets name of the test method currently being executed + /// + public override string TestName + { + get + { + return this.GetPropertyValue(TestNameLabel) as string; + } + } + + /// + /// Gets the test properties when overridden in a derived class. + /// + /// + /// An System.Collections.IDictionary object that contains key/value pairs that + /// represent the test properties. + /// + public override IDictionary Properties + { + get + { + return this.properties as IDictionary; + } + } + + public UTF.TestContext Context + { + get + { + return this as UTF.TestContext; + } + } + + /// + /// Set the unit-test outcome + /// + /// The test outcome. + public void SetOutcome(UTF.UnitTestOutcome outcome) + { + this.outcome = outcome; + } + + /// + /// Returns whether property with parameter name is present or not + /// + /// The property name. + /// Property value. + /// True if property with parameter name is present. + public bool TryGetPropertyValue(string propertyName, out object propertyValue) + { + if (this.properties == null) + { + propertyValue = null; + return false; + } + + return this.properties.TryGetValue(propertyName, out propertyValue); + } + + /// + /// Adds the parameter name/value pair to property bag + /// + /// The property name. + /// Property value. + public void AddProperty(string propertyName, string propertyValue) + { + if (this.properties == null) + { + this.properties = new Dictionary(); + } + + this.properties.Add(propertyName, propertyValue); + } + + /// + /// Returning null as this feature is not supported in ASP .net and UWP + /// + /// List of result files. Null presently. + public IList GetResultFiles() + { + return null; + } + + /// + /// When overridden in a derived class, used to write trace messages while the + /// test is running. + /// + /// The formatted string that contains the trace message. + public override void WriteLine(string message) + { + if (this.stringWriterDisposed) + { + return; + } + + try + { + var msg = message?.Replace("\0", "\\0"); + this.stringWriter.WriteLine(msg); + } + catch (ObjectDisposedException) + { + this.stringWriterDisposed = true; + } + } + + /// + /// When overridden in a derived class, used to write trace messages while the + /// test is running. + /// + /// The string that contains the trace message. + /// Arguments to add to the trace message. + public override void WriteLine(string format, params object[] args) + { + if (this.stringWriterDisposed) + { + return; + } + + try + { + string message = string.Format(CultureInfo.CurrentCulture, format?.Replace("\0", "\\0"), args); + this.stringWriter.WriteLine(message); + } + catch (ObjectDisposedException) + { + this.stringWriterDisposed = true; + } + } + + /// + /// Gets messages from the testContext writeLines + /// + /// The test context messages added so far. + public string GetDiagnosticMessages() + { + return this.stringWriter.ToString(); + } + + /// + /// Clears the previous testContext writeline messages. + /// + public void ClearDiagnosticMessages() + { + var sb = this.stringWriter.GetStringBuilder(); + sb.Remove(0, sb.Length); + } + + public void SetDataRow(object dataRow) + { + // Do nothing. + } + + public void SetDataConnection(object dbConnection) + { + // Do nothing. + } + + #endregion + + /// + /// Helper to safely fetch a property value. + /// + /// Property Name + /// Property value + private object GetPropertyValue(string propertyName) + { + object propertyValue = null; + this.properties.TryGetValue(propertyName, out propertyValue); + + return propertyValue; + } + + /// + /// Helper to initialize the properties. + /// + private void InitializeProperties() + { + this.properties[FullyQualifiedTestClassNameLabel] = this.testMethod.FullClassName; + this.properties[TestNameLabel] = this.testMethod.Name; + } + } + +#pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName +} diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestContextImplementation.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestContextImplementation.cs new file mode 100644 index 0000000000..460286302b --- /dev/null +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestContextImplementation.cs @@ -0,0 +1,391 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices +{ + using System; + using System.Collections; + using System.Collections.Generic; + using System.Diagnostics; + using System.Diagnostics.CodeAnalysis; + using System.Globalization; + using System.IO; + + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel; + + using UTF = Microsoft.VisualStudio.TestTools.UnitTesting; + +#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName + + /// + /// Internal implementation of TestContext exposed to the user. + /// + /// + /// The virtual string properties of the TestContext are retreived from the property dictionary + /// like GetProperty<string>("TestName") or GetProperty<string>("FullyQualifiedTestClassName"); + /// + public class TestContextImplementation : UTF.TestContext, ITestContext + { + private static readonly string FullyQualifiedTestClassNameLabel = "FullyQualifiedTestClassName"; + private static readonly string TestNameLabel = "TestName"; + + /// + /// List of result files associated with the test + /// + private IList testResultFiles; + + /// + /// Properties + /// + private IDictionary properties; + + /// + /// Unit test outcome + /// + private UTF.UnitTestOutcome outcome; + + /// + /// Test Method + /// + private ITestMethod testMethod; + + private StringWriter stringWriter; + private bool stringWriterDisposed; + + /// + /// Initializes a new instance of the class. + /// + /// The test method. + /// A writer for logging. + /// The properties. + public TestContextImplementation(ITestMethod testMethod, StringWriter writer, IDictionary properties) + { + Debug.Assert(testMethod != null, "TestMethod is not null"); + Debug.Assert(properties != null, "properties is not null"); + + this.testMethod = testMethod; + this.properties = new Dictionary(properties); + this.stringWriter = writer; + this.InitializeProperties(); + this.testResultFiles = new List(); + } + + #region TestContext impl + + // Summary: + // You can use this property in a TestCleanup method to determine the outcome + // of a test that has run. + // + // Returns: + // A Microsoft.VisualStudio.TestTools.UnitTesting.UnitTestOutcome that states + // the outcome of a test that has run. + public override UTF.UnitTestOutcome CurrentTestOutcome + { + get + { + return this.outcome; + } + } + + /// + public override string TestRunDirectory + { + get + { + return this.GetStringPropertyValue(TestContextPropertyStrings.TestRunDirectory); + } + } + + /// + public override string DeploymentDirectory + { + get + { + return this.GetStringPropertyValue(TestContextPropertyStrings.DeploymentDirectory); + } + } + + /// + public override string ResultsDirectory + { + get + { + return this.GetStringPropertyValue(TestContextPropertyStrings.ResultsDirectory); + } + } + + /// + public override string TestRunResultsDirectory + { + get + { + return this.GetStringPropertyValue(TestContextPropertyStrings.TestRunResultsDirectory); + } + } + + /// + [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", Justification = "TestResultsDirectory is what we need.")] + public override string TestResultsDirectory + { + get + { + // In MSTest, it is actually "In\697105f7-004f-42e8-bccf-eb024870d3e9\User1", but + // we are setting it to "In" only because MSTest does not create this directory. + return this.GetStringPropertyValue(TestContextPropertyStrings.TestResultsDirectory); + } + } + + /// + public override string TestDir + { + get + { + return this.GetStringPropertyValue(TestContextPropertyStrings.TestDir); + } + } + + /// + public override string TestDeploymentDir + { + get + { + return this.GetStringPropertyValue(TestContextPropertyStrings.TestDeploymentDir); + } + } + + /// + public override string TestLogsDir + { + get + { + return this.GetStringPropertyValue(TestContextPropertyStrings.TestLogsDir); + } + } + + /// + /// Gets fully-qualified name of the class containing the test method currently being executed + /// + /// + /// This property can be useful in attributes derived from ExpectedExceptionBaseAttribute. + /// Those attributes have access to the test context, and provide messages that are included + /// in the test results. Users can benefit from messages that include the fully-qualified + /// class name in addition to the name of the test method currently being executed. + /// + public override string FullyQualifiedTestClassName + { + get + { + return this.GetPropertyValue(FullyQualifiedTestClassNameLabel) as string; + } + } + + /// + /// Gets name of the test method currently being executed + /// + public override string TestName + { + get + { + return this.GetPropertyValue(TestNameLabel) as string; + } + } + + /// + /// Gets the test properties when overridden in a derived class. + /// + /// + /// An System.Collections.IDictionary object that contains key/value pairs that + /// represent the test properties. + /// + public override IDictionary Properties + { + get + { + return this.properties as IDictionary; + } + } + + public UTF.TestContext Context + { + get + { + return this as UTF.TestContext; + } + } + + /// + public override void AddResultFile(string fileName) + { + if (string.IsNullOrEmpty(fileName)) + { + throw new ArgumentException(Resource.Common_CannotBeNullOrEmpty, "fileName"); + } + + this.testResultFiles.Add(Path.GetFullPath(fileName)); + } + + /// + /// Set the unit-test outcome + /// + /// The test outcome. + public void SetOutcome(UTF.UnitTestOutcome outcome) + { + this.outcome = outcome; + } + + /// + /// Returns whether property with parameter name is present or not + /// + /// The property name. + /// Property value. + /// True if property with parameter name is present. + public bool TryGetPropertyValue(string propertyName, out object propertyValue) + { + if (this.properties == null) + { + propertyValue = null; + return false; + } + + return this.properties.TryGetValue(propertyName, out propertyValue); + } + + /// + /// Adds the parameter name/value pair to property bag + /// + /// The property name. + /// Property value. + public void AddProperty(string propertyName, string propertyValue) + { + if (this.properties == null) + { + this.properties = new Dictionary(); + } + + this.properties.Add(propertyName, propertyValue); + } + + /// + /// Returning null as this feature is not supported in ASP .net and UWP + /// + /// List of result files. Null presently. + public IList GetResultFiles() + { + return null; + } + + /// + /// When overridden in a derived class, used to write trace messages while the + /// test is running. + /// + /// The formatted string that contains the trace message. + public override void WriteLine(string message) + { + if (this.stringWriterDisposed) + { + return; + } + + try + { + var msg = message?.Replace("\0", "\\0"); + this.stringWriter.WriteLine(msg); + } + catch (ObjectDisposedException) + { + this.stringWriterDisposed = true; + } + } + + /// + /// When overridden in a derived class, used to write trace messages while the + /// test is running. + /// + /// The string that contains the trace message. + /// Arguments to add to the trace message. + public override void WriteLine(string format, params object[] args) + { + if (this.stringWriterDisposed) + { + return; + } + + try + { + string message = string.Format(CultureInfo.CurrentCulture, format?.Replace("\0", "\\0"), args); + this.stringWriter.WriteLine(message); + } + catch (ObjectDisposedException) + { + this.stringWriterDisposed = true; + } + } + + /// + /// Gets messages from the testContext writeLines + /// + /// The test context messages added so far. + public string GetDiagnosticMessages() + { + return this.stringWriter.ToString(); + } + + /// + /// Clears the previous testContext writeline messages. + /// + public void ClearDiagnosticMessages() + { + var sb = this.stringWriter.GetStringBuilder(); + sb.Remove(0, sb.Length); + } + + public void SetDataRow(object dataRow) + { + // Do nothing. + } + + public void SetDataConnection(object dbConnection) + { + // Do nothing. + } + + #endregion + + /// + /// Helper to safely fetch a property value. + /// + /// Property Name + /// Property value + private object GetPropertyValue(string propertyName) + { + object propertyValue = null; + this.properties.TryGetValue(propertyName, out propertyValue); + + return propertyValue; + } + + /// + /// Helper to safely fetch a property value. + /// + /// Property Name + /// Property value + private string GetStringPropertyValue(string propertyName) + { + object propertyValue = null; + this.properties.TryGetValue(propertyName, out propertyValue); + return propertyValue as string; + } + + /// + /// Helper to initialize the properties. + /// + private void InitializeProperties() + { + this.properties[FullyQualifiedTestClassNameLabel] = this.testMethod.FullClassName; + this.properties[TestNameLabel] = this.testMethod.Name; + } + } + +#pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName +} diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestSourceHost.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestSourceHost.cs new file mode 100644 index 0000000000..be2a7f1556 --- /dev/null +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestSourceHost.cs @@ -0,0 +1,134 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices +{ + using System; + using System.IO; + + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; + +#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName + + /// + /// A host that loads the test source + /// + public class TestSourceHost : ITestSourceHost + { + private string sourceFileName; + private IRunSettings runSettings; + private IFrameworkHandle frameworkHandle; + + private string currentDirectory = null; + + /// + /// Initializes a new instance of the class. + /// + /// The source file name. + /// The run-settings provided for this session. + /// The handle to the test platform. + public TestSourceHost(string sourceFileName, IRunSettings runSettings, IFrameworkHandle frameworkHandle) + { + this.sourceFileName = sourceFileName; + this.runSettings = runSettings; + this.frameworkHandle = frameworkHandle; + + // Set the environment context. + this.SetContext(sourceFileName); + } + + /// + /// Setup the isolation host. + /// + public void SetupHost() + { + } + + /// + /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. + /// + public void Dispose() + { + // Do nothing. + } + + /// + /// Creates an instance of a given type in the test source host. + /// + /// The type that needs to be created in the host. + /// The arguments to pass to the constructor. + /// This array of arguments must match in number, order, and type the parameters of the constructor to invoke. + /// Pass in null for a constructor with no arguments. + /// + /// An instance of the type created in the host. + /// . + /// + public object CreateInstanceForType(Type type, object[] args) + { + return Activator.CreateInstance(type, args); + } + + /// + /// Updates child-domain's appbase to point to test source location + /// + public void UpdateAppBaseToTestSourceLocation() + { + // Do nothing. + } + + private string GetConfigFileForTestSource(string sourceFileName) + { + return new DeploymentUtility().GetConfigFile(sourceFileName); + } + + /// + /// Sets context required for running tests. + /// + /// + /// source parameter used for setting context + /// + private void SetContext(string source) + { + if (string.IsNullOrEmpty(source)) + { + return; + } + + Exception setWorkingDirectoryException = null; + this.currentDirectory = Directory.GetCurrentDirectory(); + try + { + Directory.SetCurrentDirectory(Path.GetDirectoryName(source)); + } + catch (IOException ex) + { + setWorkingDirectoryException = ex; + } + catch (System.Security.SecurityException ex) + { + setWorkingDirectoryException = ex; + } + + if (setWorkingDirectoryException != null) + { + EqtTrace.Error("MSTestExecutor.SetWorkingDirectory: Failed to set the working directory to '{0}'. {1}", Path.GetDirectoryName(source), setWorkingDirectoryException); + } + } + + /// + /// Resets the context as it was before calling SetContext() + /// + private void ResetContext() + { + if (!string.IsNullOrEmpty(this.currentDirectory)) + { + Directory.SetCurrentDirectory(this.currentDirectory); + } + } + } + +#pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName +} diff --git a/src/TestFramework/Extension.Core/Extension.Core.csproj b/src/TestFramework/Extension.Core/Extension.Core.csproj index a71634a810..5aced6dd66 100644 --- a/src/TestFramework/Extension.Core/Extension.Core.csproj +++ b/src/TestFramework/Extension.Core/Extension.Core.csproj @@ -37,6 +37,7 @@ + @@ -48,6 +49,5 @@ - \ No newline at end of file diff --git a/src/TestFramework/Extension.Core/TestContext.cs b/src/TestFramework/Extension.Core/TestContext.cs new file mode 100644 index 0000000000..e9b2a70be5 --- /dev/null +++ b/src/TestFramework/Extension.Core/TestContext.cs @@ -0,0 +1,132 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestTools.UnitTesting +{ + using System; + using System.Collections; + using System.Diagnostics; + using System.Diagnostics.CodeAnalysis; + using System.Globalization; + +#pragma warning disable SA1649 // File name must match first type name + /// + /// Used to store information that is provided to unit tests. + /// + public abstract class TestContext +#pragma warning restore SA1649 // File name must match first type name + { + /// + /// Gets test properties for a test. + /// + public abstract IDictionary Properties { get; } + + #region Test run deployment directories + + /// + /// Gets base directory for the test run, under which deployed files and result files are stored. + /// + public virtual string TestRunDirectory => this.GetProperty("TestRunDirectory"); + + /// + /// Gets directory for files deployed for the test run. Typically a subdirectory of . + /// + public virtual string DeploymentDirectory => this.GetProperty("DeploymentDirectory"); + + /// + /// Gets base directory for results from the test run. Typically a subdirectory of . + /// + public virtual string ResultsDirectory => this.GetProperty("ResultsDirectory"); + + /// + /// Gets directory for test run result files. Typically a subdirectory of . + /// + public virtual string TestRunResultsDirectory => this.GetProperty("TestRunResultsDirectory"); + + /// + /// Gets directory for test result files. + /// + [SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly", Justification = "Compat")] + public virtual string TestResultsDirectory => this.GetProperty("TestResultsDirectory"); + + #region Old names, for backwards compatibility + + /// + /// Gets base directory for the test run, under which deployed files and result files are stored. + /// Same as . Use that property instead. + /// + public virtual string TestDir => this.GetProperty("TestDir"); + + /// + /// Gets directory for files deployed for the test run. Typically a subdirectory of . + /// Same as . Use that property instead. + /// + public virtual string TestDeploymentDir => this.GetProperty("TestDeploymentDir"); + + /// + /// Gets directory for test run result files. Typically a subdirectory of . + /// Same as . Use that property for test run result files, or + /// for test-specific result files instead. + /// + public virtual string TestLogsDir => this.GetProperty("TestLogsDir"); + + #endregion + + #endregion + + // This property can be useful in attributes derived from ExpectedExceptionBaseAttribute. + // Those attributes have access to the test context, and provide messages that are included + // in the test results. Users can benefit from messages that include the fully-qualified + // class name in addition to the name of the test method currently being executed. + + /// + /// Gets the Fully-qualified name of the class containing the test method currently being executed + /// + public virtual string FullyQualifiedTestClassName => this.GetProperty("FullyQualifiedTestClassName"); + + /// + /// Gets the name of the test method currently being executed + /// + public virtual string TestName => this.GetProperty("TestName"); + + /// + /// Gets the current test outcome. + /// + public virtual UnitTestOutcome CurrentTestOutcome => UnitTestOutcome.Unknown; + + /// + /// Used to write trace messages while the test is running + /// + /// formatted message string + public abstract void WriteLine(string message); + + /// + /// Used to write trace messages while the test is running + /// + /// format string + /// the arguments + public abstract void WriteLine(string format, params object[] args); + + /// + /// Adds a file name to the list in TestResult.ResultFileNames + /// + /// + /// The file Name. + /// + public abstract void AddResultFile(string fileName); + + private T GetProperty(string name) + where T : class + { + object o = this.Properties[name]; + + // If o has a value, but it's not the right type + if (o != null && !(o is T)) + { + throw new InvalidCastException(string.Format(CultureInfo.CurrentCulture, FrameworkMessages.InvalidPropertyType, name, o.GetType(), typeof(T))); + } + + return (T)o; + } + } +} diff --git a/test/E2ETests/Automation.CLI/Automation.CLI.csproj b/test/E2ETests/Automation.CLI/Automation.CLI.csproj index 6d74c16b8d..8270da9b26 100644 --- a/test/E2ETests/Automation.CLI/Automation.CLI.csproj +++ b/test/E2ETests/Automation.CLI/Automation.CLI.csproj @@ -97,17 +97,22 @@ $(TargetDir)..\ $(TargetDir)..\..\TestAssets - xcopy /Y /I "$(SourcePath)MSTest.CoreAdapter\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll" "$(DestinationPath)" - xcopy /Y /I "$(SourcePath)MSTest.CoreAdapter\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.pdb" "$(DestinationPath)" - xcopy /Y /I "$(SourcePath)PlatformServices.Desktop\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll" "$(DestinationPath)" - xcopy /Y /I "$(SourcePath)PlatformServices.Desktop\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.pdb" "$(DestinationPath)" - xcopy /Y /I "$(SourcePath)PlatformServices.Interface\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll" "$(DestinationPath)" - xcopy /Y /I "$(SourcePath)PlatformServices.Interface\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.pdb" "$(DestinationPath)" - xcopy /Y /I "$(SourcePath)MSTest.Core\Microsoft.VisualStudio.TestPlatform.TestFramework.dll" "$(DestinationPath)" - xcopy /Y /I "$(SourcePath)MSTest.Core\Microsoft.VisualStudio.TestPlatform.TestFramework.pdb" "$(DestinationPath)" - xcopy /Y /I "$(SourcePath)Extension.Desktop\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll" "$(DestinationPath)" - xcopy /Y /I "$(SourcePath)Extension.Desktop\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.pdb" "$(DestinationPath)" - + xcopy /Y /I "$(SourcePath)MSTest.CoreAdapter\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll" "$(DestinationPath)" + xcopy /Y /I "$(SourcePath)MSTest.CoreAdapter\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.pdb" "$(DestinationPath)" + xcopy /Y /I "$(SourcePath)PlatformServices.Desktop\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll" "$(DestinationPath)" + xcopy /Y /I "$(SourcePath)PlatformServices.Desktop\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.pdb" "$(DestinationPath)" + xcopy /Y /I "$(SourcePath)MSTest.CoreAdapter\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll" "$(DestinationPath)\netcoreapp2.1\" + xcopy /Y /I "$(SourcePath)MSTest.CoreAdapter\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.pdb" "$(DestinationPath)\netcoreapp2.1\" + xcopy /Y /I "$(SourcePath)PlatformServices.NetCore\netstandard1.5\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll" "$(DestinationPath)\netcoreapp2.1\" + xcopy /Y /I "$(SourcePath)PlatformServices.NetCore\netstandard1.5\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.pdb" "$(DestinationPath)\netcoreapp2.1\" + xcopy /Y /I "$(SourcePath)PlatformServices.NetCore\netstandard1.5\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll" "$(DestinationPath)\netcoreapp2.1\" + xcopy /Y /I "$(SourcePath)PlatformServices.Interface\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll" "$(DestinationPath)" + xcopy /Y /I "$(SourcePath)PlatformServices.Interface\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.pdb" "$(DestinationPath)" + xcopy /Y /I "$(SourcePath)MSTest.Core\Microsoft.VisualStudio.TestPlatform.TestFramework.dll" "$(DestinationPath)" + xcopy /Y /I "$(SourcePath)MSTest.Core\Microsoft.VisualStudio.TestPlatform.TestFramework.pdb" "$(DestinationPath)" + xcopy /Y /I "$(SourcePath)Extension.Desktop\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll" "$(DestinationPath)" + xcopy /Y /I "$(SourcePath)Extension.Desktop\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.pdb" "$(DestinationPath)" + + + + + + + + + diff --git a/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/Properties/PublishProfiles/FolderProfile.pubxml b/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/Properties/PublishProfiles/FolderProfile.pubxml new file mode 100644 index 0000000000..2fd113351c --- /dev/null +++ b/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/Properties/PublishProfiles/FolderProfile.pubxml @@ -0,0 +1,13 @@ + + + + + FileSystem + Release + Any CPU + netcoreapp2.1 + ..\..\..\..\artifacts\TestAssets\netcoreapp2.1 + + \ No newline at end of file From 54f15b16c619087edf59472d680e91235bc54556 Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Mon, 18 Mar 2019 18:35:50 +0530 Subject: [PATCH 16/24] netcore test version upgrade and file operations separate --- Nuget.config | 2 +- .../PlatformServices.NetCore.csproj | 2 +- .../Services/NetCoreFileOperations.cs | 101 ++++++++++++++++++ .../PlatformServices.Portable.csproj | 6 +- .../Services/PortableFileOperations.cs} | 0 .../DeploymentTestProjectNetCore.csproj | 2 +- .../ActionUtility.cs | 2 +- ...PlatformServices.NetCore.Unit.Tests.csproj | 2 +- .../Deployment/ns10DeploymentItemTests.cs | 2 +- .../Deployment/ns10TestRunDirectoriesTests.cs | 2 +- .../ns10ExceptionExtensionsTests.cs | 2 +- .../ns10MSTestAdapterSettingsTests.cs | 2 +- .../Utilities/ns10DeploymentUtilityTests.cs | 2 +- .../Utilities/ns10FileUtilityTests.cs | 2 +- .../ns10DiaSessionOperationsTests.cs | 2 +- .../netstandard1.0/ns10FileOperationsTests.cs | 2 +- .../ns10ReflectionOperationsTests.cs | 2 +- .../ns10TestContextImplementationTests.cs | 2 +- .../netstandard1.0/ns10TestSourceHostTests.cs | 2 +- .../netstandard1.0/ns10TestSourceTests.cs | 2 +- .../ns10ThreadOperationsTests.cs | 2 +- .../ns13MSTestSettingsProviderTests.cs | 2 +- .../ns13DeploymentItemUtilityTests.cs | 2 +- .../Utilities/ns13ReflectionUtilityTests.cs | 2 +- .../ns13TraceListenerManagerTests.cs | 2 +- .../netstandard1.3/ns13TraceListenerTests.cs | 4 +- 26 files changed, 127 insertions(+), 28 deletions(-) create mode 100644 src/Adapter/PlatformServices.NetCore/Services/NetCoreFileOperations.cs rename src/Adapter/{PlatformServices.Shared/netstandard1.0/Services/ns10FileOperations.cs => PlatformServices.Portable/Services/PortableFileOperations.cs} (100%) diff --git a/Nuget.config b/Nuget.config index 57644a2b47..a6cbf7a3e9 100644 --- a/Nuget.config +++ b/Nuget.config @@ -3,11 +3,11 @@ - + diff --git a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj index 971a1b799f..ac6f122a4f 100644 --- a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj +++ b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj @@ -19,7 +19,7 @@ - + diff --git a/src/Adapter/PlatformServices.NetCore/Services/NetCoreFileOperations.cs b/src/Adapter/PlatformServices.NetCore/Services/NetCoreFileOperations.cs new file mode 100644 index 0000000000..eabc4ecb32 --- /dev/null +++ b/src/Adapter/PlatformServices.NetCore/Services/NetCoreFileOperations.cs @@ -0,0 +1,101 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Reflection; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; + +#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName + + public class FileOperations : IFileOperations + { + /// + /// Loads an assembly. + /// + /// The assembly name. + /// Indicates whether this should be a reflection only load. + /// The . + /// This is currently not implemented. + public Assembly LoadAssembly(string assemblyName, bool isReflectionOnly) + { + var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(assemblyName); + return Assembly.Load(new AssemblyName(fileNameWithoutExtension)); + } + + /// + /// Gets the path to the .DLL of the assembly. + /// + /// The assembly. + /// Path to the .DLL of the assembly. + public string GetAssemblyPath(Assembly assembly) + { + #if NETSTANDARD2_0 + return assembly.Location; + #else + return null; + #endif + } + + /// + /// Verifies if file exists in context. + /// + /// The assembly file name. + /// true if file exists. + /// This is currently not implemented. + public bool DoesFileExist(string assemblyFileName) + { + // For projectK these assemblies can be created on the fly which means the file might not exist on disk. + // Depend on Assembly Load failures intead of this validation. + return true; + } + + /// + /// Creates a Navigation session for the source file. + /// This is used to get file path and line number information for its components. + /// + /// The source file. + /// A Navigation session instance for the current platform. + public object CreateNavigationSession(string source) + { + return DiaSessionOperations.CreateNavigationSession(source); + } + + /// + /// Get's the navigation data for a navigation session. + /// + /// The navigation session. + /// The class name. + /// The method name. + /// The min line number. + /// The file name. + public void GetNavigationData(object navigationSession, string className, string methodName, out int minLineNumber, out string fileName) + { + DiaSessionOperations.GetNavigationData(navigationSession, className, methodName, out minLineNumber, out fileName); + } + + /// + /// Dispose's the navigation session instance. + /// + /// The navigation session. + public void DisposeNavigationSession(object navigationSession) + { + DiaSessionOperations.DisposeNavigationSession(navigationSession); + } + + /// + /// Gets the full file path of an assembly file. + /// + /// The file name. + /// The full file path. + public string GetFullFilePath(string assemblyFileName) + { + return assemblyFileName; + } + } + +#pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName +} diff --git a/src/Adapter/PlatformServices.Portable/PlatformServices.Portable.csproj b/src/Adapter/PlatformServices.Portable/PlatformServices.Portable.csproj index 4f75ec8f54..8bc061aec6 100644 --- a/src/Adapter/PlatformServices.Portable/PlatformServices.Portable.csproj +++ b/src/Adapter/PlatformServices.Portable/PlatformServices.Portable.csproj @@ -40,10 +40,7 @@ SerializableAttribute.cs - - Services\ns10FileOperations.cs - - + Services\ns10DiaSessionOperations.cs @@ -81,6 +78,7 @@ + diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10FileOperations.cs b/src/Adapter/PlatformServices.Portable/Services/PortableFileOperations.cs similarity index 100% rename from src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10FileOperations.cs rename to src/Adapter/PlatformServices.Portable/Services/PortableFileOperations.cs diff --git a/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj b/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj index 6769cfec55..0897f2ab5b 100644 --- a/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj +++ b/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj @@ -1,7 +1,7 @@  - netcoreapp1.1 + netcoreapp2.1 NetCore false false diff --git a/test/UnitTests/MSTest.CoreAdapter.TestUtilities/ActionUtility.cs b/test/UnitTests/MSTest.CoreAdapter.TestUtilities/ActionUtility.cs index 00021fdc50..c971d622f9 100644 --- a/test/UnitTests/MSTest.CoreAdapter.TestUtilities/ActionUtility.cs +++ b/test/UnitTests/MSTest.CoreAdapter.TestUtilities/ActionUtility.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.TestUtilities { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using TestFramework = Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj index cca4ca0c08..c0c9a58892 100644 --- a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj +++ b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj @@ -8,7 +8,7 @@ MSTestAdapter.PlatformServices.NetCore.UnitTests MSTestAdapter.PlatformServices.NetCore.UnitTests - netcoreapp1.0 + netcoreapp1.1 $(PackageTargetFallback);portable-net45+win8+wpa81+wp8 diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs index 36acbd7f47..849e7cc57e 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.Tests.Deployment { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs index 19672ba589..4e4d6c1347 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.Tests.Deployment { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs index bc53bdb8df..a0dc6992b5 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.Tests.Extensions { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs index 087494c784..184f345b82 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10DeploymentUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10DeploymentUtilityTests.cs index 73ac328b16..24d89339c5 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10DeploymentUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10DeploymentUtilityTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.Tests.Utilities { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs index 9b5262647b..5f8758c48e 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.Tests.Utilities { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10DiaSessionOperationsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10DiaSessionOperationsTests.cs index 5c5e1b456c..1721f73a10 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10DiaSessionOperationsTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10DiaSessionOperationsTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.Tests.Services { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs index ad1f0b2ca1..e29e32cf27 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.Tests.Services { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs index c6b0422a9b..cbb00103ad 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.Tests.Services { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestContextImplementationTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestContextImplementationTests.cs index 6e02a56289..cf89e50ec0 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestContextImplementationTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestContextImplementationTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.Tests.Services { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceHostTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceHostTests.cs index e73fec574f..6d8685f1db 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceHostTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceHostTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.Tests.Services { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceTests.cs index 6d4ac2882c..389f46121c 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.Tests.Services { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ThreadOperationsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ThreadOperationsTests.cs index 96861be632..0b9e2ba72d 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ThreadOperationsTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ThreadOperationsTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.Tests.Services { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13MSTestSettingsProviderTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13MSTestSettingsProviderTests.cs index f8951d2621..bf7401202f 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13MSTestSettingsProviderTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13MSTestSettingsProviderTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.Desktop.UnitTests.Services { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs index 67f4480fef..b98726dda0 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs @@ -5,7 +5,7 @@ namespace MSTestAdapter.PlatformServices.Tests.Utilities { extern alias FrameworkV2Extension; -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13ReflectionUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13ReflectionUtilityTests.cs index 9c1ea78cf1..918214b735 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13ReflectionUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13ReflectionUtilityTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.Tests.Utilities { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerManagerTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerManagerTests.cs index 2a9333f722..323498ea47 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerManagerTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerManagerTests.cs @@ -3,7 +3,7 @@ namespace MSTestAdapter.PlatformServices.UnitTests.Services { -#if NETCOREAPP1_0 +#if NETCOREAPP1_1 using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerTests.cs index b166248683..86382dcc62 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerTests.cs @@ -3,8 +3,8 @@ namespace MSTestAdapter.PlatformServices.UnitTests.Services { -#if NETCOREAPP1_0 - using Microsoft.VisualStudio.TestTools.UnitTesting; +#if NETCOREAPP1_1 + using Microsoft.VisualStudio.TestTools.UnitTesting; #else extern alias FrameworkV1; From aa23712bacfec27b779e46bbe77d4cde49439569 Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Tue, 26 Mar 2019 14:57:46 +0530 Subject: [PATCH 17/24] jenkins issue with duplicate libraries --- .../PlatformServices.NetCore.csproj | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj index ad3668095e..dd572956b2 100644 --- a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj +++ b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj @@ -76,4 +76,11 @@ + + + + + + + \ No newline at end of file From 2108a2d782169bad830ff9d5cd0449ca37d95e48 Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Tue, 26 Mar 2019 14:57:46 +0530 Subject: [PATCH 18/24] jenkins issue with duplicate libraries --- .../PlatformServices.NetCore.csproj | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj index ad3668095e..2edf920c66 100644 --- a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj +++ b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj @@ -76,4 +76,18 @@ + + + + + + + + + + + + + \ No newline at end of file From 7fcc434c494d62d3f6a0f7802dc8a0f35a279ebb Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Tue, 26 Mar 2019 20:19:46 +0530 Subject: [PATCH 19/24] jenkins duplicacy --- .../DeploymentTestProject/DeploymentTestProject.csproj | 8 -------- .../DeploymentTestProjectNetCore.csproj | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/test/E2ETests/TestAssets/DeploymentTestProject/DeploymentTestProject.csproj b/test/E2ETests/TestAssets/DeploymentTestProject/DeploymentTestProject.csproj index b20c38357b..8f587e1cdb 100644 --- a/test/E2ETests/TestAssets/DeploymentTestProject/DeploymentTestProject.csproj +++ b/test/E2ETests/TestAssets/DeploymentTestProject/DeploymentTestProject.csproj @@ -32,12 +32,4 @@ PreserveNewest - - - - - - - - diff --git a/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj b/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj index 0897f2ab5b..54de7b0056 100644 --- a/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj +++ b/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1 + netcoreapp1.0 NetCore false false From 0e666ca4c5f1b8ef14717732e1fa42c75bdbb17d Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Tue, 26 Mar 2019 23:55:25 +0530 Subject: [PATCH 20/24] smoke fix post debug changes --- .gitignore | 3 +-- scripts/Build.ps1 | 13 +++++-------- scripts/test.ps1 | 2 +- .../PlatformServices.NetCore.csproj | 14 -------------- test/E2ETests/Smoke.E2E.Tests/DeploymentTests.cs | 4 ++-- .../DeploymentTestProjectNetCore.cs | 4 ++-- .../DeploymentTestProjectNetCore.csproj | 15 ++++----------- 7 files changed, 15 insertions(+), 40 deletions(-) diff --git a/.gitignore b/.gitignore index b634f35fa6..ee13fdfdcb 100644 --- a/.gitignore +++ b/.gitignore @@ -121,5 +121,4 @@ project.fragment.lock.json *.ru.resx *.tr.resx *.zh-Hans.resx -*.zh-Hant.resx -/.localhistory/D/testfx +*.zh-Hant.resx \ No newline at end of file diff --git a/scripts/Build.ps1 b/scripts/Build.ps1 index 6eabdbae19..4013a40900 100644 --- a/scripts/Build.ps1 +++ b/scripts/Build.ps1 @@ -225,24 +225,21 @@ function Perform-Build { } } } - Write-Log "AAAAAA" + Invoke-Build -solution "TestFx.sln" - Write-Log "BBBBB" + if($TFB_Templates -or $TFB_Full) { - Write-Log "CCCCC" - - # Invoke-Build -solution "Templates\MSTestTemplates.sln" -hasVsixExtension true + Invoke-Build -solution "Templates\MSTestTemplates.sln" -hasVsixExtension true } - Write-Log "DDDDD" if($TFB_Wizards -or $TFB_Full) { - # Invoke-Build -solution "WizardExtensions\WizardExtensions.sln" -hasVsixExtension true + Invoke-Build -solution "WizardExtensions\WizardExtensions.sln" -hasVsixExtension true } if($TFB_Official) { - # Build-vsmanprojs -hasVsixExtension true + Build-vsmanprojs -hasVsixExtension true } Write-Log "Perform-Build: Completed. {$(Get-ElapsedTime($timer))}" diff --git a/scripts/test.ps1 b/scripts/test.ps1 index 6ffe9328a4..1fbaccee9b 100644 --- a/scripts/test.ps1 +++ b/scripts/test.ps1 @@ -19,7 +19,7 @@ Param( [Switch] $Parallel = $false, [Parameter(Mandatory=$false)] - [Switch] $All = $true, + [Switch] $All = $false, [Parameter(Mandatory=$false)] [Alias("h")] diff --git a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj index 2edf920c66..ad3668095e 100644 --- a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj +++ b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj @@ -76,18 +76,4 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/test/E2ETests/Smoke.E2E.Tests/DeploymentTests.cs b/test/E2ETests/Smoke.E2E.Tests/DeploymentTests.cs index 7eead57bef..24e313af9c 100644 --- a/test/E2ETests/Smoke.E2E.Tests/DeploymentTests.cs +++ b/test/E2ETests/Smoke.E2E.Tests/DeploymentTests.cs @@ -38,8 +38,8 @@ public void ValidateTestSourceLocationDeployment() public void ValidateTestSourceLocationDeploymentNetCore() { this.InvokeVsTestForExecution(new string[] { TestAssemblyNetCore }, null); - this.ValidatePassedTestsContain("DeploymentTestProjectNetCore.DeploymentTestProjectNetCore.PassIfFilePresent", "DeploymentTestProjectNetCore.DeploymentTestProjectNetCore.PassIfDeclaredFilesPresent"); - this.ValidateFailedTestsContain("DeploymentTestProjectNetCore.dll", "DeploymentTestProjectNetCore.DeploymentTestProjectNetCore.FailIfFilePresent"); + this.ValidatePassedTestsContain("DeploymentTestProjectNetCore.DeploymentTestProjectNetCore.FailIfFilePresent", "DeploymentTestProjectNetCore.DeploymentTestProjectNetCore.PassIfDeclaredFilesPresent"); + this.ValidateFailedTestsContain("DeploymentTestProjectNetCore.dll", "DeploymentTestProjectNetCore.DeploymentTestProjectNetCore.PassIfFilePresent"); } } } diff --git a/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.cs b/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.cs index 3a2911feb1..de5364c521 100644 --- a/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.cs +++ b/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.cs @@ -3,7 +3,7 @@ namespace DeploymentTestProjectNetCore { - [DeploymentItem("DeploymentFile.xml")] + [DeploymentItem(@"..\..\..\test\E2ETests\TestAssets\DeploymentTestProjectNetCore\DeploymentFile.xml")] [TestClass] public class DeploymentTestProjectNetCore { @@ -19,7 +19,7 @@ public void FailIfFilePresent() Assert.IsFalse(File.Exists("EmptyDataFile.xml")); } - [DeploymentItem("TestCaseDeploymentFile.xml")] + [DeploymentItem(@"..\..\..\test\E2ETests\TestAssets\DeploymentTestProjectNetCore\TestCaseDeploymentFile.xml")] [TestMethod] public void PassIfDeclaredFilesPresent() { diff --git a/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj b/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj index 54de7b0056..a6bc96eada 100644 --- a/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj +++ b/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj @@ -1,7 +1,7 @@  - netcoreapp1.0 + netcoreapp1.1 NetCore false false @@ -19,13 +19,13 @@ - PreserveNewest + Never - PreserveNewest + Never - PreserveNewest + Never @@ -35,11 +35,4 @@ - - - From b7466e2a078468ef4f9c352036bf68da3e3ac3c5 Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Wed, 27 Mar 2019 12:30:00 +0530 Subject: [PATCH 21/24] fix spacing --- Nuget.config | 4 ++-- scripts/Build.ps1 | 3 ++- .../Services/DesktopTestDataSource.cs | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Nuget.config b/Nuget.config index a6cbf7a3e9..c9e46028f9 100644 --- a/Nuget.config +++ b/Nuget.config @@ -3,11 +3,11 @@ + - - + diff --git a/scripts/Build.ps1 b/scripts/Build.ps1 index 4013a40900..66637253d7 100644 --- a/scripts/Build.ps1 +++ b/scripts/Build.ps1 @@ -225,13 +225,14 @@ function Perform-Build { } } } - + Invoke-Build -solution "TestFx.sln" if($TFB_Templates -or $TFB_Full) { Invoke-Build -solution "Templates\MSTestTemplates.sln" -hasVsixExtension true } + if($TFB_Wizards -or $TFB_Full) { Invoke-Build -solution "WizardExtensions\WizardExtensions.sln" -hasVsixExtension true diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs index 773dcd85c0..0019d0b5ca 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestDataSource.cs @@ -13,6 +13,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Data; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; + using UTF = Microsoft.VisualStudio.TestTools.UnitTesting; #pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName From 2e4c598599bf65041db836c0e643cfe1cecc2e16 Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Thu, 28 Mar 2019 03:04:15 +0530 Subject: [PATCH 22/24] pragma --- scripts/build/stylecop.ruleset | 3 +- scripts/build/stylecop.test.ruleset | 5 +- .../Services/DesktopFileOperations.cs | 2 - .../Services/DesktopReflectionOperations.cs | 2 - .../DesktopTestContextImplementation.cs | 2 - .../Services/DesktopTestSourceHost.cs | 2 - .../Utilities/DesktopAssemblyUtility.cs | 2 - .../Utilities/DesktopDeploymentUtility.cs | 2 - .../Utilities/DesktopReflectionUtility.cs | 2 - .../Deployment/NetCoreTestRunDirectories.cs | 2 - .../PlatformServices.NetCore.csproj | 2 +- .../Services/NetCoreFileOperations.cs | 100 ---- .../NetCoreTestContextImplementation.cs | 2 - .../Services/NetCoreTestSourceHost.cs | 28 +- .../Utilities/NetCoreAssemblyUtility.cs | 2 - .../Utilities/NetCoreDeploymentUtility.cs | 25 +- .../Utilities/NetCoreReflectionUtility.cs | 2 - .../PlatformServices.Portable.csproj | 4 +- .../Services/ns10FileOperations.cs} | 0 .../Services/ns10MSTestSettingsProvider.cs | 2 - .../ns10TestContextPropertyStrings.cs | 2 - .../Extensions/ns13ExceptionExtensions.cs | 1 - .../Services/ns13MSTestAdapterSettings.cs | 2 - .../Services/ns13TestDeployment.cs | 3 +- .../Utilities/ns13DeploymentItemUtility.cs | 2 - .../Utilities/ns13DeploymentUtilityBase.cs | 2 - .../Utilities/ns13FileUtility.cs | 2 - .../netstandard1.3/ns13DeploymentItem.cs | 2 - src/Package/MSTest.TestAdapter.nuspec | 4 +- .../Extension.Core/NetCoreTestContext.cs | 8 +- .../Extension.Desktop/DesktopTestContext.cs | 8 +- .../Automation.CLI/Automation.CLI.csproj | 1 + ...PlatformServices.Desktop.Unit.Tests.csproj | 3 + .../Services/DesktopTestDeploymentTests.cs | 435 +------------- ...PlatformServices.NetCore.Unit.Tests.csproj | 2 +- .../Deployment/ns10DeploymentItemTests.cs | 2 - .../Deployment/ns10TestRunDirectoriesTests.cs | 2 - .../ns10ExceptionExtensionsTests.cs | 2 - .../Utilities/ns10FileUtilityTests.cs | 2 - .../netstandard1.0/ns10FileOperationsTests.cs | 1 - .../ns10ReflectionOperationsTests.cs | 2 - .../ns10SettingsProviderTests.cs | 2 - .../ns10TestContextImplementationTests.cs | 2 - .../netstandard1.0/ns10TestSourceTests.cs | 2 - .../Services/ns13TestDeploymentTests.cs | 552 ++++++++++++++++++ 45 files changed, 594 insertions(+), 643 deletions(-) delete mode 100644 src/Adapter/PlatformServices.NetCore/Services/NetCoreFileOperations.cs rename src/Adapter/{PlatformServices.Portable/Services/PortableFileOperations.cs => PlatformServices.Shared/netstandard1.0/Services/ns10FileOperations.cs} (100%) create mode 100644 test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13TestDeploymentTests.cs diff --git a/scripts/build/stylecop.ruleset b/scripts/build/stylecop.ruleset index 3d7b8ef6a5..467b822851 100644 --- a/scripts/build/stylecop.ruleset +++ b/scripts/build/stylecop.ruleset @@ -1,4 +1,4 @@ - + @@ -6,6 +6,7 @@ + diff --git a/scripts/build/stylecop.test.ruleset b/scripts/build/stylecop.test.ruleset index c409cd73f9..91f196256f 100644 --- a/scripts/build/stylecop.test.ruleset +++ b/scripts/build/stylecop.test.ruleset @@ -1,4 +1,4 @@ - + @@ -12,5 +12,6 @@ + - + \ No newline at end of file diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopFileOperations.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopFileOperations.cs index 07a3110c11..e437b850ce 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopFileOperations.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopFileOperations.cs @@ -11,8 +11,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; using Microsoft.VisualStudio.TestPlatform.ObjectModel; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - /// /// This service is responsible for any file based operations. /// diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopReflectionOperations.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopReflectionOperations.cs index b8ce5c2ec5..08af6a077e 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopReflectionOperations.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopReflectionOperations.cs @@ -9,8 +9,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - /// /// This service is responsible for platform specific reflection operations. /// diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs index 4bb97b58ce..fb194f8b92 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs @@ -18,8 +18,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel; using UTF = Microsoft.VisualStudio.TestTools.UnitTesting; -#pragma warning disable SA1649 // File name must match first type name - /// /// Internal implementation of TestContext exposed to the user. /// The virtual string properties of the TestContext are retreived from the property dictionary diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs index 91aa97f6bc..205955f374 100644 --- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs +++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestSourceHost.cs @@ -14,8 +14,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - /// /// A host that loads the test source.This can be in isolation for desktop using an AppDomain or just loading the source in the current context. /// diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/DesktopAssemblyUtility.cs b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopAssemblyUtility.cs index c5b4931c15..006849bce7 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/DesktopAssemblyUtility.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopAssemblyUtility.cs @@ -13,8 +13,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; using Microsoft.VisualStudio.TestPlatform.ObjectModel; -#pragma warning disable SA1649 // File name must match first type name - /// /// Utility for assembly specific functionality. /// diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/DesktopDeploymentUtility.cs b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopDeploymentUtility.cs index e8b7447d6b..593974700b 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/DesktopDeploymentUtility.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopDeploymentUtility.cs @@ -19,8 +19,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; -#pragma warning disable SA1649 // File name must match first type name - internal class DeploymentUtility : DeploymentUtilityBase { public DeploymentUtility() diff --git a/src/Adapter/PlatformServices.Desktop/Utilities/DesktopReflectionUtility.cs b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopReflectionUtility.cs index ea00146e3b..4b3127f89f 100644 --- a/src/Adapter/PlatformServices.Desktop/Utilities/DesktopReflectionUtility.cs +++ b/src/Adapter/PlatformServices.Desktop/Utilities/DesktopReflectionUtility.cs @@ -10,8 +10,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using System.Linq; using System.Reflection; -#pragma warning disable SA1649 // File name must match first type name - /// /// Utility for reflection API's /// diff --git a/src/Adapter/PlatformServices.NetCore/Deployment/NetCoreTestRunDirectories.cs b/src/Adapter/PlatformServices.NetCore/Deployment/NetCoreTestRunDirectories.cs index 57eb6d3814..2967db5859 100644 --- a/src/Adapter/PlatformServices.NetCore/Deployment/NetCoreTestRunDirectories.cs +++ b/src/Adapter/PlatformServices.NetCore/Deployment/NetCoreTestRunDirectories.cs @@ -7,8 +7,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Dep using System.Diagnostics; using System.IO; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - /// /// The test run directories. /// diff --git a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj index ad3668095e..6e8d04964a 100644 --- a/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj +++ b/src/Adapter/PlatformServices.NetCore/PlatformServices.NetCore.csproj @@ -19,8 +19,8 @@ + - diff --git a/src/Adapter/PlatformServices.NetCore/Services/NetCoreFileOperations.cs b/src/Adapter/PlatformServices.NetCore/Services/NetCoreFileOperations.cs deleted file mode 100644 index 4a4e2238ad..0000000000 --- a/src/Adapter/PlatformServices.NetCore/Services/NetCoreFileOperations.cs +++ /dev/null @@ -1,100 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. See LICENSE file in the project root for full license information. - -namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices -{ - using System; - using System.IO; - using System.Reflection; - using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface; - -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - - public class FileOperations : IFileOperations - { - /// - /// Loads an assembly. - /// - /// The assembly name. - /// Indicates whether this should be a reflection only load. - /// The . - /// This is currently not implemented. - public Assembly LoadAssembly(string assemblyName, bool isReflectionOnly) - { - var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(assemblyName); - return Assembly.Load(new AssemblyName(fileNameWithoutExtension)); - } - - /// - /// Gets the path to the .DLL of the assembly. - /// - /// The assembly. - /// Path to the .DLL of the assembly. - public string GetAssemblyPath(Assembly assembly) - { - #if NETSTANDARD2_0 - return assembly.Location; - #else - return null; - #endif - } - - /// - /// Verifies if file exists in context. - /// - /// The assembly file name. - /// true if file exists. - /// This is currently not implemented. - public bool DoesFileExist(string assemblyFileName) - { - // For projectK these assemblies can be created on the fly which means the file might not exist on disk. - // Depend on Assembly Load failures intead of this validation. - return true; - } - - /// - /// Creates a Navigation session for the source file. - /// This is used to get file path and line number information for its components. - /// - /// The source file. - /// A Navigation session instance for the current platform. - public object CreateNavigationSession(string source) - { - return DiaSessionOperations.CreateNavigationSession(source); - } - - /// - /// Get's the navigation data for a navigation session. - /// - /// The navigation session. - /// The class name. - /// The method name. - /// The min line number. - /// The file name. - public void GetNavigationData(object navigationSession, string className, string methodName, out int minLineNumber, out string fileName) - { - DiaSessionOperations.GetNavigationData(navigationSession, className, methodName, out minLineNumber, out fileName); - } - - /// - /// Dispose's the navigation session instance. - /// - /// The navigation session. - public void DisposeNavigationSession(object navigationSession) - { - DiaSessionOperations.DisposeNavigationSession(navigationSession); - } - - /// - /// Gets the full file path of an assembly file. - /// - /// The file name. - /// The full file path. - public string GetFullFilePath(string assemblyFileName) - { - return assemblyFileName; - } - } - -#pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName -} diff --git a/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestContextImplementation.cs b/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestContextImplementation.cs index 622a63b890..62aaa28ceb 100644 --- a/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestContextImplementation.cs +++ b/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestContextImplementation.cs @@ -16,8 +16,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using UTF = Microsoft.VisualStudio.TestTools.UnitTesting; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - /// /// Internal implementation of TestContext exposed to the user. /// diff --git a/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestSourceHost.cs b/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestSourceHost.cs index be2a7f1556..bde6958a33 100644 --- a/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestSourceHost.cs +++ b/src/Adapter/PlatformServices.NetCore/Services/NetCoreTestSourceHost.cs @@ -11,17 +11,12 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - /// /// A host that loads the test source /// public class TestSourceHost : ITestSourceHost { private string sourceFileName; - private IRunSettings runSettings; - private IFrameworkHandle frameworkHandle; - private string currentDirectory = null; /// @@ -33,8 +28,6 @@ public class TestSourceHost : ITestSourceHost public TestSourceHost(string sourceFileName, IRunSettings runSettings, IFrameworkHandle frameworkHandle) { this.sourceFileName = sourceFileName; - this.runSettings = runSettings; - this.frameworkHandle = frameworkHandle; // Set the environment context. this.SetContext(sourceFileName); @@ -52,7 +45,7 @@ public void SetupHost() /// public void Dispose() { - // Do nothing. + this.ResetContext(); } /// @@ -79,18 +72,13 @@ public void UpdateAppBaseToTestSourceLocation() // Do nothing. } - private string GetConfigFileForTestSource(string sourceFileName) - { - return new DeploymentUtility().GetConfigFile(sourceFileName); - } - - /// - /// Sets context required for running tests. - /// - /// - /// source parameter used for setting context - /// - private void SetContext(string source) + /// + /// Sets context required for running tests. + /// + /// + /// source parameter used for setting context + /// + private void SetContext(string source) { if (string.IsNullOrEmpty(source)) { diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreAssemblyUtility.cs b/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreAssemblyUtility.cs index 8d34582d64..923d005162 100644 --- a/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreAssemblyUtility.cs +++ b/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreAssemblyUtility.cs @@ -13,8 +13,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; using Microsoft.VisualStudio.TestPlatform.ObjectModel; -#pragma warning disable SA1649 // File name must match first type name - /// /// Utility for assembly specific functionality. /// diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreDeploymentUtility.cs b/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreDeploymentUtility.cs index fd291211de..073eadf299 100644 --- a/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreDeploymentUtility.cs +++ b/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreDeploymentUtility.cs @@ -18,8 +18,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; -#pragma warning disable SA1649 // File name must match first type name - internal class DeploymentUtility : DeploymentUtilityBase { public DeploymentUtility() @@ -32,8 +30,15 @@ public DeploymentUtility(DeploymentItemUtility deploymentItemUtility, AssemblyUt { } + /// + /// add deployment items based on MSTestSettingsProvider.Settings.DeployTestSourceDependencies. This property is ignored in net core. + /// + /// The test source. + /// Deployment Items. + /// Warnings. public override void AddDeploymentItemsBasedOnMsTestSetting(string testSource, IList deploymentItems, List warnings) { + // It should add items from bin\debug but since deployment items in netcore are run from bin\debug only, so no need to implement it } /// @@ -60,21 +65,5 @@ protected override void AddDependenciesOfDeploymentItem(string deploymentItemFil { // Its implemented only in full framework project as dependent files are not fetched in netcore. } - - private bool IsDeploymentItemSourceADirectory(DeploymentItem deploymentItem, string testSource, out string resultDirectory) - { - resultDirectory = null; - - string directory = this.GetFullPathToDeploymentItemSource(deploymentItem.SourcePath, testSource); - directory = directory.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); - - if (this.FileUtility.DoesDirectoryExist(directory)) - { - resultDirectory = directory; - return true; - } - - return false; - } } } diff --git a/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreReflectionUtility.cs b/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreReflectionUtility.cs index 83c997e249..ad5255660a 100644 --- a/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreReflectionUtility.cs +++ b/src/Adapter/PlatformServices.NetCore/Utilities/NetCoreReflectionUtility.cs @@ -11,8 +11,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using System.Linq; using System.Reflection; -#pragma warning disable SA1649 // File name must match first type name - /// /// Utility for reflection API's /// diff --git a/src/Adapter/PlatformServices.Portable/PlatformServices.Portable.csproj b/src/Adapter/PlatformServices.Portable/PlatformServices.Portable.csproj index 8bc061aec6..9e1e3c98f7 100644 --- a/src/Adapter/PlatformServices.Portable/PlatformServices.Portable.csproj +++ b/src/Adapter/PlatformServices.Portable/PlatformServices.Portable.csproj @@ -43,6 +43,9 @@ Services\ns10DiaSessionOperations.cs + + Services\ns10FileOperations.cs + Services\ns10ReflectionOperations.cs @@ -78,7 +81,6 @@ - diff --git a/src/Adapter/PlatformServices.Portable/Services/PortableFileOperations.cs b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10FileOperations.cs similarity index 100% rename from src/Adapter/PlatformServices.Portable/Services/PortableFileOperations.cs rename to src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10FileOperations.cs diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10MSTestSettingsProvider.cs b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10MSTestSettingsProvider.cs index e3311986df..54dbc51203 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10MSTestSettingsProvider.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10MSTestSettingsProvider.cs @@ -6,9 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using System.Collections.Generic; using System.Xml; using Microsoft.VisualStudio.TestPlatform.ObjectModel; - using ISettingsProvider = Interface.ISettingsProvider; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName /// /// Class to read settings from the runsettings xml for the desktop. diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextPropertyStrings.cs b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextPropertyStrings.cs index f794d6f902..1a17f1759a 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextPropertyStrings.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextPropertyStrings.cs @@ -3,8 +3,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices { -#pragma warning disable SA1649 // File name must match first type name - /// /// Test Context Property Names. /// diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Extensions/ns13ExceptionExtensions.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Extensions/ns13ExceptionExtensions.cs index 588c233e9f..4b9ce94cd0 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Extensions/ns13ExceptionExtensions.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Extensions/ns13ExceptionExtensions.cs @@ -5,7 +5,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Ext { using System; using System.Diagnostics; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName /// /// Extension methods for the exception class. diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs index 3e5746a79c..a622a4dcb7 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13MSTestAdapterSettings.cs @@ -12,8 +12,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; - #pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - public class MSTestAdapterSettings { /// diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs index e090360567..d3dcbb3c3d 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Services/ns13TestDeployment.cs @@ -17,8 +17,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - /// /// The test deployment. /// @@ -140,6 +138,7 @@ public bool Deploy(IEnumerable tests, IRunContext runContext, IFramewo return false; } + // Object model currently does not have support for SuspendCodeCoverage. We can remove this once support is added #if !NETSTANDARD1_5 using (new SuspendCodeCoverage()) #endif diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs index d272f919a5..ad06769007 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentItemUtility.cs @@ -14,8 +14,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestTools.UnitTesting; -#pragma warning disable SA1649 // File name must match first type name - /// /// The deployment utility. /// diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs index d6f8854f62..006d44bfe4 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13DeploymentUtilityBase.cs @@ -19,8 +19,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; -#pragma warning disable SA1649 // File name must match first type name - internal abstract class DeploymentUtilityBase { protected const string TestAssemblyConfigFileExtension = ".config"; diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs index b150fd5054..9a4826293e 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/Utilities/ns13FileUtility.cs @@ -13,8 +13,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Uti using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; using Microsoft.VisualStudio.TestPlatform.ObjectModel; -#pragma warning disable SA1649 // File name must match first type name - internal class FileUtility { private AssemblyUtility assemblyUtility; diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs b/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs index 06391729ae..d5713dc543 100644 --- a/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs +++ b/src/Adapter/PlatformServices.Shared/netstandard1.3/ns13DeploymentItem.cs @@ -7,8 +7,6 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Dep using System.Diagnostics; using System.Globalization; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - /// /// Specifies type of deployment item origin, where the item comes from. /// diff --git a/src/Package/MSTest.TestAdapter.nuspec b/src/Package/MSTest.TestAdapter.nuspec index bc6e7fc79e..d67b9b24a8 100644 --- a/src/Package/MSTest.TestAdapter.nuspec +++ b/src/Package/MSTest.TestAdapter.nuspec @@ -79,7 +79,7 @@ - + diff --git a/src/TestFramework/Extension.Core/NetCoreTestContext.cs b/src/TestFramework/Extension.Core/NetCoreTestContext.cs index dda9c588a0..e9689e3cce 100644 --- a/src/TestFramework/Extension.Core/NetCoreTestContext.cs +++ b/src/TestFramework/Extension.Core/NetCoreTestContext.cs @@ -9,12 +9,10 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting using System.Diagnostics.CodeAnalysis; using System.Globalization; -#pragma warning disable SA1649 // File name must match first type name - /// - /// Used to store information that is provided to unit tests. - /// + /// + /// Used to store information that is provided to unit tests. + /// public abstract class TestContext -#pragma warning restore SA1649 // File name must match first type name { /// /// Gets test properties for a test. diff --git a/src/TestFramework/Extension.Desktop/DesktopTestContext.cs b/src/TestFramework/Extension.Desktop/DesktopTestContext.cs index a95b06d0e1..a6f019bbcc 100644 --- a/src/TestFramework/Extension.Desktop/DesktopTestContext.cs +++ b/src/TestFramework/Extension.Desktop/DesktopTestContext.cs @@ -12,12 +12,10 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting using System.Diagnostics.CodeAnalysis; using System.Globalization; -#pragma warning disable SA1649 // File name must match first type name - /// - /// Used to store information that is provided to unit tests. - /// + /// + /// Used to store information that is provided to unit tests. + /// public abstract class TestContext -#pragma warning restore SA1649 // File name must match first type name { /// /// Gets test properties for a test. diff --git a/test/E2ETests/Automation.CLI/Automation.CLI.csproj b/test/E2ETests/Automation.CLI/Automation.CLI.csproj index f2e5c4ba30..f72792ac61 100644 --- a/test/E2ETests/Automation.CLI/Automation.CLI.csproj +++ b/test/E2ETests/Automation.CLI/Automation.CLI.csproj @@ -106,6 +106,7 @@ xcopy /Y /I "$(SourcePath)PlatformServices.NetCore\netstandard1.5\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll" "$(DestinationPath)\netcoreapp1.1\" xcopy /Y /I "$(SourcePath)PlatformServices.NetCore\netstandard1.5\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.pdb" "$(DestinationPath)\netcoreapp1.1\" xcopy /Y /I "$(SourcePath)PlatformServices.NetCore\netstandard1.5\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll" "$(DestinationPath)\netcoreapp1.1\" + xcopy /Y /I "$(SourcePath)PlatformServices.NetCore\netstandard1.5\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.pdb" "$(DestinationPath)\netcoreapp1.1\" xcopy /Y /I "$(SourcePath)PlatformServices.Interface\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll" "$(DestinationPath)" xcopy /Y /I "$(SourcePath)PlatformServices.Interface\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.pdb" "$(DestinationPath)" xcopy /Y /I "$(SourcePath)MSTest.Core\Microsoft.VisualStudio.TestPlatform.TestFramework.dll" "$(DestinationPath)" diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/PlatformServices.Desktop.Unit.Tests.csproj b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/PlatformServices.Desktop.Unit.Tests.csproj index 991f4b1897..cb0fca9577 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/PlatformServices.Desktop.Unit.Tests.csproj +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/PlatformServices.Desktop.Unit.Tests.csproj @@ -82,6 +82,9 @@ Services\ns13MSTestSettingsProviderTests.cs + + Services\ns13TestDeploymentTests.cs + Utilities\ns13DeploymentItemUtilityTests.cs diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDeploymentTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDeploymentTests.cs index 2634654b9d..75f7fbadb2 100644 --- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDeploymentTests.cs +++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestDeploymentTests.cs @@ -52,279 +52,8 @@ public void TestInit() MSTestSettingsProvider.Reset(); } - #region GetDeploymentItems tests. - - [TestMethod] - public void GetDeploymentItemsReturnsNullWhenNoDeploymentItems() - { - var methodInfo = - typeof(DesktopTestDeploymentTests).GetMethod("GetDeploymentItemsReturnsNullWhenNoDeploymentItems"); - - Assert.IsNull(new TestDeployment().GetDeploymentItems(methodInfo, typeof(DesktopTestDeploymentTests), this.warnings)); - } - - [TestMethod] - public void GetDeploymentItemsReturnsDeploymentItems() - { - // Arrange. - var testDeployment = new TestDeployment(new DeploymentItemUtility(this.mockReflectionUtility.Object), null, null); - - // setup mocks - var methodLevelDeploymentItems = new[] - { - new KeyValuePair( - DefaultDeploymentItemPath, - DefaultDeploymentItemOutputDirectory) - }; - var classLevelDeploymentItems = new[] - { - new KeyValuePair( - DefaultDeploymentItemPath + "\\temp2", - DefaultDeploymentItemOutputDirectory) - }; - var memberInfo = - typeof(DesktopTestDeploymentTests).GetMethod( - "GetDeploymentItemsReturnsDeploymentItems"); - this.SetupDeploymentItems(memberInfo, methodLevelDeploymentItems); - this.SetupDeploymentItems(typeof(DesktopTestDeploymentTests), classLevelDeploymentItems); - - // Act. - var deploymentItems = testDeployment.GetDeploymentItems(memberInfo, typeof(DesktopTestDeploymentTests), this.warnings); - - // Assert. - var expectedDeploymentItems = new KeyValuePair[] - { - new KeyValuePair( - DefaultDeploymentItemPath, - DefaultDeploymentItemOutputDirectory), - new KeyValuePair( - DefaultDeploymentItemPath + "\\temp2", - DefaultDeploymentItemOutputDirectory) - }; - - CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); - } - - #endregion - - #region Cleanup tests - - [TestMethod] - public void CleanupShouldNotDeleteDirectoriesIfRunDirectoiresIsNull() - { - var testDeployment = new TestDeployment(null, null, this.mockFileUtility.Object); - - testDeployment.Cleanup(); - - this.mockFileUtility.Verify(fu => fu.DeleteDirectories(It.IsAny()), Times.Never); - } - - [TestMethod] - public void CleanupShouldNotDeleteDirectoriesIfRunSettingsSpecifiesSo() - { - string runSettingxml = - @"False"; - StringReader stringReader = new StringReader(runSettingxml); - XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); - MSTestSettingsProvider mstestSettingsProvider = new MSTestSettingsProvider(); - mstestSettingsProvider.Load(reader); - - TestRunDirectories testRunDirectories; - var testCase = this.GetTestCase(Assembly.GetExecutingAssembly().Location); - - // Setup mocks. - var testDeployment = this.CreateAndSetupDeploymentRelatedUtilities(out testRunDirectories); - - var mockRunContext = new Mock(); - mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory); - - Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object)); - - testDeployment.Cleanup(); - - this.mockFileUtility.Verify(fu => fu.DeleteDirectories(It.IsAny()), Times.Never); - } - - [TestMethod] - public void CleanupShouldDeleteRootDeploymentDirectory() - { - TestRunDirectories testRunDirectories; - var testCase = this.GetTestCase(Assembly.GetExecutingAssembly().Location); - - // Setup mocks. - var testDeployment = this.CreateAndSetupDeploymentRelatedUtilities(out testRunDirectories); - - var mockRunContext = new Mock(); - mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory); - - Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object)); - - // Act. - testDeployment.Cleanup(); - - this.mockFileUtility.Verify(fu => fu.DeleteDirectories(testRunDirectories.RootDeploymentDirectory), Times.Once); - } - - #endregion - - #region GetDeploymentDirectory tests - - [TestMethod] - public void GetDeploymentDirectoryShouldReturnNullIfDeploymentDirectoryIsNull() - { - Assert.IsNull(new TestDeployment().GetDeploymentDirectory()); - } - - [TestMethod] - public void GetDeploymentDirectoryShouldReturnDeploymentOutputDirectory() - { - TestRunDirectories testRunDirectories; - var testCase = this.GetTestCase(Assembly.GetExecutingAssembly().Location); - - // Setup mocks. - var testDeployment = this.CreateAndSetupDeploymentRelatedUtilities(out testRunDirectories); - - var mockRunContext = new Mock(); - mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory); - - Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object)); - - // Act. - Assert.AreEqual(testRunDirectories.OutDirectory, testDeployment.GetDeploymentDirectory()); - } - - #endregion - #region Deploy tests - [TestMethod] - public void DeployShouldReturnFalseWhenDeploymentEnabledSetToFalseButHasDeploymentItems() - { - var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A"); - var kvparray = new[] - { - new KeyValuePair( - DefaultDeploymentItemPath, - DefaultDeploymentItemOutputDirectory) - }; - testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, kvparray); - - var testDeployment = new TestDeployment( - new DeploymentItemUtility(this.mockReflectionUtility.Object), - new DeploymentUtility(), - this.mockFileUtility.Object); - - string runSettingxml = - @"False"; - StringReader stringReader = new StringReader(runSettingxml); - XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); - MSTestSettingsProvider mstestSettingsProvider = new MSTestSettingsProvider(); - mstestSettingsProvider.Load(reader); - - // Deployment should not happen - Assert.IsFalse(testDeployment.Deploy(new List { testCase }, null, null)); - - // Deplyment directories should not be created - Assert.IsNull(testDeployment.GetDeploymentDirectory()); - } - - [TestMethod] - public void DeployShouldReturnFalseWhenDeploymentEnabledSetToFalseAndHasNoDeploymentItems() - { - var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A"); - testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, null); - var testDeployment = new TestDeployment( - new DeploymentItemUtility(this.mockReflectionUtility.Object), - new DeploymentUtility(), - this.mockFileUtility.Object); - - string runSettingxml = - @"False"; - StringReader stringReader = new StringReader(runSettingxml); - XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); - MSTestSettingsProvider mstestSettingsProvider = new MSTestSettingsProvider(); - mstestSettingsProvider.Load(reader); - - // Deployment should not happen - Assert.IsFalse(testDeployment.Deploy(new List { testCase }, null, null)); - - // Deployment directories should get created - Assert.IsNotNull(testDeployment.GetDeploymentDirectory()); - } - - [TestMethod] - public void DeployShouldReturnFalseWhenDeploymentEnabledSetToTrueButHasNoDeploymentItems() - { - var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A"); - testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, null); - var testDeployment = new TestDeployment( - new DeploymentItemUtility(this.mockReflectionUtility.Object), - new DeploymentUtility(), - this.mockFileUtility.Object); - - string runSettingxml = - @"True"; - StringReader stringReader = new StringReader(runSettingxml); - XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); - MSTestSettingsProvider mstestSettingsProvider = new MSTestSettingsProvider(); - mstestSettingsProvider.Load(reader); - - // Deployment should not happen - Assert.IsFalse(testDeployment.Deploy(new List { testCase }, null, null)); - - // Deployment directories should get created - Assert.IsNotNull(testDeployment.GetDeploymentDirectory()); - } - - // [Todo] This test has to have mocks. It actually deploys stuff and we cannot assume that all the dependencies get copied over to bin\debug. - [TestMethod] - [Ignore] - public void DeployShouldReturnTrueWhenDeploymentEnabledSetToTrueAndHasDeploymentItems() - { - var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), Assembly.GetExecutingAssembly().Location); - var kvpArray = new[] - { - new KeyValuePair( - DefaultDeploymentItemPath, - DefaultDeploymentItemOutputDirectory) - }; - testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, kvpArray); - var testDeployment = new TestDeployment( - new DeploymentItemUtility(this.mockReflectionUtility.Object), - new DeploymentUtility(), - this.mockFileUtility.Object); - - string runSettingxml = - @"True"; - StringReader stringReader = new StringReader(runSettingxml); - XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); - MSTestSettingsProvider mstestSettingsProvider = new MSTestSettingsProvider(); - mstestSettingsProvider.Load(reader); - - // Deployment should happen - Assert.IsTrue(testDeployment.Deploy(new List { testCase }, null, new Mock().Object)); - - // Deployment directories should get created - Assert.IsNotNull(testDeployment.GetDeploymentDirectory()); - } - - [TestMethod] - public void DeployShouldCreateDeploymentDirectories() - { - TestRunDirectories testRunDirectories; - var testCase = this.GetTestCase(Assembly.GetExecutingAssembly().Location); - - // Setup mocks. - var testDeployment = this.CreateAndSetupDeploymentRelatedUtilities(out testRunDirectories); - - var mockRunContext = new Mock(); - mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory); - - Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object)); - - this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(testRunDirectories.RootDeploymentDirectory), Times.Once); - } - [TestMethod] public void DeployShouldDeployFilesInASourceAndReturnTrue() { @@ -384,125 +113,11 @@ public void DeployShouldDeployFilesInMultipleSourcesAndReturnTrue() Times.Once); } - #endregion - - #region GetDeploymentInformation tests - - [TestMethod] - public void GetDeploymentInformationShouldReturnAppBaseDirectoryIfRunDirectoryIsNull() - { - TestDeployment.Reset(); - var properties = TestDeployment.GetDeploymentInformation(Assembly.GetExecutingAssembly().Location); - - var applicationBaseDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - var expectedProperties = new Dictionary - { - { - TestContextPropertyStrings.TestRunDirectory, - applicationBaseDirectory - }, - { - TestContextPropertyStrings.DeploymentDirectory, - applicationBaseDirectory - }, - { - TestContextPropertyStrings.ResultsDirectory, - applicationBaseDirectory - }, - { - TestContextPropertyStrings - .TestRunResultsDirectory, - applicationBaseDirectory - }, - { - TestContextPropertyStrings - .TestResultsDirectory, - applicationBaseDirectory - }, - { - TestContextPropertyStrings.TestDir, - applicationBaseDirectory - }, - { - TestContextPropertyStrings.TestDeploymentDir, - applicationBaseDirectory - }, - { - TestContextPropertyStrings.TestLogsDir, - applicationBaseDirectory - } - }; - Assert.IsNotNull(properties); - CollectionAssert.AreEqual(expectedProperties.ToList(), properties.ToList()); - } - - [TestMethod] - public void GetDeploymentInformationShouldReturnRunDirectoryInformationIfSourceIsNull() - { - // Arrange. - TestRunDirectories testRunDirectories; - var testCase = this.GetTestCase(Assembly.GetExecutingAssembly().Location); - - // Setup mocks. - var testDeployment = this.CreateAndSetupDeploymentRelatedUtilities(out testRunDirectories); - - var mockRunContext = new Mock(); - mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory); - - Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object)); - - // Act. - var properties = TestDeployment.GetDeploymentInformation(null); - - // Assert. - var expectedProperties = new Dictionary - { - { - TestContextPropertyStrings.TestRunDirectory, - testRunDirectories.RootDeploymentDirectory - }, - { - TestContextPropertyStrings.DeploymentDirectory, - testRunDirectories.OutDirectory - }, - { - TestContextPropertyStrings.ResultsDirectory, - testRunDirectories.InDirectory - }, - { - TestContextPropertyStrings - .TestRunResultsDirectory, - testRunDirectories.InMachineNameDirectory - }, - { - TestContextPropertyStrings - .TestResultsDirectory, - testRunDirectories.InDirectory - }, - { - TestContextPropertyStrings.TestDir, - testRunDirectories.RootDeploymentDirectory - }, - { - TestContextPropertyStrings.TestDeploymentDir, - testRunDirectories.OutDirectory - }, - { - TestContextPropertyStrings.TestLogsDir, - testRunDirectories.InMachineNameDirectory - } - }; - - Assert.IsNotNull(properties); - CollectionAssert.AreEqual(expectedProperties.ToList(), properties.ToList()); - } - [TestMethod] - public void GetDeploymentInformationShouldReturnRunDirectoryInformationIfSourceIsNotNull() + public void DeployShouldCreateDeploymentDirectories() { - // Arrange. TestRunDirectories testRunDirectories; - var testCase = this.GetTestCase(Assembly.GetExecutingAssembly().Location); + var testCase = this.GetTestCase(typeof(DesktopTestDeploymentTests).GetTypeInfo().Assembly.Location); // Setup mocks. var testDeployment = this.CreateAndSetupDeploymentRelatedUtilities(out testRunDirectories); @@ -512,50 +127,8 @@ public void GetDeploymentInformationShouldReturnRunDirectoryInformationIfSourceI Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object)); - // Act. - var properties = TestDeployment.GetDeploymentInformation(Assembly.GetExecutingAssembly().Location); - - // Assert. - var expectedProperties = new Dictionary - { - { - TestContextPropertyStrings.TestRunDirectory, - testRunDirectories.RootDeploymentDirectory - }, - { - TestContextPropertyStrings.DeploymentDirectory, - testRunDirectories.OutDirectory - }, - { - TestContextPropertyStrings.ResultsDirectory, - testRunDirectories.InDirectory - }, - { - TestContextPropertyStrings - .TestRunResultsDirectory, - testRunDirectories.InMachineNameDirectory - }, - { - TestContextPropertyStrings - .TestResultsDirectory, - testRunDirectories.InDirectory - }, - { - TestContextPropertyStrings.TestDir, - testRunDirectories.RootDeploymentDirectory - }, - { - TestContextPropertyStrings.TestDeploymentDir, - testRunDirectories.OutDirectory - }, - { - TestContextPropertyStrings.TestLogsDir, - testRunDirectories.InMachineNameDirectory - } - }; - - Assert.IsNotNull(properties); - CollectionAssert.AreEqual(expectedProperties.ToList(), properties.ToList()); + // matched twice because root deployment and out directory are same in net core + this.mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(testRunDirectories.RootDeploymentDirectory), Times.Once); } #endregion diff --git a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj index c0c9a58892..fd9d5671fc 100644 --- a/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj +++ b/test/UnitTests/PlatformServices.NetCore.Unit.Tests/PlatformServices.NetCore.Unit.Tests.csproj @@ -29,6 +29,7 @@ + @@ -51,7 +52,6 @@ - diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs index 849e7cc57e..f3e59eba8c 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs @@ -15,8 +15,6 @@ namespace MSTestAdapter.PlatformServices.Tests.Deployment using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; -#pragma warning disable SA1649 // File name must match first type name - [TestClass] public class DeploymentItemTests { diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs index 4e4d6c1347..cc2f4b6739 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs @@ -16,8 +16,6 @@ namespace MSTestAdapter.PlatformServices.Tests.Deployment using System.IO; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; -#pragma warning disable SA1649 // File name must match first type name - [TestClass] public class TestRunDirectoriesTests { diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs index a0dc6992b5..088217afaa 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs @@ -16,8 +16,6 @@ namespace MSTestAdapter.PlatformServices.Tests.Extensions using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - [TestClass] public class ExceptionExtensionsTests { diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs index 5f8758c48e..ad9a367823 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs @@ -21,8 +21,6 @@ namespace MSTestAdapter.PlatformServices.Tests.Utilities using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; using Moq; -#pragma warning disable SA1649 // File name must match first type name - [TestClass] public class FileUtilityTests { diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs index e29e32cf27..0cd2bb3157 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs @@ -19,7 +19,6 @@ namespace MSTestAdapter.PlatformServices.Tests.Services using System.Reflection; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; using MSTestAdapter.TestUtilities; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName [TestClass] public class FileOperationsTests diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs index cbb00103ad..4c9bdd038c 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs @@ -19,8 +19,6 @@ namespace MSTestAdapter.PlatformServices.Tests.Services using System.Reflection; using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - [TestClass] public class ReflectionOperationsTests { diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs index 04704db378..0920ce5412 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs @@ -16,8 +16,6 @@ namespace MSTestAdapter.PlatformServices.Tests.Services using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; using Moq; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - [TestClass] public class SettingsProviderTests { diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestContextImplementationTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestContextImplementationTests.cs index cf89e50ec0..c063c1f42e 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestContextImplementationTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestContextImplementationTests.cs @@ -26,8 +26,6 @@ namespace MSTestAdapter.PlatformServices.Tests.Services using Moq; using ITestMethod = Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel.ITestMethod; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - [TestClass] public class TestContextImplementationTests { diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceTests.cs index 389f46121c..66657e8e60 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceTests.cs @@ -20,8 +20,6 @@ namespace MSTestAdapter.PlatformServices.Tests.Services using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; -#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName - [TestClass] public class TestSourceTests { diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13TestDeploymentTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13TestDeploymentTests.cs new file mode 100644 index 0000000000..092bebcfd8 --- /dev/null +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13TestDeploymentTests.cs @@ -0,0 +1,552 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +namespace MSTestAdapter.PlatformServices.Tests.Services +{ + extern alias FrameworkV2Extension; +#if NETCOREAPP1_1 + using Microsoft.VisualStudio.TestTools.UnitTesting; +#else + extern alias FrameworkV1; + extern alias FrameworkV2; + + using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert; + using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert; + using Ignore = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.IgnoreAttribute; + using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute; + using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute; + using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; +#endif + + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Reflection; + using System.Xml; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment; + using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities; + using Microsoft.VisualStudio.TestPlatform.ObjectModel; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; + using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities; + using Moq; + using MSTestAdapter.PlatformServices.Tests.Utilities; + + using TestFrameworkV2Extension = FrameworkV2Extension::Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class TestDeploymentTests + { + private const string DefaultDeploymentItemPath = @"c:\temp"; + private const string DefaultDeploymentItemOutputDirectory = "out"; + + private Mock mockReflectionUtility; + private Mock mockFileUtility; + + private IList warnings; + + [TestInitialize] + public void TestInit() + { + this.mockReflectionUtility = new Mock(); + this.mockFileUtility = new Mock(); + this.warnings = new List(); + + // Reset adapter settings. + MSTestSettingsProvider.Reset(); + } + +#region GetDeploymentItems tests. + + [TestMethod] + public void GetDeploymentItemsReturnsNullWhenNoDeploymentItems() + { + var methodInfo = + typeof(TestDeploymentTests).GetMethod("GetDeploymentItemsReturnsNullWhenNoDeploymentItems"); + + Assert.IsNull(new TestDeployment().GetDeploymentItems(methodInfo, typeof(TestDeploymentTests), this.warnings)); + } + + [TestMethod] + public void GetDeploymentItemsReturnsDeploymentItems() + { + // Arrange. + var testDeployment = new TestDeployment(new DeploymentItemUtility(this.mockReflectionUtility.Object), null, null); + + // setup mocks + var methodLevelDeploymentItems = new[] + { + new KeyValuePair( + DefaultDeploymentItemPath, + DefaultDeploymentItemOutputDirectory) + }; + var classLevelDeploymentItems = new[] + { + new KeyValuePair( + DefaultDeploymentItemPath + "\\temp2", + DefaultDeploymentItemOutputDirectory) + }; + var memberInfo = + typeof(TestDeploymentTests).GetMethod( + "GetDeploymentItemsReturnsDeploymentItems"); + this.SetupDeploymentItems(memberInfo, methodLevelDeploymentItems); + this.SetupDeploymentItems(typeof(TestDeploymentTests).GetTypeInfo(), classLevelDeploymentItems); + + // Act. + var deploymentItems = testDeployment.GetDeploymentItems(memberInfo, typeof(TestDeploymentTests), this.warnings); + + // Assert. + var expectedDeploymentItems = new KeyValuePair[] + { + new KeyValuePair( + DefaultDeploymentItemPath, + DefaultDeploymentItemOutputDirectory), + new KeyValuePair( + DefaultDeploymentItemPath + "\\temp2", + DefaultDeploymentItemOutputDirectory) + }; + + CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray()); + } + +#endregion + +#region Cleanup tests + + [TestMethod] + public void CleanupShouldNotDeleteDirectoriesIfRunDirectoiresIsNull() + { + var testDeployment = new TestDeployment(null, null, this.mockFileUtility.Object); + + testDeployment.Cleanup(); + + this.mockFileUtility.Verify(fu => fu.DeleteDirectories(It.IsAny()), Times.Never); + } + + [TestMethod] + public void CleanupShouldNotDeleteDirectoriesIfRunSettingsSpecifiesSo() + { + string runSettingxml = + @"False"; + StringReader stringReader = new StringReader(runSettingxml); + XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); + MSTestSettingsProvider mstestSettingsProvider = new MSTestSettingsProvider(); + mstestSettingsProvider.Load(reader); + + TestRunDirectories testRunDirectories; + var testCase = this.GetTestCase(typeof(TestDeploymentTests).GetTypeInfo().Assembly.Location); + + // Setup mocks. + var testDeployment = this.CreateAndSetupDeploymentRelatedUtilities(out testRunDirectories); + + var mockRunContext = new Mock(); + mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory); + + Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object)); + + testDeployment.Cleanup(); + + this.mockFileUtility.Verify(fu => fu.DeleteDirectories(It.IsAny()), Times.Never); + } + + [TestMethod] + public void CleanupShouldDeleteRootDeploymentDirectory() + { + TestRunDirectories testRunDirectories; + var testCase = this.GetTestCase(typeof(DeploymentUtilityTests).GetTypeInfo().Assembly.Location); + + // Setup mocks. + var testDeployment = this.CreateAndSetupDeploymentRelatedUtilities(out testRunDirectories); + + var mockRunContext = new Mock(); + mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory); + + Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object)); + + // Act. + testDeployment.Cleanup(); + + this.mockFileUtility.Verify(fu => fu.DeleteDirectories(testRunDirectories.RootDeploymentDirectory), Times.Once); + } + +#endregion + +#region GetDeploymentDirectory tests + + [TestMethod] + public void GetDeploymentDirectoryShouldReturnNullIfDeploymentDirectoryIsNull() + { + Assert.IsNull(new TestDeployment().GetDeploymentDirectory()); + } + + [TestMethod] + public void GetDeploymentDirectoryShouldReturnDeploymentOutputDirectory() + { + TestRunDirectories testRunDirectories; + var testCase = this.GetTestCase(typeof(TestDeploymentTests).GetTypeInfo().Assembly.Location); + + // Setup mocks. + var testDeployment = this.CreateAndSetupDeploymentRelatedUtilities(out testRunDirectories); + + var mockRunContext = new Mock(); + mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory); + + Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object)); + + // Act. + Assert.AreEqual(testRunDirectories.OutDirectory, testDeployment.GetDeploymentDirectory()); + } + +#endregion + +#region Deploy tests + + [TestMethod] + public void DeployShouldReturnFalseWhenDeploymentEnabledSetToFalseButHasDeploymentItems() + { + var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A"); + var kvparray = new[] + { + new KeyValuePair( + DefaultDeploymentItemPath, + DefaultDeploymentItemOutputDirectory) + }; + testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, kvparray); + + var testDeployment = new TestDeployment( + new DeploymentItemUtility(this.mockReflectionUtility.Object), + new DeploymentUtility(), + this.mockFileUtility.Object); + + string runSettingxml = + @"False"; + StringReader stringReader = new StringReader(runSettingxml); + XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); + MSTestSettingsProvider mstestSettingsProvider = new MSTestSettingsProvider(); + mstestSettingsProvider.Load(reader); + + // Deployment should not happen + Assert.IsFalse(testDeployment.Deploy(new List { testCase }, null, null)); + + // Deplyment directories should not be created + Assert.IsNull(testDeployment.GetDeploymentDirectory()); + } + + [TestMethod] + public void DeployShouldReturnFalseWhenDeploymentEnabledSetToFalseAndHasNoDeploymentItems() + { + var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A"); + testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, null); + var testDeployment = new TestDeployment( + new DeploymentItemUtility(this.mockReflectionUtility.Object), + new DeploymentUtility(), + this.mockFileUtility.Object); + + string runSettingxml = + @"False"; + StringReader stringReader = new StringReader(runSettingxml); + XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); + MSTestSettingsProvider mstestSettingsProvider = new MSTestSettingsProvider(); + mstestSettingsProvider.Load(reader); + + // Deployment should not happen + Assert.IsFalse(testDeployment.Deploy(new List { testCase }, null, null)); + + // Deployment directories should get created + Assert.IsNotNull(testDeployment.GetDeploymentDirectory()); + } + + [TestMethod] + public void DeployShouldReturnFalseWhenDeploymentEnabledSetToTrueButHasNoDeploymentItems() + { + var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A"); + testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, null); + var testDeployment = new TestDeployment( + new DeploymentItemUtility(this.mockReflectionUtility.Object), + new DeploymentUtility(), + this.mockFileUtility.Object); + + string runSettingxml = + @"True"; + StringReader stringReader = new StringReader(runSettingxml); + XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); + MSTestSettingsProvider mstestSettingsProvider = new MSTestSettingsProvider(); + mstestSettingsProvider.Load(reader); + + // Deployment should not happen + Assert.IsFalse(testDeployment.Deploy(new List { testCase }, null, null)); + + // Deployment directories should get created + Assert.IsNotNull(testDeployment.GetDeploymentDirectory()); + } + + // [Todo] This test has to have mocks. It actually deploys stuff and we cannot assume that all the dependencies get copied over to bin\debug. + [TestMethod] + [Ignore] + public void DeployShouldReturnTrueWhenDeploymentEnabledSetToTrueAndHasDeploymentItems() + { + var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), typeof(TestDeploymentTests).GetTypeInfo().Assembly.Location); + var kvpArray = new[] + { + new KeyValuePair( + DefaultDeploymentItemPath, + DefaultDeploymentItemOutputDirectory) + }; + testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, kvpArray); + var testDeployment = new TestDeployment( + new DeploymentItemUtility(this.mockReflectionUtility.Object), + new DeploymentUtility(), + this.mockFileUtility.Object); + + string runSettingxml = + @"True"; + StringReader stringReader = new StringReader(runSettingxml); + XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings); + MSTestSettingsProvider mstestSettingsProvider = new MSTestSettingsProvider(); + mstestSettingsProvider.Load(reader); + + // Deployment should happen + Assert.IsTrue(testDeployment.Deploy(new List { testCase }, null, new Mock().Object)); + + // Deployment directories should get created + Assert.IsNotNull(testDeployment.GetDeploymentDirectory()); + } + +#endregion + +#region GetDeploymentInformation tests + + [TestMethod] + public void GetDeploymentInformationShouldReturnAppBaseDirectoryIfRunDirectoryIsNull() + { + TestDeployment.Reset(); + var properties = TestDeployment.GetDeploymentInformation(typeof(TestDeploymentTests).GetTypeInfo().Assembly.Location); + + var applicationBaseDirectory = Path.GetDirectoryName(typeof(TestDeploymentTests).GetTypeInfo().Assembly.Location); + var expectedProperties = new Dictionary + { + { + TestContextPropertyStrings.TestRunDirectory, + applicationBaseDirectory + }, + { + TestContextPropertyStrings.DeploymentDirectory, + applicationBaseDirectory + }, + { + TestContextPropertyStrings.ResultsDirectory, + applicationBaseDirectory + }, + { + TestContextPropertyStrings + .TestRunResultsDirectory, + applicationBaseDirectory + }, + { + TestContextPropertyStrings + .TestResultsDirectory, + applicationBaseDirectory + }, + { + TestContextPropertyStrings.TestDir, + applicationBaseDirectory + }, + { + TestContextPropertyStrings.TestDeploymentDir, + applicationBaseDirectory + }, + { + TestContextPropertyStrings.TestLogsDir, + applicationBaseDirectory + } + }; + Assert.IsNotNull(properties); + CollectionAssert.AreEqual(expectedProperties.ToList(), properties.ToList()); + } + + [TestMethod] + public void GetDeploymentInformationShouldReturnRunDirectoryInformationIfSourceIsNull() + { + // Arrange. + TestRunDirectories testRunDirectories; + var testCase = this.GetTestCase(typeof(TestDeploymentTests).GetTypeInfo().Assembly.Location); + + // Setup mocks. + var testDeployment = this.CreateAndSetupDeploymentRelatedUtilities(out testRunDirectories); + + var mockRunContext = new Mock(); + mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory); + + Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object)); + + // Act. + var properties = TestDeployment.GetDeploymentInformation(null); + + // Assert. + var expectedProperties = new Dictionary + { + { + TestContextPropertyStrings.TestRunDirectory, + testRunDirectories.RootDeploymentDirectory + }, + { + TestContextPropertyStrings.DeploymentDirectory, + testRunDirectories.OutDirectory + }, + { + TestContextPropertyStrings.ResultsDirectory, + testRunDirectories.InDirectory + }, + { + TestContextPropertyStrings + .TestRunResultsDirectory, + testRunDirectories.InMachineNameDirectory + }, + { + TestContextPropertyStrings + .TestResultsDirectory, + testRunDirectories.InDirectory + }, + { + TestContextPropertyStrings.TestDir, + testRunDirectories.RootDeploymentDirectory + }, + { + TestContextPropertyStrings.TestDeploymentDir, + testRunDirectories.OutDirectory + }, + { + TestContextPropertyStrings.TestLogsDir, + testRunDirectories.InMachineNameDirectory + } + }; + + Assert.IsNotNull(properties); + CollectionAssert.AreEqual(expectedProperties.ToList(), properties.ToList()); + } + + [TestMethod] + public void GetDeploymentInformationShouldReturnRunDirectoryInformationIfSourceIsNotNull() + { + // Arrange. + TestRunDirectories testRunDirectories; + var testCase = this.GetTestCase(typeof(TestDeploymentTests).GetTypeInfo().Assembly.Location); + + // Setup mocks. + var testDeployment = this.CreateAndSetupDeploymentRelatedUtilities(out testRunDirectories); + + var mockRunContext = new Mock(); + mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory); + + Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object)); + + // Act. + var properties = TestDeployment.GetDeploymentInformation(typeof(TestDeploymentTests).GetTypeInfo().Assembly.Location); + + // Assert. + var expectedProperties = new Dictionary + { + { + TestContextPropertyStrings.TestRunDirectory, + testRunDirectories.RootDeploymentDirectory + }, + { + TestContextPropertyStrings.DeploymentDirectory, + testRunDirectories.OutDirectory + }, + { + TestContextPropertyStrings.ResultsDirectory, + testRunDirectories.InDirectory + }, + { + TestContextPropertyStrings + .TestRunResultsDirectory, + testRunDirectories.InMachineNameDirectory + }, + { + TestContextPropertyStrings + .TestResultsDirectory, + testRunDirectories.InDirectory + }, + { + TestContextPropertyStrings.TestDir, + testRunDirectories.RootDeploymentDirectory + }, + { + TestContextPropertyStrings.TestDeploymentDir, + testRunDirectories.OutDirectory + }, + { + TestContextPropertyStrings.TestLogsDir, + testRunDirectories.InMachineNameDirectory + } + }; + + Assert.IsNotNull(properties); + CollectionAssert.AreEqual(expectedProperties.ToList(), properties.ToList()); + } + +#endregion + +#region private methods + + private void SetupDeploymentItems(MemberInfo memberInfo, KeyValuePair[] deploymentItems) + { + var deploymentItemAttributes = new List(); + + foreach (var deploymentItem in deploymentItems) + { + deploymentItemAttributes.Add(new TestFrameworkV2Extension.DeploymentItemAttribute(deploymentItem.Key, deploymentItem.Value)); + } + + this.mockReflectionUtility.Setup( + ru => + ru.GetCustomAttributes( + memberInfo, + typeof(TestFrameworkV2Extension.DeploymentItemAttribute))).Returns((object[])deploymentItemAttributes.ToArray()); + } + + private TestCase GetTestCase(string source) + { + var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), source); + var kvpArray = new[] + { + new KeyValuePair( + DefaultDeploymentItemPath, + DefaultDeploymentItemOutputDirectory) + }; + testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, kvpArray); + + return testCase; + } + + private TestDeployment CreateAndSetupDeploymentRelatedUtilities(out TestRunDirectories testRunDirectories) + { + var currentExecutingFolder = Path.GetDirectoryName(typeof(TestDeploymentTests).GetTypeInfo().Assembly.Location); + + testRunDirectories = new TestRunDirectories(currentExecutingFolder); + + this.mockFileUtility.Setup(fu => fu.DoesDirectoryExist(It.Is(s => !s.EndsWith(".dll")))).Returns(true); + this.mockFileUtility.Setup(fu => fu.DoesFileExist(It.IsAny())).Returns(true); + var mockAssemblyUtility = new Mock(); +#if !NETCOREAPP1_1 + mockAssemblyUtility.Setup( + au => au.GetFullPathToDependentAssemblies(It.IsAny(), It.IsAny(), out this.warnings)) + .Returns(new string[] { }); + mockAssemblyUtility.Setup( + au => au.GetSatelliteAssemblies(It.IsAny())) + .Returns(new List { }); +#endif + this.mockFileUtility.Setup(fu => fu.GetNextIterationDirectoryName(It.IsAny(), It.IsAny())) + .Returns(testRunDirectories.RootDeploymentDirectory); + + var deploymentItemUtility = new DeploymentItemUtility(this.mockReflectionUtility.Object); + + return new TestDeployment( + deploymentItemUtility, + new DeploymentUtility(deploymentItemUtility, mockAssemblyUtility.Object, this.mockFileUtility.Object), + this.mockFileUtility.Object); + } +#endregion + } +} From 737abcb04ac3324eca4f2fe329193fc4904e69f0 Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Mon, 1 Apr 2019 12:01:32 +0530 Subject: [PATCH 23/24] removing comment and pubxml --- .../DeploymentTestProjectNetCore.csproj | 1 + .../Properties/PublishProfiles/FolderProfile.pubxml | 13 ------------- .../Utilities/ns13DeploymentItemUtilityTests.cs | 2 -- 3 files changed, 1 insertion(+), 15 deletions(-) delete mode 100644 test/E2ETests/TestAssets/DeploymentTestProjectNetCore/Properties/PublishProfiles/FolderProfile.pubxml diff --git a/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj b/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj index a6bc96eada..be5a9e7536 100644 --- a/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj +++ b/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/DeploymentTestProjectNetCore.csproj @@ -15,6 +15,7 @@ + diff --git a/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/Properties/PublishProfiles/FolderProfile.pubxml b/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/Properties/PublishProfiles/FolderProfile.pubxml deleted file mode 100644 index 2fd113351c..0000000000 --- a/test/E2ETests/TestAssets/DeploymentTestProjectNetCore/Properties/PublishProfiles/FolderProfile.pubxml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - FileSystem - Release - Any CPU - netcoreapp2.1 - ..\..\..\..\artifacts\TestAssets\netcoreapp2.1 - - \ No newline at end of file diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs index b98726dda0..83f29aac3f 100644 --- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs +++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs @@ -33,8 +33,6 @@ namespace MSTestAdapter.PlatformServices.Tests.Utilities using TestFrameworkV2Extension = FrameworkV2Extension::Microsoft.VisualStudio.TestTools.UnitTesting; - // using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute; - // using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute; [TestClass] #pragma warning disable SA1649 // File name must match first type name public class DeploymentItemUtilityTests From 6396799da0d5e5120d64822553b75526ae6dde4d Mon Sep 17 00:00:00 2001 From: Ankit Arora Date: Mon, 1 Apr 2019 15:13:26 +0530 Subject: [PATCH 24/24] changes in accordance with timeout commit --- TestFx.sln | 2 ++ src/TestFramework/Extension.Core/NetCoreTestContext.cs | 7 ++++++- test/E2ETests/Smoke.E2E.Tests/DeploymentTests.cs | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/TestFx.sln b/TestFx.sln index 27eeeb952d..efe419e3a9 100644 --- a/TestFx.sln +++ b/TestFx.sln @@ -180,6 +180,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestProjectForAssemblyResol EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataRowTestProject", "test\E2ETests\TestAssets\DataRowTestProject\DataRowTestProject.csproj", "{7FB80AAB-7123-4416-B6CD-8D3D69AA83F1}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TimeoutTestProject", "test\E2ETests\TestAssets\TimeoutTestProject\TimeoutTestProject.csproj", "{4F0B2ACF-1341-42AF-918C-669A6D5CEA2B}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DeploymentTestProjectNetCore", "test\E2ETests\TestAssets\DeploymentTestProjectNetCore\DeploymentTestProjectNetCore.csproj", "{26F0B8EF-92D4-4A23-ACB4-D1B662F0EEBE}" EndProject Global diff --git a/src/TestFramework/Extension.Core/NetCoreTestContext.cs b/src/TestFramework/Extension.Core/NetCoreTestContext.cs index e9689e3cce..644d75ce01 100644 --- a/src/TestFramework/Extension.Core/NetCoreTestContext.cs +++ b/src/TestFramework/Extension.Core/NetCoreTestContext.cs @@ -5,9 +5,9 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting { using System; using System.Collections; - using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Globalization; + using System.Threading; /// /// Used to store information that is provided to unit tests. @@ -21,6 +21,11 @@ public abstract class TestContext #region Test run deployment directories + /// + /// Gets or sets the cancellation token source. This token source is cancelled when test timesout. Also when explicitly cancelled the test will be aborted + /// + public virtual CancellationTokenSource CancellationTokenSource { get; protected set; } + /// /// Gets base directory for the test run, under which deployed files and result files are stored. /// diff --git a/test/E2ETests/Smoke.E2E.Tests/DeploymentTests.cs b/test/E2ETests/Smoke.E2E.Tests/DeploymentTests.cs index f73f35db79..c2295d8b7c 100644 --- a/test/E2ETests/Smoke.E2E.Tests/DeploymentTests.cs +++ b/test/E2ETests/Smoke.E2E.Tests/DeploymentTests.cs @@ -39,7 +39,7 @@ public void ValidateTestSourceLocationDeploymentNetCore() { this.InvokeVsTestForExecution(new string[] { TestAssemblyNetCore }, null); this.ValidatePassedTestsContain("DeploymentTestProjectNetCore.DeploymentTestProjectNetCore.FailIfFilePresent", "DeploymentTestProjectNetCore.DeploymentTestProjectNetCore.PassIfDeclaredFilesPresent"); - this.ValidateFailedTestsContain("DeploymentTestProjectNetCore.dll", "DeploymentTestProjectNetCore.DeploymentTestProjectNetCore.PassIfFilePresent"); + this.ValidateFailedTestsContain("DeploymentTestProjectNetCore.dll", true, "DeploymentTestProjectNetCore.DeploymentTestProjectNetCore.PassIfFilePresent"); } } }