Copy FileSystemGlobbing and HashCodeCombiner sources

This commit is contained in:
Pranav K 2016-04-29 12:11:27 -07:00
parent f8631fa4b7
commit 734c9fc43b
75 changed files with 3999 additions and 43 deletions

View file

@ -0,0 +1,61 @@
// 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.IO;
namespace Microsoft.DotNet.ProjectModel.FileSystemGlobbing.Tests.TestUtility
{
public class DisposableFileSystem : IDisposable
{
public DisposableFileSystem()
{
RootPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Directory.CreateDirectory(RootPath);
DirectoryInfo = new DirectoryInfo(RootPath);
}
public string RootPath { get; }
public DirectoryInfo DirectoryInfo { get; }
public DisposableFileSystem CreateFolder(string path)
{
Directory.CreateDirectory(Path.Combine(RootPath, path));
return this;
}
public DisposableFileSystem CreateFile(string path)
{
File.WriteAllText(Path.Combine(RootPath, path), "temp");
return this;
}
public DisposableFileSystem CreateFiles(params string[] fileRelativePaths)
{
foreach (var path in fileRelativePaths)
{
var fullPath = Path.Combine(RootPath, path);
Directory.CreateDirectory(Path.GetDirectoryName(fullPath));
File.WriteAllText(
fullPath,
string.Format("Automatically generated for testing on {0:yyyy}/{0:MM}/{0:dd} {0:hh}:{0:mm}:{0:ss}", DateTime.UtcNow));
}
return this;
}
public void Dispose()
{
try
{
Directory.Delete(RootPath, true);
}
catch
{
// Don't throw if this fails.
}
}
}
}