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
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using Testably.Abstractions.Testing;

namespace aweXpect.Testably.Tests;

public sealed partial class Statistics
{
public sealed partial class Recorded
{
public sealed class DirectoryNegated
{
[Fact]
public async Task WhenNegatingNeverAndCalled_ShouldSucceed()
{
MockFileSystem fileSystem = new();
fileSystem.Directory.CreateDirectory("foo");

async Task Act()
{
await That(fileSystem.Statistics).DoesNotComplyWith(it
=> it.Recorded().Directory.CreateDirectory().Never());
}

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenNegatingNeverAndNotCalled_ShouldFailWithAtLeastOneWording()
{
MockFileSystem fileSystem = new();

async Task Act()
{
await That(fileSystem.Statistics).DoesNotComplyWith(it
=> it.Recorded().Directory.CreateDirectory().Never());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that fileSystem.Statistics
recorded at least one call to Directory.CreateDirectory,
but it was recorded 0 times
""");
}

[Fact]
public async Task WhenNegatingNeverWithMatcherAndNotCalled_ShouldIncludeMatcher()
{
MockFileSystem fileSystem = new();

async Task Act()
{
await That(fileSystem.Statistics).DoesNotComplyWith(it
=> it.Recorded().Directory.CreateDirectory(p => p == "foo").Never());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that fileSystem.Statistics
recorded at least one call to Directory.CreateDirectory with path matching p => p == "foo",
but it was recorded 0 times
""");
}

[Fact]
public async Task WhenNegatingExactlyAndMatching_ShouldFailWithDidNotRecordWording()
{
MockFileSystem fileSystem = new();
fileSystem.Directory.CreateDirectory("foo");

async Task Act()
{
await That(fileSystem.Statistics).DoesNotComplyWith(it
=> it.Recorded().Directory.CreateDirectory().Once());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that fileSystem.Statistics
did not record a call to Directory.CreateDirectory exactly once,
but it was recorded 1 time
""");
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Testably.Abstractions.Testing;

namespace aweXpect.Testably.Tests;

public sealed partial class Statistics
{
public sealed partial class Recorded
{
public sealed class DirectoryTwoMatchers
{
#if NET8_0_OR_GREATER
[Fact]
public async Task WithTwoMatchers_NoMatch_ShouldJoinMatchersWithComma()
{
MockFileSystem fileSystem = new();

async Task Act()
{
await That(fileSystem.Statistics).Recorded()
.Directory.CreateSymbolicLink(p => p == "foo", t => t == "bar").Once();
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that fileSystem.Statistics
recorded a call to Directory.CreateSymbolicLink with path matching p => p == "foo", pathToTarget matching t => t == "bar" exactly once,
but it was recorded 0 times
""");
}

[Fact]
public async Task WithNeverAndMatcher_Matching_ShouldFailIncludingMatcher()
{
MockFileSystem fileSystem = new();
fileSystem.Directory.CreateDirectory("target");
fileSystem.Directory.CreateSymbolicLink("link", "target");

async Task Act()
{
await That(fileSystem.Statistics).Recorded()
.Directory.CreateSymbolicLink(p => p == "link").Never();
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that fileSystem.Statistics
recorded no call to Directory.CreateSymbolicLink with path matching p => p == "link",
but it was recorded 1 time
""");
}
#endif
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
using System.IO.Abstractions;
using Testably.Abstractions.Testing;

namespace aweXpect.Testably.Tests;

public sealed partial class Statistics
{
public sealed partial class Recorded
{
public sealed class FileInfoPropertyAccess
{
[Fact]
public async Task WhenNeverAccessed_NeverGet_ShouldSucceed()
{
MockFileSystem fileSystem = new();
fileSystem.File.WriteAllText("foo.txt", "");

async Task Act()
{
await That(fileSystem.Statistics).Recorded()
.FileInfo["foo.txt"].IsReadOnly.Get().Never();
}

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenAccessed_NeverGet_ShouldFailWithNoGetWording()
{
MockFileSystem fileSystem = new();
fileSystem.File.WriteAllText("foo.txt", "");
IFileInfo fileInfo = fileSystem.FileInfo.New("foo.txt");
_ = fileInfo.IsReadOnly;

async Task Act()
{
await That(fileSystem.Statistics).Recorded()
.FileInfo["foo.txt"].IsReadOnly.Get().Never();
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that fileSystem.Statistics
recorded no get of FileInfo["foo.txt"].IsReadOnly,
but it was recorded 1 time
""");
}

[Fact]
public async Task WhenSet_NeverSet_ShouldFailWithNoSetWording()
{
MockFileSystem fileSystem = new();
fileSystem.File.WriteAllText("foo.txt", "");
IFileInfo fileInfo = fileSystem.FileInfo.New("foo.txt");
fileInfo.IsReadOnly = false;

async Task Act()
{
await That(fileSystem.Statistics).Recorded()
.FileInfo["foo.txt"].IsReadOnly.Set().Never();
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that fileSystem.Statistics
recorded no set of FileInfo["foo.txt"].IsReadOnly,
but it was recorded 1 time
""");
}

[Fact]
public async Task WhenNegatingNeverGetAndAccessed_ShouldSucceed()
{
MockFileSystem fileSystem = new();
fileSystem.File.WriteAllText("foo.txt", "");
IFileInfo fileInfo = fileSystem.FileInfo.New("foo.txt");
_ = fileInfo.IsReadOnly;

async Task Act()
{
await That(fileSystem.Statistics).DoesNotComplyWith(it
=> it.Recorded().FileInfo["foo.txt"].IsReadOnly.Get().Never());
}

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenNegatingNeverGetAndNotAccessed_ShouldFailWithAtLeastOneGetWording()
{
MockFileSystem fileSystem = new();
fileSystem.File.WriteAllText("foo.txt", "");

async Task Act()
{
await That(fileSystem.Statistics).DoesNotComplyWith(it
=> it.Recorded().FileInfo["foo.txt"].IsReadOnly.Get().Never());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that fileSystem.Statistics
recorded at least one get of FileInfo["foo.txt"].IsReadOnly,
but it was recorded 0 times
""");
}

[Fact]
public async Task WhenNegatingNeverSetAndNotAccessed_ShouldFailWithAtLeastOneSetWording()
{
MockFileSystem fileSystem = new();
fileSystem.File.WriteAllText("foo.txt", "");

async Task Act()
{
await That(fileSystem.Statistics).DoesNotComplyWith(it
=> it.Recorded().FileInfo["foo.txt"].IsReadOnly.Set().Never());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that fileSystem.Statistics
recorded at least one set of FileInfo["foo.txt"].IsReadOnly,
but it was recorded 0 times
""");
}

[Fact]
public async Task WhenNegatingExactlyGetAndAccessed_ShouldFailWithDidNotRecordGetWording()
{
MockFileSystem fileSystem = new();
fileSystem.File.WriteAllText("foo.txt", "");
IFileInfo fileInfo = fileSystem.FileInfo.New("foo.txt");
_ = fileInfo.IsReadOnly;

async Task Act()
{
await That(fileSystem.Statistics).DoesNotComplyWith(it
=> it.Recorded().FileInfo["foo.txt"].IsReadOnly.Get().Once());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that fileSystem.Statistics
did not record a get of FileInfo["foo.txt"].IsReadOnly exactly once,
but it was recorded 1 time
""");
}
}
}
}
Loading
Loading