2016-10-28 01:46:43 +00:00
|
|
|
|
// 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" };
|
|
|
|
|
|
2017-02-10 18:54:05 +00:00
|
|
|
|
public string AssetName { get; private set; }
|
2017-02-10 17:49:21 +00:00
|
|
|
|
|
2017-08-30 00:59:34 +00:00
|
|
|
|
public FileInfo DotnetExeFile => _testAssets.DotnetCsprojExe;
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2017-08-30 00:59:34 +00:00
|
|
|
|
public string ProjectFilePattern => "*.csproj";
|
2017-01-06 09:40:26 +00:00
|
|
|
|
|
2017-02-10 18:54:05 +00:00
|
|
|
|
public DirectoryInfo Root { get; private set; }
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2017-08-30 00:59:34 +00:00
|
|
|
|
private TestAssets _testAssets { get; }
|
|
|
|
|
|
|
|
|
|
internal TestAssetInfo(DirectoryInfo root, string assetName, TestAssets testAssets)
|
2016-10-28 01:46:43 +00:00
|
|
|
|
{
|
2017-01-06 09:40:26 +00:00
|
|
|
|
if (root == null)
|
2016-10-28 01:46:43 +00:00
|
|
|
|
{
|
2017-01-06 09:40:26 +00:00
|
|
|
|
throw new ArgumentNullException(nameof(root));
|
2016-10-28 01:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 09:40:26 +00:00
|
|
|
|
if (string.IsNullOrWhiteSpace(assetName))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Argument cannot be null or whitespace", nameof(assetName));
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-30 00:59:34 +00:00
|
|
|
|
if (testAssets == null)
|
2017-01-06 09:40:26 +00:00
|
|
|
|
{
|
2017-08-30 00:59:34 +00:00
|
|
|
|
throw new ArgumentNullException(nameof(testAssets));
|
2017-01-06 09:40:26 +00:00
|
|
|
|
}
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2017-02-10 18:54:05 +00:00
|
|
|
|
Root = root;
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2017-02-10 18:54:05 +00:00
|
|
|
|
AssetName = assetName;
|
2017-01-06 09:40:26 +00:00
|
|
|
|
|
2017-08-30 00:59:34 +00:00
|
|
|
|
_testAssets = testAssets;
|
2016-10-28 01:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TestAssetInstance CreateInstance([CallerMemberName] string callingMethod = "", string identifier = "")
|
|
|
|
|
{
|
2017-01-06 09:40:26 +00:00
|
|
|
|
var instancePath = GetTestDestinationDirectory(callingMethod, identifier);
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2017-01-06 09:40:26 +00:00
|
|
|
|
var testInstance = new TestAssetInstance(this, instancePath);
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
|
|
return testInstance;
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 09:40:26 +00:00
|
|
|
|
internal IEnumerable<FileInfo> GetSourceFiles()
|
|
|
|
|
{
|
|
|
|
|
ThrowIfTestAssetDoesNotExist();
|
|
|
|
|
|
2017-02-10 18:54:05 +00:00
|
|
|
|
return Root.GetFiles("*.*", SearchOption.AllDirectories)
|
|
|
|
|
.Where(f => !FilesToExclude.Contains(f.Name));
|
2017-01-06 09:40:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private DirectoryInfo GetTestDestinationDirectory(string callingMethod, string identifier)
|
2016-10-28 01:46:43 +00:00
|
|
|
|
{
|
2017-08-30 00:59:34 +00:00
|
|
|
|
return _testAssets.CreateTestDirectory(AssetName, callingMethod, identifier);
|
2016-10-28 01:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-06 09:40:26 +00:00
|
|
|
|
private void ThrowIfTestAssetDoesNotExist()
|
|
|
|
|
{
|
2017-02-10 18:54:05 +00:00
|
|
|
|
if (!Root.Exists)
|
2017-01-06 09:40:26 +00:00
|
|
|
|
{
|
2017-02-10 18:54:05 +00:00
|
|
|
|
throw new DirectoryNotFoundException($"Directory not found at '{Root.FullName}'");
|
2017-01-06 09:40:26 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-28 01:46:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|