backup folder cleanup to make tests using TestAssets rerunnable
This commit is contained in:
parent
9b28fbecd6
commit
05daa15ea1
1 changed files with 36 additions and 24 deletions
|
@ -16,35 +16,47 @@ namespace Microsoft.DotNet.TestFramework
|
||||||
{
|
{
|
||||||
public class TestAssetInstance
|
public class TestAssetInstance
|
||||||
{
|
{
|
||||||
private TestAssetInfo _testAssetInfo;
|
|
||||||
|
|
||||||
private DirectoryInfo _root;
|
|
||||||
|
|
||||||
public DirectoryInfo Root
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return _root;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public TestAssetInstance(TestAssetInfo testAssetInfo, DirectoryInfo root)
|
public TestAssetInstance(TestAssetInfo testAssetInfo, DirectoryInfo root)
|
||||||
{
|
{
|
||||||
_testAssetInfo = testAssetInfo;
|
if (testAssetInfo == null)
|
||||||
|
|
||||||
_root = root;
|
|
||||||
|
|
||||||
if (root.Exists)
|
|
||||||
{
|
{
|
||||||
root.Delete(recursive: true);
|
throw new ArgumentException(nameof(testAssetInfo));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (root == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException(nameof(root));
|
||||||
}
|
}
|
||||||
|
|
||||||
root.Create();
|
TestAssetInfo = testAssetInfo;
|
||||||
|
|
||||||
|
Root = root;
|
||||||
|
|
||||||
|
MigrationBackupRoot = new DirectoryInfo(Path.Combine(root.Parent.FullName, "backup"));
|
||||||
|
|
||||||
|
if (Root.Exists)
|
||||||
|
{
|
||||||
|
Root.Delete(recursive: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
Root.Create();
|
||||||
|
|
||||||
|
if (MigrationBackupRoot.Exists)
|
||||||
|
{
|
||||||
|
MigrationBackupRoot.Delete(recursive: true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public DirectoryInfo MigrationBackupRoot { get; }
|
||||||
|
|
||||||
|
public DirectoryInfo Root { get; }
|
||||||
|
|
||||||
|
public TestAssetInfo TestAssetInfo { get; }
|
||||||
|
|
||||||
|
|
||||||
public TestAssetInstance WithSourceFiles()
|
public TestAssetInstance WithSourceFiles()
|
||||||
{
|
{
|
||||||
var filesToCopy = _testAssetInfo.GetSourceFiles();
|
var filesToCopy = TestAssetInfo.GetSourceFiles();
|
||||||
|
|
||||||
CopyFiles(filesToCopy);
|
CopyFiles(filesToCopy);
|
||||||
|
|
||||||
|
@ -53,7 +65,7 @@ namespace Microsoft.DotNet.TestFramework
|
||||||
|
|
||||||
public TestAssetInstance WithRestoreFiles()
|
public TestAssetInstance WithRestoreFiles()
|
||||||
{
|
{
|
||||||
var filesToCopy = _testAssetInfo.GetRestoreFiles();
|
var filesToCopy = TestAssetInfo.GetRestoreFiles();
|
||||||
|
|
||||||
CopyFiles(filesToCopy);
|
CopyFiles(filesToCopy);
|
||||||
|
|
||||||
|
@ -62,7 +74,7 @@ namespace Microsoft.DotNet.TestFramework
|
||||||
|
|
||||||
public TestAssetInstance WithBuildFiles()
|
public TestAssetInstance WithBuildFiles()
|
||||||
{
|
{
|
||||||
var filesToCopy = _testAssetInfo.GetBuildFiles();
|
var filesToCopy = TestAssetInfo.GetBuildFiles();
|
||||||
|
|
||||||
CopyFiles(filesToCopy);
|
CopyFiles(filesToCopy);
|
||||||
|
|
||||||
|
@ -81,7 +93,7 @@ namespace Microsoft.DotNet.TestFramework
|
||||||
</packageSources>
|
</packageSources>
|
||||||
</configuration>";
|
</configuration>";
|
||||||
content = content.Replace("$fullpath$", nugetCache);
|
content = content.Replace("$fullpath$", nugetCache);
|
||||||
|
|
||||||
using (var newNuGetConfigStream =
|
using (var newNuGetConfigStream =
|
||||||
new FileStream(newNuGetConfig.FullName, FileMode.Create, FileAccess.Write))
|
new FileStream(newNuGetConfig.FullName, FileMode.Create, FileAccess.Write))
|
||||||
{
|
{
|
||||||
|
@ -96,7 +108,7 @@ namespace Microsoft.DotNet.TestFramework
|
||||||
{
|
{
|
||||||
foreach (var file in filesToCopy)
|
foreach (var file in filesToCopy)
|
||||||
{
|
{
|
||||||
var relativePath = file.FullName.Substring(_testAssetInfo.Root.FullName.Length + 1);
|
var relativePath = file.FullName.Substring(TestAssetInfo.Root.FullName.Length + 1);
|
||||||
|
|
||||||
var newPath = Path.Combine(Root.FullName, relativePath);
|
var newPath = Path.Combine(Root.FullName, relativePath);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue