Removing Microsoft.DotNet.TestFramework from the product code and from the SDK deployment and moving the code to the test folder.
This commit is contained in:
parent
35793cf406
commit
3efd44f935
18 changed files with 25 additions and 10 deletions
|
@ -15,7 +15,7 @@
|
|||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Sln.Internal\Microsoft.DotNet.Cli.Sln.Internal.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
|
|
@ -80,6 +80,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.DotNet.MSBuildSdk
|
|||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "dotnet-clean.Tests", "dotnet-clean.Tests\dotnet-clean.Tests.csproj", "{D9A582B8-1FE2-45D5-B139-0BA828FE3691}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.DotNet.TestFramework", "Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj", "{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
|
@ -522,6 +524,18 @@ Global
|
|||
{D9A582B8-1FE2-45D5-B139-0BA828FE3691}.Release|x64.Build.0 = Release|x64
|
||||
{D9A582B8-1FE2-45D5-B139-0BA828FE3691}.Release|x86.ActiveCfg = Release|x86
|
||||
{D9A582B8-1FE2-45D5-B139-0BA828FE3691}.Release|x86.Build.0 = Release|x86
|
||||
{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}.Debug|x64.Build.0 = Debug|x64
|
||||
{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}.Debug|x86.ActiveCfg = Debug|x86
|
||||
{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}.Debug|x86.Build.0 = Debug|x86
|
||||
{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}.Release|x64.ActiveCfg = Release|x64
|
||||
{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}.Release|x64.Build.0 = Release|x64
|
||||
{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}.Release|x86.ActiveCfg = Release|x86
|
||||
{D23AFC9C-8FD5-45DD-A84C-0E6528C42F0E}.Release|x86.Build.0 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.IO;
|
||||
|
||||
namespace Microsoft.DotNet.TestFramework
|
||||
{
|
||||
internal static class DirectoryInfoExtensions
|
||||
{
|
||||
public static bool Contains(this DirectoryInfo subject, FileSystemInfo target)
|
||||
{
|
||||
return target.FullName.StartsWith(subject.FullName);
|
||||
}
|
||||
|
||||
public static DirectoryInfo GetDirectory(this DirectoryInfo subject, params string [] directoryNames)
|
||||
{
|
||||
return new DirectoryInfo(Path.Combine(subject.FullName, Path.Combine(directoryNames)));
|
||||
}
|
||||
|
||||
public static FileInfo GetFile(this DirectoryInfo subject, string fileName)
|
||||
{
|
||||
return new FileInfo(Path.Combine(subject.FullName, fileName));
|
||||
}
|
||||
|
||||
public static void EnsureExistsAndEmpty(this DirectoryInfo subject)
|
||||
{
|
||||
if (subject.Exists)
|
||||
{
|
||||
subject.Delete(true);
|
||||
}
|
||||
|
||||
subject.Create();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>Microsoft.DotNet.TestFramework Class Library</Description>
|
||||
<VersionPrefix>$(CliVersionPrefix)</VersionPrefix>
|
||||
<TargetFramework>netstandard1.5</TargetFramework>
|
||||
<AssemblyOriginatorKeyFile>../../tools/Key.snk</AssemblyOriginatorKeyFile>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
<PublicSign Condition=" '$(OS)' != 'Windows_NT' ">true</PublicSign>
|
||||
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,6 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Reflection;
|
||||
|
||||
[assembly: AssemblyMetadataAttribute("Serviceable", "True")]
|
80
test/Microsoft.DotNet.TestFramework/TestAssetInfo.cs
Normal file
80
test/Microsoft.DotNet.TestFramework/TestAssetInfo.cs
Normal file
|
@ -0,0 +1,80 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Microsoft.DotNet.TestFramework
|
||||
{
|
||||
public class TestAssetInfo
|
||||
{
|
||||
private readonly string [] FilesToExclude = { ".DS_Store", ".noautobuild" };
|
||||
|
||||
public string AssetName { get; private set; }
|
||||
|
||||
public FileInfo DotnetExeFile => _testAssets.DotnetCsprojExe;
|
||||
|
||||
public string ProjectFilePattern => "*.csproj";
|
||||
|
||||
public DirectoryInfo Root { get; private set; }
|
||||
|
||||
private TestAssets _testAssets { get; }
|
||||
|
||||
internal TestAssetInfo(DirectoryInfo root, string assetName, TestAssets testAssets)
|
||||
{
|
||||
if (root == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(root));
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(assetName))
|
||||
{
|
||||
throw new ArgumentException("Argument cannot be null or whitespace", nameof(assetName));
|
||||
}
|
||||
|
||||
if (testAssets == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(testAssets));
|
||||
}
|
||||
|
||||
Root = root;
|
||||
|
||||
AssetName = assetName;
|
||||
|
||||
_testAssets = testAssets;
|
||||
}
|
||||
|
||||
public TestAssetInstance CreateInstance([CallerMemberName] string callingMethod = "", string identifier = "")
|
||||
{
|
||||
var instancePath = GetTestDestinationDirectory(callingMethod, identifier);
|
||||
|
||||
var testInstance = new TestAssetInstance(this, instancePath);
|
||||
|
||||
return testInstance;
|
||||
}
|
||||
|
||||
internal IEnumerable<FileInfo> GetSourceFiles()
|
||||
{
|
||||
ThrowIfTestAssetDoesNotExist();
|
||||
|
||||
return Root.GetFiles("*.*", SearchOption.AllDirectories)
|
||||
.Where(f => !FilesToExclude.Contains(f.Name));
|
||||
}
|
||||
|
||||
private DirectoryInfo GetTestDestinationDirectory(string callingMethod, string identifier)
|
||||
{
|
||||
return _testAssets.CreateTestDirectory(AssetName, callingMethod, identifier);
|
||||
}
|
||||
|
||||
private void ThrowIfTestAssetDoesNotExist()
|
||||
{
|
||||
if (!Root.Exists)
|
||||
{
|
||||
throw new DirectoryNotFoundException($"Directory not found at '{Root.FullName}'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
308
test/Microsoft.DotNet.TestFramework/TestAssetInstance.cs
Normal file
308
test/Microsoft.DotNet.TestFramework/TestAssetInstance.cs
Normal file
|
@ -0,0 +1,308 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools.Common;
|
||||
|
||||
namespace Microsoft.DotNet.TestFramework
|
||||
{
|
||||
public class TestAssetInstance
|
||||
{
|
||||
public DirectoryInfo MigrationBackupRoot { get; }
|
||||
|
||||
public DirectoryInfo Root { get; }
|
||||
|
||||
public TestAssetInfo TestAssetInfo { get; }
|
||||
|
||||
private bool _filesCopied = false;
|
||||
|
||||
private bool _restored = false;
|
||||
|
||||
private bool _built = false;
|
||||
|
||||
public static string CurrentRuntimeFrameworkVersion = new Muxer().SharedFxVersion;
|
||||
|
||||
public TestAssetInstance(TestAssetInfo testAssetInfo, DirectoryInfo root)
|
||||
{
|
||||
if (testAssetInfo == null)
|
||||
{
|
||||
throw new ArgumentException(nameof(testAssetInfo));
|
||||
}
|
||||
|
||||
if (root == null)
|
||||
{
|
||||
throw new ArgumentException(nameof(root));
|
||||
}
|
||||
|
||||
TestAssetInfo = testAssetInfo;
|
||||
|
||||
Root = root;
|
||||
|
||||
MigrationBackupRoot = new DirectoryInfo(Path.Combine(root.Parent.FullName, "backup"));
|
||||
|
||||
if (Root.Exists)
|
||||
{
|
||||
try
|
||||
{
|
||||
Root.Delete(recursive: true);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
throw new InvalidOperationException("Unable to delete directory: " + Root.FullName, ex);
|
||||
}
|
||||
}
|
||||
|
||||
Root.Create();
|
||||
|
||||
if (MigrationBackupRoot.Exists)
|
||||
{
|
||||
MigrationBackupRoot.Delete(recursive: true);
|
||||
}
|
||||
}
|
||||
|
||||
public TestAssetInstance WithSourceFiles()
|
||||
{
|
||||
if (!_filesCopied)
|
||||
{
|
||||
CopySourceFiles();
|
||||
|
||||
_filesCopied = true;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestAssetInstance WithRestoreFiles()
|
||||
{
|
||||
if (!_restored)
|
||||
{
|
||||
WithSourceFiles();
|
||||
|
||||
RestoreAllProjects();
|
||||
|
||||
_restored = true;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestAssetInstance WithBuildFiles()
|
||||
{
|
||||
if (!_built)
|
||||
{
|
||||
WithRestoreFiles();
|
||||
|
||||
BuildRootProjectOrSolution();
|
||||
|
||||
_built = true;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestAssetInstance WithNuGetConfig(string nugetCache)
|
||||
{
|
||||
var thisAssembly = typeof(TestAssetInstance).GetTypeInfo().Assembly;
|
||||
var newNuGetConfig = Root.GetFile("NuGet.Config");
|
||||
|
||||
var content = @"<?xml version=""1.0"" encoding=""utf-8""?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key=""dotnet-core"" value=""https://dotnet.myget.org/F/dotnet-core/api/v3/index.json"" />
|
||||
<add key=""test-packages"" value=""$fullpath$"" />
|
||||
</packageSources>
|
||||
</configuration>";
|
||||
content = content.Replace("$fullpath$", nugetCache);
|
||||
|
||||
using (var newNuGetConfigStream =
|
||||
new FileStream(newNuGetConfig.FullName, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
var contentBytes = new UTF8Encoding(true).GetBytes(content);
|
||||
newNuGetConfigStream.Write(contentBytes, 0, contentBytes.Length);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestAssetInstance WithEmptyGlobalJson()
|
||||
{
|
||||
var file = Root.Parent.GetFile("global.json");
|
||||
|
||||
File.WriteAllText(file.FullName, @"{}");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestAssetInstance WithProjectChanges(Action<XDocument> xmlAction)
|
||||
{
|
||||
return WithProjectChanges((path, project) => xmlAction(project));
|
||||
}
|
||||
|
||||
public TestAssetInstance WithProjectChanges(Action<string, XDocument> xmlAction)
|
||||
{
|
||||
var projectFileInfos = Root.GetFiles("*.*proj", SearchOption.AllDirectories);
|
||||
|
||||
foreach (var projectFileInfo in projectFileInfos)
|
||||
{
|
||||
var projectFile = projectFileInfo.FullName;
|
||||
var project = XDocument.Load(projectFile);
|
||||
|
||||
xmlAction(projectFile, project);
|
||||
|
||||
using (var file = File.CreateText(projectFile))
|
||||
{
|
||||
project.Save(file);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public TestAssetInstance UseCurrentRuntimeFrameworkVersion()
|
||||
{
|
||||
return WithProjectChanges(project =>
|
||||
{
|
||||
var ns = project.Root.Name.Namespace;
|
||||
|
||||
var propertyGroup = project.Root.Elements(ns + "PropertyGroup").LastOrDefault();
|
||||
if (propertyGroup == null)
|
||||
{
|
||||
propertyGroup = new XElement(ns + "PropertyGroup");
|
||||
project.Root.Add(propertyGroup);
|
||||
}
|
||||
|
||||
propertyGroup.Add(new XElement(ns + "RuntimeFrameworkVersion", CurrentRuntimeFrameworkVersion));
|
||||
});
|
||||
}
|
||||
|
||||
private static string RebasePath(string path, string oldBaseDirectory, string newBaseDirectory)
|
||||
{
|
||||
path = Path.IsPathRooted(path) ? PathUtility.GetRelativePath(PathUtility.EnsureTrailingSlash(oldBaseDirectory), path) : path;
|
||||
return Path.Combine(newBaseDirectory, path);
|
||||
}
|
||||
|
||||
private void CopySourceFiles()
|
||||
{
|
||||
var filesToCopy = TestAssetInfo.GetSourceFiles();
|
||||
foreach (var file in filesToCopy)
|
||||
{
|
||||
var newPath = RebasePath(file.FullName, TestAssetInfo.Root.FullName, Root.FullName);
|
||||
|
||||
var newFile = new FileInfo(newPath);
|
||||
|
||||
PathUtility.EnsureDirectoryExists(newFile.Directory.FullName);
|
||||
|
||||
CopyFileAdjustingPaths(file, newFile);
|
||||
}
|
||||
}
|
||||
|
||||
private void CopyFileAdjustingPaths(FileInfo source, FileInfo destination)
|
||||
{
|
||||
if (string.Equals(source.Name, "nuget.config", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
CopyNugetConfigAdjustingPath(source, destination);
|
||||
}
|
||||
else
|
||||
{
|
||||
source.CopyTo(destination.FullName);
|
||||
}
|
||||
}
|
||||
|
||||
private void CopyNugetConfigAdjustingPath(FileInfo source, FileInfo destination)
|
||||
{
|
||||
var doc = XDocument.Load(source.FullName, LoadOptions.PreserveWhitespace);
|
||||
foreach (var packageSource in doc.Root.Element("packageSources").Elements("add").Attributes("value"))
|
||||
{
|
||||
if (!Path.IsPathRooted(packageSource.Value))
|
||||
{
|
||||
string fullPathAtSource = Path.GetFullPath(Path.Combine(source.Directory.FullName, packageSource.Value));
|
||||
if (!PathUtility.IsChildOfDirectory(TestAssetInfo.Root.FullName, fullPathAtSource))
|
||||
{
|
||||
packageSource.Value = fullPathAtSource;
|
||||
}
|
||||
}
|
||||
|
||||
using (var file = new FileStream(
|
||||
destination.FullName,
|
||||
FileMode.CreateNew,
|
||||
FileAccess.ReadWrite))
|
||||
{
|
||||
doc.Save(file, SaveOptions.None);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildRootProjectOrSolution()
|
||||
{
|
||||
string[] args = new string[] { "build" };
|
||||
|
||||
Console.WriteLine($"TestAsset Build '{TestAssetInfo.AssetName}'");
|
||||
|
||||
var commandResult = Command.Create(TestAssetInfo.DotnetExeFile.FullName, args)
|
||||
.WorkingDirectory(Root.FullName)
|
||||
.CaptureStdOut()
|
||||
.CaptureStdErr()
|
||||
.Execute();
|
||||
|
||||
int exitCode = commandResult.ExitCode;
|
||||
|
||||
if (exitCode != 0)
|
||||
{
|
||||
Console.WriteLine(commandResult.StdOut);
|
||||
|
||||
Console.WriteLine(commandResult.StdErr);
|
||||
|
||||
string message = string.Format($"TestAsset Build '{TestAssetInfo.AssetName}' Failed with {exitCode}");
|
||||
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerable<FileInfo> GetProjectFiles()
|
||||
{
|
||||
return Root.GetFiles(TestAssetInfo.ProjectFilePattern, SearchOption.AllDirectories);
|
||||
}
|
||||
|
||||
private void Restore(FileInfo projectFile)
|
||||
{
|
||||
var restoreArgs = new string[] { "restore", projectFile.FullName };
|
||||
|
||||
var commandResult = Command.Create(TestAssetInfo.DotnetExeFile.FullName, restoreArgs)
|
||||
.CaptureStdOut()
|
||||
.CaptureStdErr()
|
||||
.Execute();
|
||||
|
||||
int exitCode = commandResult.ExitCode;
|
||||
|
||||
if (exitCode != 0)
|
||||
{
|
||||
Console.WriteLine(commandResult.StdOut);
|
||||
|
||||
Console.WriteLine(commandResult.StdErr);
|
||||
|
||||
string message = string.Format($"TestAsset Restore '{TestAssetInfo.AssetName}'@'{projectFile.FullName}' Failed with {exitCode}");
|
||||
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
|
||||
private void RestoreAllProjects()
|
||||
{
|
||||
Console.WriteLine($"TestAsset Restore '{TestAssetInfo.AssetName}'");
|
||||
|
||||
foreach (var projFile in GetProjectFiles())
|
||||
{
|
||||
Restore(projFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
|
||||
namespace Microsoft.DotNet.TestFramework
|
||||
{
|
||||
public class TestAssetInventoryFiles
|
||||
{
|
||||
private FileInfo _source;
|
||||
|
||||
private FileInfo _restore;
|
||||
|
||||
private FileInfo _build;
|
||||
|
||||
public FileInfo Source
|
||||
{
|
||||
get
|
||||
{
|
||||
_source.Refresh();
|
||||
|
||||
return _source;
|
||||
}
|
||||
|
||||
private set
|
||||
{
|
||||
_source = value;
|
||||
}
|
||||
}
|
||||
|
||||
public FileInfo Restore
|
||||
{
|
||||
get
|
||||
{
|
||||
_restore.Refresh();
|
||||
|
||||
return _restore;
|
||||
}
|
||||
|
||||
private set
|
||||
{
|
||||
_restore = value;
|
||||
}
|
||||
}
|
||||
|
||||
public FileInfo Build
|
||||
{
|
||||
get
|
||||
{
|
||||
_build.Refresh();
|
||||
|
||||
return _build;
|
||||
}
|
||||
|
||||
private set
|
||||
{
|
||||
_build = value;
|
||||
}
|
||||
}
|
||||
|
||||
public TestAssetInventoryFiles(DirectoryInfo inventoryFileDirectory)
|
||||
{
|
||||
Source = new FileInfo(Path.Combine(inventoryFileDirectory.FullName, "source.txt"));
|
||||
|
||||
Restore = new FileInfo(Path.Combine(inventoryFileDirectory.FullName, "restore.txt"));
|
||||
|
||||
Build = new FileInfo(Path.Combine(inventoryFileDirectory.FullName, "build.txt"));
|
||||
}
|
||||
|
||||
public IEnumerable<FileInfo> AllInventoryFiles
|
||||
{
|
||||
get
|
||||
{
|
||||
return new List<FileInfo>
|
||||
{
|
||||
Source,
|
||||
Restore,
|
||||
Build
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
22
test/Microsoft.DotNet.TestFramework/TestAssetKinds.cs
Normal file
22
test/Microsoft.DotNet.TestFramework/TestAssetKinds.cs
Normal file
|
@ -0,0 +1,22 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
|
||||
namespace Microsoft.DotNet.TestFramework
|
||||
{
|
||||
public class TestAssetKinds
|
||||
{
|
||||
public static string DesktopTestProjects = "DesktopTestProjects";
|
||||
|
||||
public static string TestProjects = "TestProjects";
|
||||
|
||||
public static string NonRestoredTestProjects = "NonRestoredTestProjects";
|
||||
}
|
||||
}
|
91
test/Microsoft.DotNet.TestFramework/TestAssets.cs
Normal file
91
test/Microsoft.DotNet.TestFramework/TestAssets.cs
Normal file
|
@ -0,0 +1,91 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
|
||||
namespace Microsoft.DotNet.TestFramework
|
||||
{
|
||||
public class TestAssets
|
||||
{
|
||||
private DirectoryInfo _root;
|
||||
|
||||
private FileInfo _dotnetCsprojExe;
|
||||
|
||||
private string _testWorkingFolder;
|
||||
|
||||
public FileInfo DotnetCsprojExe => _dotnetCsprojExe;
|
||||
|
||||
public TestAssets(DirectoryInfo assetsRoot, FileInfo dotnetCsprojExe, string testWorkingFolder)
|
||||
{
|
||||
if (assetsRoot == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(assetsRoot));
|
||||
}
|
||||
|
||||
if (dotnetCsprojExe == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(dotnetCsprojExe));
|
||||
}
|
||||
|
||||
if (!assetsRoot.Exists)
|
||||
{
|
||||
throw new DirectoryNotFoundException($"Directory not found at '{assetsRoot}'");
|
||||
}
|
||||
|
||||
if (!dotnetCsprojExe.Exists)
|
||||
{
|
||||
throw new FileNotFoundException("Csproj dotnet executable must exist", dotnetCsprojExe.FullName);
|
||||
}
|
||||
|
||||
_root = assetsRoot;
|
||||
|
||||
_dotnetCsprojExe = dotnetCsprojExe;
|
||||
_testWorkingFolder = testWorkingFolder;
|
||||
}
|
||||
|
||||
public TestAssetInfo Get(string name)
|
||||
{
|
||||
return Get(TestAssetKinds.TestProjects, name);
|
||||
}
|
||||
|
||||
public TestAssetInfo Get(string kind, string name)
|
||||
{
|
||||
var assetDirectory = new DirectoryInfo(Path.Combine(_root.FullName, kind, name));
|
||||
|
||||
return new TestAssetInfo(
|
||||
assetDirectory,
|
||||
name,
|
||||
this);
|
||||
}
|
||||
|
||||
public DirectoryInfo CreateTestDirectory(string testProjectName = "temp", [CallerMemberName] string callingMethod = "", string identifier = "")
|
||||
{
|
||||
var testDestination = GetTestDestinationDirectoryPath(testProjectName, callingMethod, identifier);
|
||||
|
||||
var testDirectory = new DirectoryInfo(testDestination);
|
||||
|
||||
testDirectory.EnsureExistsAndEmpty();
|
||||
|
||||
return testDirectory;
|
||||
}
|
||||
|
||||
private string GetTestDestinationDirectoryPath(string testProjectName, string callingMethod, string identifier)
|
||||
{
|
||||
#if NET451
|
||||
string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
|
||||
#else
|
||||
string baseDirectory = AppContext.BaseDirectory;
|
||||
#endif
|
||||
// Find the name of the assembly the test comes from based on the the base directory and how the output path has been constructed
|
||||
string testAssemblyName = new DirectoryInfo(baseDirectory).Parent.Parent.Name;
|
||||
|
||||
return Path.Combine(_testWorkingFolder, testAssemblyName, callingMethod + identifier, testProjectName);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj" />
|
||||
</ItemGroup>
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Microsoft.DotNet.Tools.Tests.Utilities\Microsoft.DotNet.Tools.Tests.Utilities.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Sln.Internal\Microsoft.DotNet.Cli.Sln.Internal.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj" />
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Sln.Internal\Microsoft.DotNet.Cli.Sln.Internal.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj" />
|
||||
<ProjectReference Include="..\..\src\dotnet\dotnet.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Sln.Internal\Microsoft.DotNet.Cli.Sln.Internal.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj" />
|
||||
<ProjectReference Include="..\..\src\dotnet\dotnet.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Sln.Internal\Microsoft.DotNet.Cli.Sln.Internal.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj" />
|
||||
<ProjectReference Include="..\..\src\dotnet\dotnet.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Sln.Internal\Microsoft.DotNet.Cli.Sln.Internal.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.Cli.Utils\Microsoft.DotNet.Cli.Utils.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.InternalAbstractions\Microsoft.DotNet.InternalAbstractions.csproj" />
|
||||
<ProjectReference Include="..\..\src\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj" />
|
||||
<ProjectReference Include="..\Microsoft.DotNet.TestFramework\Microsoft.DotNet.TestFramework.csproj" />
|
||||
<ProjectReference Include="..\..\src\dotnet\dotnet.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue