Dotnet publish tests
This commit is contained in:
parent
cd357cb273
commit
07eb7ef28f
43 changed files with 1826 additions and 129 deletions
|
@ -0,0 +1,72 @@
|
|||
// 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.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
{
|
||||
public class CommandResultAssertions
|
||||
{
|
||||
private CommandResult _commandResult;
|
||||
|
||||
public CommandResultAssertions(CommandResult commandResult)
|
||||
{
|
||||
_commandResult = commandResult;
|
||||
}
|
||||
|
||||
public AndConstraint<CommandResultAssertions> ExitWith(int expectedExitCode)
|
||||
{
|
||||
Execute.Assertion.ForCondition(_commandResult.ExitCode == expectedExitCode)
|
||||
.FailWith("Expected command to exit with {0} but it exited with {1}.", expectedExitCode, _commandResult.ExitCode);
|
||||
return new AndConstraint<CommandResultAssertions>(this);
|
||||
}
|
||||
|
||||
public AndConstraint<CommandResultAssertions> Pass()
|
||||
{
|
||||
Execute.Assertion.ForCondition(_commandResult.ExitCode == 0)
|
||||
.FailWith("Expected command to pass but it exited with {0}.", _commandResult.ExitCode);
|
||||
return new AndConstraint<CommandResultAssertions>(this);
|
||||
}
|
||||
|
||||
public AndConstraint<CommandResultAssertions> Fail()
|
||||
{
|
||||
Execute.Assertion.ForCondition(_commandResult.ExitCode != 0)
|
||||
.FailWith("Expected command to fail but it exited with {0}.", _commandResult.ExitCode);
|
||||
return new AndConstraint<CommandResultAssertions>(this);
|
||||
}
|
||||
|
||||
public AndConstraint<CommandResultAssertions> HaveStdOut()
|
||||
{
|
||||
Execute.Assertion.ForCondition(!string.IsNullOrEmpty(_commandResult.StdOut))
|
||||
.FailWith("Command did not output anything to stdout");
|
||||
return new AndConstraint<CommandResultAssertions>(this);
|
||||
}
|
||||
|
||||
public AndConstraint<CommandResultAssertions> HaveStdErr()
|
||||
{
|
||||
Execute.Assertion.ForCondition(!string.IsNullOrEmpty(_commandResult.StdErr))
|
||||
.FailWith("Command did not output anything to stderr");
|
||||
return new AndConstraint<CommandResultAssertions>(this);
|
||||
}
|
||||
|
||||
public AndConstraint<CommandResultAssertions> NotHaveStdOut()
|
||||
{
|
||||
Execute.Assertion.ForCondition(string.IsNullOrEmpty(_commandResult.StdOut))
|
||||
.FailWith("Expected command to not output to stdout but found - {0}{1}", Environment.NewLine, _commandResult.StdOut);
|
||||
return new AndConstraint<CommandResultAssertions>(this);
|
||||
}
|
||||
|
||||
public AndConstraint<CommandResultAssertions> NotHaveStdErr()
|
||||
{
|
||||
Execute.Assertion.ForCondition(string.IsNullOrEmpty(_commandResult.StdErr))
|
||||
.FailWith("Expected command to not output to stderr but found - {0}{1}", Environment.NewLine, _commandResult.StdErr);
|
||||
return new AndConstraint<CommandResultAssertions>(this);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
// 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 Microsoft.DotNet.Cli.Utils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
{
|
||||
public static class CommandResultExtensions
|
||||
{
|
||||
public static CommandResultAssertions Should(this CommandResult commandResult)
|
||||
{
|
||||
return new CommandResultAssertions(commandResult);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
// 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;
|
||||
}
|
||||
|
||||
public AndConstraint<DirectoryInfoAssertions> Exist()
|
||||
{
|
||||
_dirInfo.Exists.Should().BeTrue();
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
return new AndConstraint<DirectoryInfoAssertions>(new DirectoryInfoAssertions(dir));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
// 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.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
{
|
||||
public static class DirectoryInfoExtensions
|
||||
{
|
||||
public static DirectoryInfoAssertions Should(this DirectoryInfo dir)
|
||||
{
|
||||
return new DirectoryInfoAssertions(dir);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue