-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Ability to filter handling of a ValidationException by the erro…
…r filter
- Loading branch information
1 parent
41ae74e
commit 7e10dd9
Showing
10 changed files
with
219 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using FluentValidation; | ||
using HotChocolate; | ||
using Moq; | ||
using Xunit; | ||
|
||
namespace FairyBread.Tests | ||
{ | ||
public class DefaultValidationErrorFilterTests | ||
{ | ||
[Fact] | ||
public void Should_Handle_ValidationException() | ||
{ | ||
// Arrange | ||
var error = new AnError().WithException(new ValidationException("some msg")); | ||
|
||
var defaultValidationErrorFilter = new ValidationErrorFilter(); | ||
|
||
// Act / Assert | ||
Assert.Throws<NotImplementedException>(() => defaultValidationErrorFilter.OnError(error)); | ||
} | ||
|
||
[Fact] | ||
public void Should_Ignore_OtherException() | ||
{ | ||
// Arrange | ||
var error = new AnError().WithException(new Exception("some msg")); | ||
|
||
var defaultValidationErrorFilter = new ValidationErrorFilter(); | ||
|
||
// Act / Assert | ||
defaultValidationErrorFilter.OnError(error); | ||
} | ||
|
||
[Fact] | ||
public void Should_Ignore_CertainValidationException() | ||
{ | ||
// Arrange | ||
var error = new AnError().WithException(new Exception("some msg")); | ||
|
||
var defaultValidationErrorFilter = new ValidationErrorFilter(ex => false); | ||
|
||
// Act / Assert | ||
defaultValidationErrorFilter.OnError(error); | ||
} | ||
|
||
class AnError : IError | ||
{ | ||
public string Message => throw new NotImplementedException(); | ||
|
||
public string Code => throw new NotImplementedException(); | ||
|
||
public IReadOnlyList<object> Path => throw new NotImplementedException(); | ||
|
||
public IReadOnlyList<Location> Locations => throw new NotImplementedException(); | ||
|
||
private Exception? _exception; | ||
public Exception? Exception => _exception; | ||
|
||
public IReadOnlyDictionary<string, object> Extensions => throw new NotImplementedException(); | ||
|
||
public IError AddExtension(string key, object value) => throw new NotImplementedException(); | ||
public IError RemoveException() => throw new NotImplementedException(); | ||
public IError RemoveExtension(string key) => throw new NotImplementedException(); | ||
public IError WithCode(string code) => throw new NotImplementedException(); | ||
public IError WithException(Exception exception) | ||
{ | ||
_exception = exception; | ||
return this; | ||
} | ||
|
||
public IError WithExtensions(IReadOnlyDictionary<string, object> extensions) => throw new NotImplementedException(); | ||
public IError WithLocations(IReadOnlyList<Location> locations) => throw new NotImplementedException(); | ||
public IError WithMessage(string message) => throw new NotImplementedException(); | ||
public IError WithPath(Path path) => throw new NotImplementedException(); | ||
public IError WithPath(IReadOnlyList<object> path) => throw new NotImplementedException(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 21 additions & 3 deletions
24
...airyBread/DefaultValidationErrorFilter.cs → src/FairyBread/ValidationErrorFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters