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
25 changes: 25 additions & 0 deletions Tests/aweXpect.Testably.Tests/DirectoryInfo.WhoseParent.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,31 @@ async Task Act()
await That(Act).Throws<InvalidOperationException>()
.WithMessage("Cannot assert on the parent of a root directory because it has no parent.");
}

[Fact]
public async Task HasName_AndWhoseParentHasName_WhenParentNameDiffers_ShouldFail()
{
MockFileSystem fileSystem = new();
fileSystem.Initialize().WithSubdirectory("project").Initialized(p => p
.WithSubdirectory("src"));
IDirectoryInfo dirInfo = fileSystem.DirectoryInfo.New("project/src");

async Task Act()
{
await That(dirInfo).HasName("src").And.WhoseParent.HasName("wrong");
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that dirInfo
has name equal to "src" whose parent has name equal to "wrong",
but it was "project" which differs at index 0:
↓ (actual)
"project"
"wrong"
↑ (expected)
""");
}
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions Tests/aweXpect.Testably.Tests/FileInfo.WhoseParent.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,47 @@ async Task Act()

await That(Act).DoesNotThrow();
}

[Fact]
public async Task HasName_AndWhoseParentHasName_WhenParentNameDiffers_ShouldFail()
{
MockFileSystem fileSystem = new();
fileSystem.Initialize().WithSubdirectory("logs").Initialized(d => d
.WithFile("today.log"));
IFileInfo fileInfo = fileSystem.FileInfo.New("logs/today.log");

async Task Act()
{
await That(fileInfo).HasName("today.log").And.WhoseParent.HasName("wrong");
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that fileInfo
has name equal to "today.log" whose parent has name equal to "wrong",
but it was "logs" which differs at index 0:
↓ (actual)
"logs"
"wrong"
↑ (expected)
""");
}

[Fact]
public async Task OnRootFile_ShouldThrow()
{
MockFileSystem fileSystem = new();
IFileInfo fileInfo = fileSystem.FileInfo.New(
fileSystem.Path.GetPathRoot(fileSystem.Directory.GetCurrentDirectory())!);

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

await That(Act).Throws<InvalidOperationException>()
.WithMessage("Cannot assert on the parent directory of the file because it has none.");
}
}
}
}
Expand Down
44 changes: 44 additions & 0 deletions Tests/aweXpect.Testably.Tests/FileVersionInfo.IsDebug.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ Expected that info
but it was not
""");
}

[Fact]
public async Task WhenNegated_AndInfoIsDebug_ShouldFail()
{
MockFileSystem fileSystem = new();
fileSystem.WithFileVersionInfo("*.dll", v => v.SetIsDebug(true));
// ReSharper disable once MethodHasAsyncOverload
fileSystem.File.WriteAllText("Acme.dll", "");
IFileVersionInfo info = fileSystem.FileVersionInfo.GetVersionInfo("Acme.dll");

async Task Act()
{
await That(info).DoesNotComplyWith(it => it.IsDebug());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that info
is not debug,
but it was
""");
}
}
}

Expand Down Expand Up @@ -130,6 +152,28 @@ async Task Act()

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenNegated_AndInfoIsNotDebug_ShouldFail()
{
MockFileSystem fileSystem = new();
fileSystem.WithFileVersionInfo("*.dll", v => v.SetIsDebug(false));
// ReSharper disable once MethodHasAsyncOverload
fileSystem.File.WriteAllText("Acme.dll", "");
IFileVersionInfo info = fileSystem.FileVersionInfo.GetVersionInfo("Acme.dll");

async Task Act()
{
await That(info).DoesNotComplyWith(it => it.IsNotDebug());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that info
is debug,
but it was not
""");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ Expected that info
but it was
""");
}

[Fact]
public async Task WhenNegated_AndInfoIsNotPrivateBuild_ShouldFail()
{
MockFileSystem fileSystem = new();
fileSystem.WithFileVersionInfo("*.dll", v => v.SetIsPrivateBuild(false));
// ReSharper disable once MethodHasAsyncOverload
fileSystem.File.WriteAllText("Acme.dll", "");
IFileVersionInfo info = fileSystem.FileVersionInfo.GetVersionInfo("Acme.dll");

async Task Act()
{
await That(info).DoesNotComplyWith(it => it.IsNotPrivateBuild());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that info
is private build,
but it was not
""");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ Expected that info
but it was
""");
}

[Fact]
public async Task WhenNegated_AndInfoIsNotSpecialBuild_ShouldFail()
{
MockFileSystem fileSystem = new();
fileSystem.WithFileVersionInfo("*.dll", v => v.SetIsSpecialBuild(false));
// ReSharper disable once MethodHasAsyncOverload
fileSystem.File.WriteAllText("Acme.dll", "");
IFileVersionInfo info = fileSystem.FileVersionInfo.GetVersionInfo("Acme.dll");

async Task Act()
{
await That(info).DoesNotComplyWith(it => it.IsNotSpecialBuild());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that info
is special build,
but it was not
""");
}
}
}
}
44 changes: 44 additions & 0 deletions Tests/aweXpect.Testably.Tests/FileVersionInfo.IsPatched.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ async Task Act()

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenNegated_AndInfoIsPatched_ShouldFail()
{
MockFileSystem fileSystem = new();
fileSystem.WithFileVersionInfo("*.dll", v => v.SetIsPatched(true));
// ReSharper disable once MethodHasAsyncOverload
fileSystem.File.WriteAllText("Acme.dll", "");
IFileVersionInfo info = fileSystem.FileVersionInfo.GetVersionInfo("Acme.dll");

async Task Act()
{
await That(info).DoesNotComplyWith(it => it.IsPatched());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that info
is not patched,
but it was
""");
}
}
}

Expand Down Expand Up @@ -130,6 +152,28 @@ Expected that info
but it was
""");
}

[Fact]
public async Task WhenNegated_AndInfoIsNotPatched_ShouldFail()
{
MockFileSystem fileSystem = new();
fileSystem.WithFileVersionInfo("*.dll", v => v.SetIsPatched(false));
// ReSharper disable once MethodHasAsyncOverload
fileSystem.File.WriteAllText("Acme.dll", "");
IFileVersionInfo info = fileSystem.FileVersionInfo.GetVersionInfo("Acme.dll");

async Task Act()
{
await That(info).DoesNotComplyWith(it => it.IsNotPatched());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that info
is patched,
but it was not
""");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ async Task Act()

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenNegated_AndInfoIsPreRelease_ShouldFail()
{
MockFileSystem fileSystem = new();
fileSystem.WithFileVersionInfo("*.dll", v => v.SetIsPreRelease(true));
// ReSharper disable once MethodHasAsyncOverload
fileSystem.File.WriteAllText("Acme.dll", "");
IFileVersionInfo info = fileSystem.FileVersionInfo.GetVersionInfo("Acme.dll");

async Task Act()
{
await That(info).DoesNotComplyWith(it => it.IsPreRelease());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that info
is not pre-release,
but it was
""");
}
}
}

Expand Down Expand Up @@ -130,6 +152,28 @@ Expected that info
but it was
""");
}

[Fact]
public async Task WhenNegated_AndInfoIsNotPreRelease_ShouldFail()
{
MockFileSystem fileSystem = new();
fileSystem.WithFileVersionInfo("*.dll", v => v.SetIsPreRelease(false));
// ReSharper disable once MethodHasAsyncOverload
fileSystem.File.WriteAllText("Acme.dll", "");
IFileVersionInfo info = fileSystem.FileVersionInfo.GetVersionInfo("Acme.dll");

async Task Act()
{
await That(info).DoesNotComplyWith(it => it.IsNotPreRelease());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that info
is pre-release,
but it was not
""");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ async Task Act()

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenNegated_AndInfoIsPrivateBuild_ShouldFail()
{
MockFileSystem fileSystem = new();
fileSystem.WithFileVersionInfo("*.dll", v => v.SetIsPrivateBuild(true));
// ReSharper disable once MethodHasAsyncOverload
fileSystem.File.WriteAllText("Acme.dll", "");
IFileVersionInfo info = fileSystem.FileVersionInfo.GetVersionInfo("Acme.dll");

async Task Act()
{
await That(info).DoesNotComplyWith(it => it.IsPrivateBuild());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that info
is not private build,
but it was
""");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,28 @@ async Task Act()

await That(Act).DoesNotThrow();
}

[Fact]
public async Task WhenNegated_AndInfoIsSpecialBuild_ShouldFail()
{
MockFileSystem fileSystem = new();
fileSystem.WithFileVersionInfo("*.dll", v => v.SetIsSpecialBuild(true));
// ReSharper disable once MethodHasAsyncOverload
fileSystem.File.WriteAllText("Acme.dll", "");
IFileVersionInfo info = fileSystem.FileVersionInfo.GetVersionInfo("Acme.dll");

async Task Act()
{
await That(info).DoesNotComplyWith(it => it.IsSpecialBuild());
}

await That(Act).ThrowsException()
.WithMessage("""
Expected that info
is not special build,
but it was
""");
}
}
}
}
Loading