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
Expand Up @@ -52,6 +52,8 @@ async Task Act()

await That(Act).Throws<ArgumentException>()
.WithParamName("unexpected");
await That(Act).Throws<ArgumentException>()
.WithMessage("The unexpected change type must include at least one flag.*").AsWildcard();
}

[Fact]
Expand Down Expand Up @@ -97,6 +99,45 @@ async Task Act()

await That(Act).Throws<ArgumentException>()
.WithParamName("expected");
await That(Act).Throws<ArgumentException>()
.WithMessage("The expected change type must include at least one flag.*").AsWildcard();
}

[Fact]
public async Task WhenSubjectIsNull_ShouldFail()
{
ChangeDescription? change = null;

async Task Act()
{
await That(change!).HasChangeType(WatcherChangeTypes.Created);
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that change
has change type Created,
but it was <null>
""");
}

[Fact]
public async Task WhenExpectedPartiallyOverlapsActual_ShouldFail()
{
ChangeDescription change = Capture(fs => fs.File.WriteAllText("foo.txt", ""));

async Task Act()
{
await That(change)
.HasChangeType(WatcherChangeTypes.Created | WatcherChangeTypes.Deleted);
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that change
has change type Created, Deleted,
but it was Created
""");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ async Task Act()

await That(Act).Throws<ArgumentException>()
.WithParamName("unexpected");
await That(Act).Throws<ArgumentException>()
.WithMessage("The unexpected file system type must include at least one flag.*").AsWildcard();
}

[Fact]
Expand All @@ -66,6 +68,8 @@ async Task Act()

await That(Act).Throws<ArgumentException>()
.WithParamName("expected");
await That(Act).Throws<ArgumentException>()
.WithMessage("The expected file system type must include at least one flag.*").AsWildcard();
}

[Fact]
Expand Down Expand Up @@ -98,6 +102,43 @@ async Task Act()

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenSubjectIsNull_ShouldFail()
{
ChangeDescription? change = null;

async Task Act()
{
await That(change!).HasFileSystemType(FileSystemTypes.File);
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that change
has file system type File,
but it was <null>
""");
}

[Fact]
public async Task WhenExpectedPartiallyOverlapsActual_ShouldFail()
{
ChangeDescription change = Capture(fs => fs.File.WriteAllText("foo.txt", ""));

async Task Act()
{
await That(change)
.HasFileSystemType(FileSystemTypes.File | FileSystemTypes.Directory);
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that change
has file system type DirectoryOrFile,
but it was File
""");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ async Task Act()
}

await That(Act).ThrowsException()
.WithMessage("*has name equal to \"bar.txt\"*").AsWildcard();
.WithMessage("""
Expected that change
has name equal to "bar.txt",
but it was "foo.txt" which differs at index 0:
↓ (actual)
"foo.txt"
"bar.txt"
↑ (expected)
""");
}

[Fact]
Expand All @@ -34,6 +42,24 @@ async Task Act()

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenSubjectIsNull_ShouldFail()
{
ChangeDescription? change = null;

async Task Act()
{
await That(change!).HasName("foo.txt");
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that change
has name equal to "foo.txt",
but it was <null>
""");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ async Task Act()
}

await That(Act).ThrowsException()
.WithMessage("*does not have notify filters*").AsWildcard();
.WithMessage($"""
Expected that change
does not have notify filters {present},
but it did
""");
}

[Fact]
Expand All @@ -49,6 +53,8 @@ async Task Act()

await That(Act).Throws<ArgumentException>()
.WithParamName("unexpected");
await That(Act).Throws<ArgumentException>()
.WithMessage("The unexpected notify filters must include at least one flag.*").AsWildcard();
}

[Fact]
Expand Down Expand Up @@ -77,20 +83,61 @@ async Task Act()

await That(Act).Throws<ArgumentException>()
.WithParamName("expected");
await That(Act).Throws<ArgumentException>()
.WithMessage("The expected notify filters must include at least one flag.*").AsWildcard();
}

[Fact]
public async Task WhenMissingExpectedFlag_ShouldFail()
{
ChangeDescription change = Capture(fs => fs.File.WriteAllText("foo.txt", ""));

NotifyFilters actual = change.NotifyFilters;

async Task Act()
{
await That(change).HasNotifyFilters(NotifyFilters.Security);
}

await That(Act).ThrowsException()
.WithMessage("*has notify filters Security*").AsWildcard();
.WithMessage($"""
Expected that change
has notify filters Security,
but it was {actual}
""");
}

[Fact]
public async Task WhenSubjectIsNull_ShouldFail()
{
ChangeDescription? change = null;

async Task Act()
{
await That(change!).HasNotifyFilters(NotifyFilters.FileName);
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that change
has notify filters FileName,
but it was <null>
""");
}

[Fact]
public async Task WhenExpectedPartiallyOverlapsActual_ShouldFail()
{
ChangeDescription change = Capture(fs => fs.File.WriteAllText("foo.txt", ""));
NotifyFilters present = change.NotifyFilters;

async Task Act()
{
await That(change).HasNotifyFilters(present | NotifyFilters.Security);
}

await That(Act).ThrowsException()
.WithMessage("*has notify filters*Security*but it was*").AsWildcard();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,24 @@ but it was not triggered
""");
}

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

async Task Act()
{
await That(sut).TriggeredNotification()
.Which(c => c.HasName("foo.txt"))
.Which(c => c.HasChangeType(WatcherChangeTypes.Deleted))
.Within(TimeSpan.FromMilliseconds(100));
}

await That(Act).ThrowsException()
.WithMessage("*which has name equal to \"foo.txt\" and has change type Deleted*").AsWildcard();
}

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