2015-12-15 01:39:29 +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 FluentAssertions;
|
|
|
|
|
using FluentAssertions.Execution;
|
|
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tools.Test.Utilities
|
|
|
|
|
{
|
|
|
|
|
public class DirectoryInfoAssertions
|
|
|
|
|
{
|
|
|
|
|
private DirectoryInfo _dirInfo;
|
|
|
|
|
|
|
|
|
|
public DirectoryInfoAssertions(DirectoryInfo dir)
|
|
|
|
|
{
|
|
|
|
|
_dirInfo = dir;
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-03 18:57:25 +00:00
|
|
|
|
public DirectoryInfo DirectoryInfo => _dirInfo;
|
|
|
|
|
|
2015-12-15 01:39:29 +00:00
|
|
|
|
public AndConstraint<DirectoryInfoAssertions> Exist()
|
|
|
|
|
{
|
|
|
|
|
Execute.Assertion.ForCondition(_dirInfo.Exists)
|
|
|
|
|
.FailWith("Expected directory {0} does not exist.", _dirInfo.FullName);
|
|
|
|
|
return new AndConstraint<DirectoryInfoAssertions>(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AndConstraint<DirectoryInfoAssertions> HaveFile(string expectedFile)
|
|
|
|
|
{
|
|
|
|
|
var file = _dirInfo.EnumerateFiles(expectedFile, SearchOption.TopDirectoryOnly).SingleOrDefault();
|
|
|
|
|
Execute.Assertion.ForCondition(file != null)
|
|
|
|
|
.FailWith("Expected File {0} cannot be found in directory {1}.", expectedFile, _dirInfo.FullName);
|
|
|
|
|
return new AndConstraint<DirectoryInfoAssertions>(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AndConstraint<DirectoryInfoAssertions> NotHaveFile(string expectedFile)
|
|
|
|
|
{
|
|
|
|
|
var file = _dirInfo.EnumerateFiles(expectedFile, SearchOption.TopDirectoryOnly).SingleOrDefault();
|
|
|
|
|
Execute.Assertion.ForCondition(file == null)
|
|
|
|
|
.FailWith("File {0} should not be found in directory {1}.", expectedFile, _dirInfo.FullName);
|
|
|
|
|
return new AndConstraint<DirectoryInfoAssertions>(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AndConstraint<DirectoryInfoAssertions> HaveFiles(IEnumerable<string> expectedFiles)
|
2016-03-09 19:36:16 +00:00
|
|
|
|
{
|
2015-12-15 01:39:29 +00:00
|
|
|
|
foreach (var expectedFile in expectedFiles)
|
|
|
|
|
{
|
|
|
|
|
HaveFile(expectedFile);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new AndConstraint<DirectoryInfoAssertions>(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public AndConstraint<DirectoryInfoAssertions> HaveDirectory(string expectedDir)
|
|
|
|
|
{
|
|
|
|
|
var dir = _dirInfo.EnumerateDirectories(expectedDir, SearchOption.TopDirectoryOnly).SingleOrDefault();
|
|
|
|
|
Execute.Assertion.ForCondition(dir != null)
|
|
|
|
|
.FailWith("Expected directory {0} cannot be found inside directory {1}.", expectedDir, _dirInfo.FullName);
|
2016-03-09 19:36:16 +00:00
|
|
|
|
|
2015-12-15 01:39:29 +00:00
|
|
|
|
return new AndConstraint<DirectoryInfoAssertions>(new DirectoryInfoAssertions(dir));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|