Skip to content

Commit

Permalink
test: Check if inner exceptions have the expected messages
Browse files Browse the repository at this point in the history
  • Loading branch information
MrDave1999 committed Dec 11, 2023
1 parent 657815b commit b6636b4
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions tests/Loader/YeSqlLoaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public void LoadFromFiles_WhenErrorsAreFound_ShouldThrowAggregateException()
"file_not_found.sql",
"file_without_extension"
};
var expectedLoaderErrors = new[]
var loaderErrors = new[]
{
string.Format(ExceptionMessages.FileNotFound, "file_not_found.sql"),
string.Format(ExceptionMessages.FileHasNotSqlExtension, "file_without_extension")
};
var expectedParserErrors = new[]
var parserErrors = new[]
{
$"errors_1.sql:(line 2, col 1): error: {string.Format(ExceptionMessages.LineIsNotAssociatedWithAnyTag, "SELECT * FROM users;")}",
$"errors_1.sql:(line 9, col 9): error: {ExceptionMessages.TagIsEmptyOrWhitespace}",
Expand All @@ -28,17 +28,23 @@ public void LoadFromFiles_WhenErrorsAreFound_ShouldThrowAggregateException()
$"errors_2.sql:(line 5, col 9): error: {ExceptionMessages.TagIsEmptyOrWhitespace}",
$"errors_2.sql:(line 6, col 1): error: {string.Format(ExceptionMessages.LineIsNotAssociatedWithAnyTag, "SELECT * FROM roles;")}"
};
var expectedErrors = new[]
{
string.Join(Environment.NewLine, loaderErrors),
string.Join(Environment.NewLine, parserErrors)
};

// Act
Action action = () => loader.LoadFromFiles(files);

// Assert
action.Should()
.Throw<AggregateException>()
.WithInnerException<YeSqlLoaderException>()
.WithMessage(string.Join(Environment.NewLine, expectedLoaderErrors))
.WithInnerException<YeSqlParserException>()
.WithMessage(string.Join(Environment.NewLine, expectedParserErrors));
.Which
.InnerExceptions
.Select(innerException => innerException.Message)
.Should()
.BeEquivalentTo(expectedErrors);
}

[Test]
Expand Down Expand Up @@ -151,12 +157,12 @@ public void LoadFromDirectories_WhenErrorsAreFound_ShouldThrowAggregateException
"directory_not_found",
"env",
};
var expectedLoaderErrors = new[]
var loaderErrors = new[]
{
string.Format(ExceptionMessages.DirectoryNotFound, "directory_not_found"),
string.Format(ExceptionMessages.NoneFileFoundInSpecifiedDirectory, "env")
};
var expectedParserErrors = new[]
var parserErrors = new[]
{
$"errors_1.sql:(line 2, col 1): error: {string.Format(ExceptionMessages.LineIsNotAssociatedWithAnyTag, "SELECT * FROM users;")}",
$"errors_1.sql:(line 9, col 9): error: {ExceptionMessages.TagIsEmptyOrWhitespace}",
Expand All @@ -165,17 +171,23 @@ public void LoadFromDirectories_WhenErrorsAreFound_ShouldThrowAggregateException
$"errors_2.sql:(line 5, col 9): error: {ExceptionMessages.TagIsEmptyOrWhitespace}",
$"errors_2.sql:(line 6, col 1): error: {string.Format(ExceptionMessages.LineIsNotAssociatedWithAnyTag, "SELECT * FROM roles;")}"
};
var expectedErrors = new[]
{
string.Join(Environment.NewLine, loaderErrors),
string.Join(Environment.NewLine, parserErrors)
};

// Act
Action action = () => loader.LoadFromDirectories(directories);

// Assert
action.Should()
.Throw<AggregateException>()
.WithInnerException<YeSqlLoaderException>()
.WithMessage(string.Join(Environment.NewLine, expectedLoaderErrors))
.WithInnerException<YeSqlParserException>()
.WithMessage(string.Join(Environment.NewLine, expectedParserErrors));
.Which
.InnerExceptions
.Select(innerException => innerException.Message)
.Should()
.BeEquivalentTo(expectedErrors);
}

[Test]
Expand Down

0 comments on commit b6636b4

Please sign in to comment.