Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Tests/aweXpect.Testably.Tests/DirectoryInfo.IsEmpty.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ but it was not
""");
}

[Fact]
public async Task WhenDirectoryDoesNotExist_ShouldFail()
{
MockFileSystem fileSystem = new();
IDirectoryInfo dirInfo = fileSystem.DirectoryInfo.New("missing");

async Task Act()
{
await That(dirInfo).IsEmpty();
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that dirInfo
is empty,
but it did not exist
""");
}

[Fact]
public async Task WhenDirectoryIsEmpty_ShouldSucceed()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System.IO.Abstractions;
using System.Text;
using Testably.Abstractions.Testing;

namespace aweXpect.Testably.Tests;

public sealed partial class FileInfo
{
public sealed partial class HasContent
{
public sealed class BinaryNegated
{
public sealed class Tests
{
[Fact]
public async Task WhenContentIsDifferent_ShouldSucceed()
{
byte[] content = Encoding.UTF8.GetBytes("baz");
byte[] expected = Encoding.UTF8.GetBytes("bar");
string path = "foo.txt";
MockFileSystem fileSystem = new();
// ReSharper disable once MethodHasAsyncOverload
fileSystem.File.WriteAllBytes(path, content);
IFileInfo fileInfo = fileSystem.FileInfo.New("foo.txt");

async Task Act()
{
await That(fileInfo).DoesNotComplyWith(it => it.HasContent(expected));
}

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenContentMatches_ShouldFail()
{
byte[] content = Encoding.UTF8.GetBytes("baz");
string path = "foo.txt";
MockFileSystem fileSystem = new();
// ReSharper disable once MethodHasAsyncOverload
fileSystem.File.WriteAllBytes(path, content);
IFileInfo fileInfo = fileSystem.FileInfo.New("foo.txt");

async Task Act()
{
await That(fileInfo).DoesNotComplyWith(it => it.HasContent(content));
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that fileInfo
has content different from content,
but it did match
""");
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
using System.IO;
using System.Text;
using Testably.Abstractions.Testing;

namespace aweXpect.Testably.Tests;

public sealed partial class FileInfo
{
public sealed partial class HasContent
{
public sealed class BinaryPlural
{
public sealed class Tests
{
[Fact]
public async Task WhenContentDiffers_ShouldFail()
{
byte[] expected = Encoding.UTF8.GetBytes("bar");
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo").Initialized(d => d
.WithFile("bar.txt").Which(f => f.HasStringContent("baz")));

async Task Act()
{
await That(sut).HasDirectory("foo")
.WithFiles(files => files.All().ComplyWith(file => file.HasContent(expected)));
}

await That(Act).ThrowsException()
.WithMessage($"""
Expected that sut
has directory 'foo' whose files have content equal to expected for all items,
but not all were

Not matching items:
[
foo{Path.DirectorySeparatorChar}bar.txt,
(… and maybe others)
]

Collection:
[
foo{Path.DirectorySeparatorChar}bar.txt
]
""").IgnoringNewlineStyle();
}

[Fact]
public async Task WhenContentMatches_ShouldSucceed()
{
byte[] content = Encoding.UTF8.GetBytes("baz");
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo").Initialized(d => d
.WithFile("bar.txt").Which(f => f.HasStringContent("baz")));

async Task Act()
{
await That(sut).HasDirectory("foo")
.WithFiles(files => files.All().ComplyWith(file => file.HasContent(content)));
}

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenNegated_WhenContentDiffers_ShouldSucceed()
{
byte[] expected = Encoding.UTF8.GetBytes("bar");
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo").Initialized(d => d
.WithFile("bar.txt").Which(f => f.HasStringContent("baz")));

async Task Act()
{
await That(sut).HasDirectory("foo")
.WithFiles(files => files.All().ComplyWith(file
=> file.DoesNotComplyWith(it => it.HasContent(expected))));
}

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenNegated_WhenContentMatches_ShouldFail()
{
byte[] content = Encoding.UTF8.GetBytes("baz");
MockFileSystem sut = new();
sut.Initialize().WithSubdirectory("foo").Initialized(d => d
.WithFile("bar.txt").Which(f => f.HasStringContent("baz")));

async Task Act()
{
await That(sut).HasDirectory("foo")
.WithFiles(files => files.All().ComplyWith(file
=> file.DoesNotComplyWith(it => it.HasContent(content))));
}

await That(Act).ThrowsException()
.WithMessage($"""
Expected that sut
has directory 'foo' whose files have content different from content for all items,
but not all were

Not matching items:
[
foo{Path.DirectorySeparatorChar}bar.txt,
(… and maybe others)
]

Collection:
[
foo{Path.DirectorySeparatorChar}bar.txt
]
""").IgnoringNewlineStyle();
}
}
}
}
}
27 changes: 27 additions & 0 deletions Tests/aweXpect.Testably.Tests/FileInfo.HasContent.SameAs.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,33 @@ Expected that fileInfo
""");
}

[Fact]
public async Task WhenExpectedFileDoesNotExist_ShouldFail()
{
MockFileSystem fileSystem = new();
string path = "foo.txt";
string expectedPath = "bar.txt";
string fullExpectedPath = fileSystem.Path.GetFullPath(expectedPath);
// ReSharper disable once MethodHasAsyncOverload
fileSystem.File.WriteAllText(path, "baz");
IFileInfo fileInfo = fileSystem.FileInfo.New("foo.txt");

async Task Act()
{
await That(fileInfo).HasContent().SameAs(expectedPath);
}

await That(Act).ThrowsException()
.WithMessage($"""
Expected that fileInfo
has the same content as file '{fullExpectedPath}',
but it did not contain any file at '{fullExpectedPath}'

File content:
baz
""");
}

[Fact]
public async Task WhenContentMatches_ShouldSucceed()
{
Expand Down
20 changes: 20 additions & 0 deletions Tests/aweXpect.Testably.Tests/FileInfo.HasContent.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,26 @@ async Task Act()

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenFileDoesNotExist_ShouldFail()
{
byte[] expected = Encoding.UTF8.GetBytes("bar");
MockFileSystem fileSystem = new();
IFileInfo fileInfo = fileSystem.FileInfo.New("foo.txt");

async Task Act()
{
await That(fileInfo).HasContent(expected);
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that fileInfo
has content equal to expected,
but it did not exist
""");
}
}

public sealed class AsWildcardTests
Expand Down
65 changes: 65 additions & 0 deletions Tests/aweXpect.Testably.Tests/FileInfo.HasLength.Negated.Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using System.IO.Abstractions;
using System.Text;
using Testably.Abstractions.Testing;

namespace aweXpect.Testably.Tests;

public sealed partial class FileInfo
{
public sealed class HasLengthNegated
{
public sealed class Tests
{
[Fact]
public async Task WhenLengthDiffers_ShouldSucceed()
{
MockFileSystem fileSystem = new();
// ReSharper disable once MethodHasAsyncOverload
fileSystem.File.WriteAllBytes("foo.txt", Encoding.UTF8.GetBytes("baz"));
IFileInfo fileInfo = fileSystem.FileInfo.New("foo.txt");

async Task Act()
{
await That(fileInfo).DoesNotComplyWith(it => it.HasLength(5));
}

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenLengthMatches_ShouldFail()
{
MockFileSystem fileSystem = new();
// ReSharper disable once MethodHasAsyncOverload
fileSystem.File.WriteAllBytes("foo.txt", Encoding.UTF8.GetBytes("baz"));
IFileInfo fileInfo = fileSystem.FileInfo.New("foo.txt");

async Task Act()
{
await That(fileInfo).DoesNotComplyWith(it => it.HasLength(3));
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that fileInfo
does not have length 3,
but it did
""");
}

[Fact]
public async Task WhenFileDoesNotExist_ShouldSucceed()
{
MockFileSystem fileSystem = new();
IFileInfo fileInfo = fileSystem.FileInfo.New("missing.txt");

async Task Act()
{
await That(fileInfo).DoesNotComplyWith(it => it.HasLength(0));
}

await That(Act).DoesNotThrow();
}
}
}
}
19 changes: 19 additions & 0 deletions Tests/aweXpect.Testably.Tests/FileInfo.IsReadOnly.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ but it was not
""");
}

[Fact]
public async Task WhenFileDoesNotExist_ShouldFail()
{
MockFileSystem fileSystem = new();
IFileInfo fileInfo = fileSystem.FileInfo.New("foo.txt");

async Task Act()
{
await That(fileInfo).IsReadOnly();
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that fileInfo
is read-only,
but it did not exist
""");
}

[Fact]
public async Task WhenFileIsReadOnly_ShouldSucceed()
{
Expand Down
Loading
Loading