-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94938a2
commit f4de475
Showing
7 changed files
with
198 additions
and
28 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
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,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
|
||
<IsPackable>false</IsPackable> | ||
|
||
<AssemblyName>MyWarehouse.Application.UnitTests</AssemblyName> | ||
|
||
<RootNamespace>MyWarehouse.Application.UnitTests</RootNamespace> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="coverlet.msbuild" Version="3.0.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="FluentAssertions" Version="5.10.3" /> | ||
<PackageReference Include="NUnit" Version="3.12.0" /> | ||
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Application\Application.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Folder Include="Common\Behaviors\" /> | ||
</ItemGroup> | ||
|
||
</Project> |
44 changes: 44 additions & 0 deletions
44
...ation.UnitTests/Common/Dependencies/DataAccess.Repositories.Common/ListQueryModelTests.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,44 @@ | ||
using FluentAssertions; | ||
using MyWarehouse.Application.Common.Dependencies.DataAccess.Repositories.Common; | ||
using MyWarehouse.Application.Common.Exceptions; | ||
using NUnit.Framework; | ||
using System; | ||
|
||
namespace MyWarehouse.Application.UnitTests.Common.Dependencies.DataAccess.Repositories.Common | ||
{ | ||
public class ListQueryModelTests | ||
{ | ||
[Test] | ||
public void Instantiation_SetsDefaultValues() | ||
{ | ||
var sut = new ListQueryModel<int>(); | ||
|
||
sut.PageIndex.Should().Be(1); | ||
sut.PageSize.Should().BeGreaterThan(1); | ||
sut.OrderBy.Should().Be("id"); | ||
sut.Filter.Should().BeNull(); | ||
} | ||
|
||
[Test] | ||
public void ThrowFilterIncorrectException_ReturnsFilterValidationError() | ||
{ | ||
var sut = new ListQueryModel<int>(); | ||
|
||
FluentActions.Invoking(() | ||
=> sut.ThrowFilterIncorrectException(new Exception())) | ||
.Should().ThrowExactly<InputValidationException>() | ||
.And.Errors.Keys.Should().Contain(nameof(ListQueryModel<int>.Filter)); | ||
} | ||
|
||
[Test] | ||
public void ThrowOrderByIncorrectException_ReturnsOrderByValidationError() | ||
{ | ||
var sut = new ListQueryModel<int>(); | ||
|
||
FluentActions.Invoking(() | ||
=> sut.ThrowOrderByIncorrectException(new Exception())) | ||
.Should().ThrowExactly<InputValidationException>() | ||
.And.Errors.Keys.Should().Contain(nameof(ListQueryModel<int>.OrderBy)); | ||
} | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
tests/Application.UnitTests/Common/Exceptions/InputValidationExceptionTests.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,79 @@ | ||
using FluentAssertions; | ||
using FluentValidation.Results; | ||
using MyWarehouse.Application.Common.Exceptions; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace MyWarehouse.Application.UnitTests.Common.Exceptions | ||
{ | ||
public class InputValidationExceptionTests | ||
{ | ||
|
||
[Test] | ||
public void Instantiation_Blank_SetsProperties() | ||
{ | ||
var innerException = new Exception(); | ||
|
||
var sut = new InputValidationException(innerException); | ||
|
||
sut.InnerException.Should().Be(innerException); | ||
sut.Message.Should().Contain("validation"); | ||
sut.Errors.Should().NotBeNull(); | ||
} | ||
|
||
[Test] | ||
public void Instantiation_WithValidationFailures_SetsProperties() | ||
{ | ||
var failures = new List<ValidationFailure>() | ||
{ | ||
new ValidationFailure("Prop", "Prop not good, mister."), | ||
new ValidationFailure("Prop", "Prop really not good, mister.") | ||
}; | ||
|
||
var sut = new InputValidationException(failures); | ||
|
||
sut.InnerException.Should().BeNull(); | ||
sut.Message.Should().Contain("validation"); | ||
sut.Errors.Should().HaveCount(1).And.ContainKey("Prop"); | ||
sut.Errors.First().Should().BeEquivalentTo( | ||
new { | ||
Key = "Prop", | ||
Value = new[] { | ||
failures[0].ErrorMessage, | ||
failures[1].ErrorMessage | ||
} | ||
}, | ||
because: "Validations failured are expected to be grouped by property name." | ||
); | ||
} | ||
|
||
[Test] | ||
public void Instantiation_WithTuples_SetsProperties() | ||
{ | ||
var failureTuples = new[] | ||
{ | ||
("Prop", "Prop not good, mister."), | ||
("Prop", "Prop really not good, mister.") | ||
}; | ||
|
||
var sut = new InputValidationException(failureTuples); | ||
|
||
sut.InnerException.Should().BeNull(); | ||
sut.Message.Should().Contain("validation"); | ||
sut.Errors.Should().HaveCount(1).And.ContainKey("Prop"); | ||
sut.Errors.First().Should().BeEquivalentTo( | ||
new | ||
{ | ||
Key = "Prop", | ||
Value = new[] { | ||
failureTuples[0].Item2, | ||
failureTuples[1].Item2 | ||
} | ||
}, | ||
because: "Validations failured are expected to be grouped by property name." | ||
); | ||
} | ||
} | ||
} |