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
1 change: 1 addition & 0 deletions tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<ItemGroup>
<PackageReference Include="TUnit" Version="1.17.*" />
<PackageReference Include="AwesomeAssertions" Version="9.4.*" />
</ItemGroup>

</Project>
49 changes: 25 additions & 24 deletions tests/SLNX-validator.Core.Tests/SlnxValidatorTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using AwesomeAssertions;
using JulianVerdurmen.SlnxValidator.Core.Validation;
using JulianVerdurmen.SlnxValidator.Core.ValidationResults;

Expand All @@ -20,7 +21,7 @@ public async Task ValidateAsync_EmptySolution_IsValid()

var result = await ValidatorWithFiles().ValidateAsync(slnx, RepoRoot);

await Assert.That(result.IsValid).IsTrue();
result.IsValid.Should().BeTrue();
}

[Test]
Expand All @@ -32,9 +33,9 @@ this is not xml at all

var result = await ValidatorWithFiles().ValidateAsync(slnx, RepoRoot);

await Assert.That(result.IsValid).IsFalse();
await Assert.That(result.Errors[0].Code).IsEqualTo(ValidationErrorCode.InvalidXml);
await Assert.That(result.Errors[0].Message).Contains("Invalid XML");
result.IsValid.Should().BeFalse();
result.Errors[0].Code.Should().Be(ValidationErrorCode.InvalidXml);
result.Errors[0].Message.Should().Contain("Invalid XML");
}

[Test]
Expand All @@ -48,8 +49,8 @@ public async Task ValidateAsync_XsdViolation_ReturnsXsdViolationError()

var result = await ValidatorWithFiles().ValidateAsync(slnx, RepoRoot);

await Assert.That(result.IsValid).IsFalse();
await Assert.That(result.Errors[0].Code).IsEqualTo(ValidationErrorCode.XsdViolation);
result.IsValid.Should().BeFalse();
result.Errors[0].Code.Should().Be(ValidationErrorCode.XsdViolation);
}

[Test]
Expand All @@ -64,8 +65,8 @@ public async Task ValidateAsync_ProjectWithoutPathAttribute_ReturnsXsdViolationE
// Path is use="required" in the XSD, so this is caught as an XSD violation
var result = await ValidatorWithFiles().ValidateAsync(slnx, RepoRoot);

await Assert.That(result.IsValid).IsFalse();
await Assert.That(result.Errors[0].Code).IsEqualTo(ValidationErrorCode.XsdViolation);
result.IsValid.Should().BeFalse();
result.Errors[0].Code.Should().Be(ValidationErrorCode.XsdViolation);
}

[Test]
Expand All @@ -81,9 +82,9 @@ public async Task ValidateAsync_MissingFileInFolder_ReturnsFileNotFoundError()

var result = await ValidatorWithFiles().ValidateAsync(slnx, RepoRoot);

await Assert.That(result.IsValid).IsFalse();
await Assert.That(result.Errors[0].Code).IsEqualTo(ValidationErrorCode.ReferencedFileNotFound);
await Assert.That(result.Errors[0].Message).Contains("README.md");
result.IsValid.Should().BeFalse();
result.Errors[0].Code.Should().Be(ValidationErrorCode.ReferencedFileNotFound);
result.Errors[0].Message.Should().Contain("README.md");
}

[Test]
Expand All @@ -100,7 +101,7 @@ public async Task ValidateAsync_ExistingFileInFolder_IsValid()
var result = await ValidatorWithFiles(Path.Combine(RepoRoot, "README.md"))
.ValidateAsync(slnx, RepoRoot);

await Assert.That(result.IsValid).IsTrue();
result.IsValid.Should().BeTrue();
}

[Test]
Expand All @@ -117,10 +118,10 @@ public async Task ValidateAsync_MultipleErrors_AllReported()

var result = await ValidatorWithFiles().ValidateAsync(slnx, RepoRoot);

await Assert.That(result.Errors.Count).IsEqualTo(2);
result.Errors.Should().HaveCount(2);
foreach (var error in result.Errors)
{
await Assert.That(error.Code).IsEqualTo(ValidationErrorCode.ReferencedFileNotFound);
error.Code.Should().Be(ValidationErrorCode.ReferencedFileNotFound);
}
}

Expand All @@ -137,20 +138,20 @@ public async Task ValidateAsync_WildcardInFilePath_ReturnsInvalidWildcardUsageEr

var result = await ValidatorWithFiles().ValidateAsync(slnx, RepoRoot);

await Assert.That(result.IsValid).IsFalse();
await Assert.That(result.Errors[0].Code).IsEqualTo(ValidationErrorCode.InvalidWildcardUsage);
await Assert.That(result.Errors[0].Message).Contains("docs/*.md");
result.IsValid.Should().BeFalse();
result.Errors[0].Code.Should().Be(ValidationErrorCode.InvalidWildcardUsage);
result.Errors[0].Message.Should().Contain("docs/*.md");
}

[Test]
public async Task ValidationErrorCode_ToCode_ReturnsPrefixedCode()
{
await Assert.That(ValidationErrorCode.FileNotFound.ToCode()).IsEqualTo("SLNX0001");
await Assert.That(ValidationErrorCode.InvalidExtension.ToCode()).IsEqualTo("SLNX0002");
await Assert.That(ValidationErrorCode.NotATextFile.ToCode()).IsEqualTo("SLNX0003");
await Assert.That(ValidationErrorCode.InvalidXml.ToCode()).IsEqualTo("SLNX0010");
await Assert.That(ValidationErrorCode.ReferencedFileNotFound.ToCode()).IsEqualTo("SLNX0011");
await Assert.That(ValidationErrorCode.InvalidWildcardUsage.ToCode()).IsEqualTo("SLNX0012");
await Assert.That(ValidationErrorCode.XsdViolation.ToCode()).IsEqualTo("SLNX0013");
ValidationErrorCode.FileNotFound.ToCode().Should().Be("SLNX0001");
ValidationErrorCode.InvalidExtension.ToCode().Should().Be("SLNX0002");
ValidationErrorCode.NotATextFile.ToCode().Should().Be("SLNX0003");
ValidationErrorCode.InvalidXml.ToCode().Should().Be("SLNX0010");
ValidationErrorCode.ReferencedFileNotFound.ToCode().Should().Be("SLNX0011");
ValidationErrorCode.InvalidWildcardUsage.ToCode().Should().Be("SLNX0012");
ValidationErrorCode.XsdViolation.ToCode().Should().Be("SLNX0013");
}
}
5 changes: 3 additions & 2 deletions tests/SLNX-validator.Core.Tests/SolutionIntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using AwesomeAssertions;
using JulianVerdurmen.SlnxValidator.Core.FileSystem;
using JulianVerdurmen.SlnxValidator.Core.Validation;
using CoreSlnxValidator = JulianVerdurmen.SlnxValidator.Core.Validation.SlnxValidator;
Expand All @@ -15,14 +16,14 @@ public async Task OwnSlnxFile_HasNoValidationErrors()
directory = directory.Parent;
}

await Assert.That(directory).IsNotNull();
directory.Should().NotBeNull();

var slnxFile = directory!.EnumerateFiles("*.slnx").First();
var content = await File.ReadAllTextAsync(slnxFile.FullName);

var validator = new CoreSlnxValidator(new RealFileSystem(), new XsdValidator());
var result = await validator.ValidateAsync(content, slnxFile.DirectoryName!);

await Assert.That(result.Errors).IsEmpty();
result.Errors.Should().BeEmpty();
}
}
16 changes: 9 additions & 7 deletions tests/SLNX-validator.Tests/ProgramIntegrationTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using AwesomeAssertions;

namespace JulianVerdurmen.SlnxValidator.Tests;

public class ProgramIntegrationTests
Expand All @@ -7,15 +9,15 @@ public async Task Invoke_WithNoArguments_ReturnsNonZeroExitCode()
{
var exitCode = await Program.Main([]);

await Assert.That(exitCode).IsNotEqualTo(0);
exitCode.Should().NotBe(0);
}

[Test]
public async Task Invoke_WithNonExistentFile_ReturnsNonZeroExitCode()
{
var exitCode = await Program.Main(["C:\\does\\not\\exist.slnx"]);

await Assert.That(exitCode).IsNotEqualTo(0);
exitCode.Should().NotBe(0);
}

[Test]
Expand All @@ -38,7 +40,7 @@ await File.WriteAllTextAsync(slnxPath, """
{
var exitCode = await Program.Main([tempDir]);

await Assert.That(exitCode).IsEqualTo(0);
exitCode.Should().Be(0);
}
finally
{
Expand Down Expand Up @@ -66,7 +68,7 @@ await File.WriteAllTextAsync(slnxPath, """
{
var exitCode = await Program.Main([$"{tempDir}/*.slnx"]);

await Assert.That(exitCode).IsEqualTo(0);
exitCode.Should().Be(0);
}
finally
{
Expand Down Expand Up @@ -94,7 +96,7 @@ await File.WriteAllTextAsync(slnxPath, """
{
var exitCode = await Program.Main([slnxPath]);

await Assert.That(exitCode).IsEqualTo(0);
exitCode.Should().Be(0);
}
finally
{
Expand All @@ -112,7 +114,7 @@ public async Task Invoke_WithNonSlnxExtension_ReturnsNonZeroExitCode()
{
var exitCode = await Program.Main([path]);

await Assert.That(exitCode).IsNotEqualTo(0);
exitCode.Should().NotBe(0);
}
finally
{
Expand All @@ -130,7 +132,7 @@ public async Task Invoke_WithBinaryFile_ReturnsNonZeroExitCode()
{
var exitCode = await Program.Main([path]);

await Assert.That(exitCode).IsNotEqualTo(0);
exitCode.Should().NotBe(0);
}
finally
{
Expand Down