Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Add tests to EnvValidationResult #173

Merged
merged 1 commit into from
Jun 17, 2024
Merged
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
98 changes: 98 additions & 0 deletions tests/Common/EnvValidationResultTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
namespace DotEnv.Core.Tests.Common;

[TestClass]
public class EnvValidationResultTests
{
[TestMethod]
public void HasError_WhenThereAreErrors_ShouldReturnsTrue()
{
// Arrange
var validationResult = new EnvValidationResult
{
"Error!"
};

// Act
bool actual = validationResult.HasError();

// Assert
actual.Should().BeTrue();
}

[TestMethod]
public void HasError_WhenThereAreNoErrors_ShouldReturnsFalse()
{
// Arrange
var validationResult = new EnvValidationResult();

// Act
bool actual = validationResult.HasError();

// Assert
actual.Should().BeFalse();
}

[TestMethod]
public void ErrorMessages_WhenThereAreNoErrors_ShouldReturnsEmptyString()
{
// Arrange
var validationResult = new EnvValidationResult();

// Act
string actual = validationResult.ErrorMessages;

// Assert
actual.Should().BeEmpty();
}

[TestMethod]
public void ErrorMessages_WhenThereAreErrors_ShouldReturnsSetOfErrors()
{
// Arrange
var validationResult = new EnvValidationResult
{
"Error1",
"Error2",
"Error3"
};
// Add new line at the beginning and end.
var expectedMessages =
"""

Error1
Error2
Error3

""";

// Act
string actual = validationResult.ErrorMessages;

// Assert
actual.Should().Be(expectedMessages);
}

[TestMethod]
public void GetEnumerator_WhenThereAreErrors_ShouldAllowIteratingOverThem()
{
// Arrange
var validationResult = new EnvValidationResult
{
"Error1",
"Error2",
"Error3"
};
var expected = new[]
{
"Error1",
"Error2",
"Error3"
};

// Act
IEnumerable<string> actual = validationResult.AsEnumerable();

// Assert
actual.Should().BeEquivalentTo(expected);
}
}
Loading