Skip to content

Commit

Permalink
Upgrade to NUnit 4.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejball committed Jan 12, 2024
1 parent c6812c4 commit 0f35ccb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ dotnet_diagnostic.IDE0170.severity = suggestion
dotnet_diagnostic.IDE0180.severity = warning
dotnet_diagnostic.IDE0290.severity = suggestion
dotnet_diagnostic.IDE1005.severity = suggestion
dotnet_diagnostic.NUnit2045.severity = suggestion
dotnet_diagnostic.SA0001.severity = none
dotnet_diagnostic.SA1003.severity = none
dotnet_diagnostic.SA1008.severity = none
Expand Down
3 changes: 2 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="NUnit" Version="3.14.0" />
<PackageVersion Include="NUnit" Version="4.0.1" />
<PackageVersion Include="NUnit3TestAdapter" Version="4.5.0" />
<PackageVersion Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageVersion Include="XmlDocMarkdown.Core" Version="2.9.0" />
</ItemGroup>
<ItemGroup>
<GlobalPackageReference Include="Faithlife.Analyzers" Version="1.4.0" />
<GlobalPackageReference Include="NUnit.Analyzers" Version="3.10.0" />
<GlobalPackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.507" />
</ItemGroup>
</Project>
20 changes: 10 additions & 10 deletions tests/Faithlife.DataAnnotations.Tests/ValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public void ValidateNull()
[TestCase("")]
public void ValidateNotValidatable(object value)
{
Assert.IsTrue(ValidatorUtility.IsValid(value));
Assert.IsEmpty(ValidatorUtility.GetValidationResults(value));
Assert.That(ValidatorUtility.IsValid(value));
Assert.That(ValidatorUtility.GetValidationResults(value), Is.Empty);
ValidatorUtility.Validate(value);
}

Expand All @@ -27,23 +27,23 @@ public void ValidateRequired()
var validatable = new ValidatableDto();

var results = ValidatorUtility.GetValidationResults(validatable);
Assert.AreEqual(nameof(ValidatableDto.Required), results.Single().MemberNames.Single());
Assert.That(results.Single().MemberNames.Single(), Is.EqualTo(nameof(ValidatableDto.Required)));
var exception = Assert.Throws<ValidationException>(() => ValidatorUtility.Validate(validatable));
Assert.AreEqual(nameof(ValidatableDto.Required), exception!.ValidationResult.MemberNames.Single());
Assert.That(exception!.ValidationResult.MemberNames.Single(), Is.EqualTo(nameof(ValidatableDto.Required)));

validatable.Required = "";
results = ValidatorUtility.GetValidationResults(validatable);
Assert.AreEqual(nameof(ValidatableDto.Required), results.Single().MemberNames.Single());
Assert.That(results.Single().MemberNames.Single(), Is.EqualTo(nameof(ValidatableDto.Required)));
Assert.Throws<ValidationException>(() => ValidatorUtility.Validate(validatable));

validatable.Required = " ";
results = ValidatorUtility.GetValidationResults(validatable);
Assert.AreEqual(nameof(ValidatableDto.Required), results.Single().MemberNames.Single());
Assert.That(results.Single().MemberNames.Single(), Is.EqualTo(nameof(ValidatableDto.Required)));
Assert.Throws<ValidationException>(() => ValidatorUtility.Validate(validatable));

validatable.Required = "x";
results = ValidatorUtility.GetValidationResults(validatable);
Assert.IsEmpty(results);
Assert.That(results, Is.Empty);
ValidatorUtility.Validate(validatable);
}

Expand All @@ -54,15 +54,15 @@ public void ValidateRecursive()
var validatable = new ValidatableDto { Required = "x", Validatable = invalid };

var results = ValidatorUtility.GetValidationResults(validatable);
Assert.AreEqual(nameof(ValidatableDto.Validatable), results.Single().MemberNames.Single());
Assert.That(results.Single().MemberNames.Single(), Is.EqualTo(nameof(ValidatableDto.Validatable)));

validatable.Validatable = new ValidatableDto { Required = "x", Validatable = invalid };
results = ValidatorUtility.GetValidationResults(validatable);
Assert.AreEqual(nameof(ValidatableDto.Validatable), results.Single().MemberNames.Single());
Assert.That(results.Single().MemberNames.Single(), Is.EqualTo(nameof(ValidatableDto.Validatable)));

validatable.Validatable.Validatable = new ValidatableDto { Required = "x" };
results = ValidatorUtility.GetValidationResults(validatable);
Assert.IsEmpty(results);
Assert.That(results, Is.Empty);
}

private sealed class ValidatableDto
Expand Down

0 comments on commit 0f35ccb

Please sign in to comment.