-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Serhii A. Hrytsenko <[email protected]>
- Loading branch information
1 parent
a08f68d
commit 0101f8d
Showing
7 changed files
with
111 additions
and
11 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
58 changes: 58 additions & 0 deletions
58
src/HomeInventory/HomeInventory.Tests/Presentation/Web/FluentOptionsValidatorTests.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using FluentValidation; | ||
using HomeInventory.Web.Framework; | ||
using Microsoft.Extensions.Options; | ||
|
||
namespace HomeInventory.Tests.Presentation.Web; | ||
|
||
[UnitTest] | ||
public sealed class FluentOptionsValidatorTests() : BaseTest<FluentOptionsValidatorTestsGivenContext>(static t => new(t)) | ||
{ | ||
[Fact] | ||
public void Create_Should_ReturnValidator() | ||
{ | ||
Given | ||
.New<string>(out var nameVar) | ||
.SubstituteFor<IValidator>(out var validatorVar); | ||
|
||
var then = When | ||
.Invoked(nameVar, validatorVar, static (name, validator) => FluentOptionsValidator.Create<SubjectOptions>(name, validator)); | ||
|
||
then.Result(actual => actual.Should().BeAssignableTo<FluentOptionsValidator<SubjectOptions>>()); | ||
} | ||
|
||
[Fact] | ||
public void Validate_Should_Skip_When_NameIsDifferent() | ||
{ | ||
Given | ||
.New<string>(out var nameVar) | ||
.New<string>(out var differentNameVar) | ||
.New<SubjectOptions>(out var optionsVar, () => new()) | ||
.SubstituteFor<IValidator>(out var validatorVar) | ||
.New(out var sutVar, nameVar, validatorVar, static (name, validator) => FluentOptionsValidator.Create<SubjectOptions>(name, validator)); | ||
|
||
var then = When | ||
.Invoked(sutVar, differentNameVar, optionsVar, (sut, name, options) => sut.Validate(name, options)); | ||
|
||
then.Result(actual => actual.Should().BeSameAs(ValidateOptionsResult.Skip)); | ||
} | ||
|
||
[Fact] | ||
public void Validate_Should_CallValidator() | ||
{ | ||
Given | ||
.New<string>(out var nameVar) | ||
.New<SubjectOptions>(out var optionsVar, () => new()) | ||
.New<FluentValidation.Results.ValidationResult>(out var resultVar, () => new()) | ||
.SubstituteFor<IValidationContext>(out var validationContextVar) | ||
.SubstituteFor(out IVariable<IValidationContextFactory<SubjectOptions>> factoryVar, optionsVar, validationContextVar, static (f, o, ctx) => f.CreateContext(o).Returns(ctx)) | ||
.SubstituteFor(out IVariable<IValidator> validatorVar, validationContextVar, resultVar, static (v, ctx, r) => v.Validate(ctx).Returns(r)) | ||
.New(out var sutVar, nameVar, validatorVar, factoryVar, static (name, validator, factory) => FluentOptionsValidator.Create(name, validator, factory)); | ||
|
||
var then = When | ||
.Invoked(sutVar, nameVar, optionsVar, (sut, name, options) => sut.Validate(name, options)); | ||
|
||
then | ||
.Result(actual => actual.Should().BeSameAs(ValidateOptionsResult.Success)) | ||
.Ensure(validatorVar, validationContextVar, static (validator, context) => validator.Received(1).Validate(context)); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...Inventory/HomeInventory.Tests/Presentation/Web/FluentOptionsValidatorTestsGivenContext.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
namespace HomeInventory.Tests.Presentation.Web; | ||
|
||
public sealed class FluentOptionsValidatorTestsGivenContext(BaseTest test) : GivenContext<FluentOptionsValidatorTestsGivenContext>(test) | ||
{ | ||
} |
8 changes: 8 additions & 0 deletions
8
src/HomeInventory/HomeInventory.Tests/Presentation/Web/SubjectOptions.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using HomeInventory.Web.Framework; | ||
|
||
namespace HomeInventory.Tests.Presentation.Web; | ||
|
||
public sealed class SubjectOptions : IOptions | ||
{ | ||
public static SectionPath Section => nameof(Section); | ||
} |
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