Skip to content

Commit fee74fb

Browse files
add unit test for command handlers.
1 parent d5bbed1 commit fee74fb

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

CleanTemplate.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{7C72E0CA-8
2727
EndProject
2828
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CleanTemplate.Api.Test", "test\Api.Test\CleanTemplate.Api.Test.csproj", "{7B57CD7B-9BE2-48D9-972A-DD52EF08F1D7}"
2929
EndProject
30+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CleanTemplate.CommandHandler.Test", "test\CleanTemplate.CommandHandler.Test\CleanTemplate.CommandHandler.Test.csproj", "{917A5A94-07E5-4045-964C-F7DF48B22FF2}"
31+
EndProject
3032
Global
3133
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3234
Debug|Any CPU = Debug|Any CPU
@@ -61,6 +63,10 @@ Global
6163
{7B57CD7B-9BE2-48D9-972A-DD52EF08F1D7}.Debug|Any CPU.Build.0 = Debug|Any CPU
6264
{7B57CD7B-9BE2-48D9-972A-DD52EF08F1D7}.Release|Any CPU.ActiveCfg = Release|Any CPU
6365
{7B57CD7B-9BE2-48D9-972A-DD52EF08F1D7}.Release|Any CPU.Build.0 = Release|Any CPU
66+
{917A5A94-07E5-4045-964C-F7DF48B22FF2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
67+
{917A5A94-07E5-4045-964C-F7DF48B22FF2}.Debug|Any CPU.Build.0 = Debug|Any CPU
68+
{917A5A94-07E5-4045-964C-F7DF48B22FF2}.Release|Any CPU.ActiveCfg = Release|Any CPU
69+
{917A5A94-07E5-4045-964C-F7DF48B22FF2}.Release|Any CPU.Build.0 = Release|Any CPU
6470
EndGlobalSection
6571
GlobalSection(SolutionProperties) = preSolution
6672
HideSolutionNode = FALSE
@@ -76,6 +82,7 @@ Global
7682
{4323D8A3-82BB-4C33-8687-AF2E5ADFA191} = {238972C8-A659-488D-9E17-8A1B3E820ECB}
7783
{91374971-8444-4CF7-A21F-5BF08111848E} = {238972C8-A659-488D-9E17-8A1B3E820ECB}
7884
{7B57CD7B-9BE2-48D9-972A-DD52EF08F1D7} = {7C72E0CA-895D-4676-BEBA-2ADB297F1164}
85+
{917A5A94-07E5-4045-964C-F7DF48B22FF2} = {7C72E0CA-895D-4676-BEBA-2ADB297F1164}
7986
EndGlobalSection
8087
GlobalSection(ExtensibilityGlobals) = postSolution
8188
SolutionGuid = {D550EB2A-3876-4261-981F-44C6D936D367}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using CleanTemplate.Application.Products.Command.AddProduct;
2+
using CleanTemplate.Common.Exceptions;
3+
using CleanTemplate.Persistance.CommandHandlers.Products;
4+
using CleanTemplate.Persistance.Db;
5+
using Microsoft.Extensions.Logging;
6+
using Moq;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
using Xunit;
10+
11+
namespace CleanTemplate.CommandHandler.Test
12+
{
13+
public class AddProductCommandHandlerTest
14+
{
15+
[Fact]
16+
public async Task AddProductCommandHandler_Should_ThrowException()
17+
{
18+
var dbContext = new Mock<CleanArchWriteDbContext>();
19+
var logger = new Mock<ILogger<AddProductCommandHandler>>();
20+
21+
var commandHandler = new AddProductCommandHandler(dbContext.Object, logger.Object);
22+
23+
var request = new Mock<AddProductCommand>();
24+
25+
//await Assert.ThrowsAsync<InvalidNullInputException>(() => commandHandler.Handle(request.Object, CancellationToken.None));
26+
await Assert.ThrowsAsync<InvalidNullInputException>(() => commandHandler.Handle(null, CancellationToken.None));
27+
}
28+
}
29+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
7+
<IsPackable>false</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
12+
<PackageReference Include="Moq" Version="4.16.1" />
13+
<PackageReference Include="xunit" Version="2.4.1" />
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
15+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16+
<PrivateAssets>all</PrivateAssets>
17+
</PackageReference>
18+
<PackageReference Include="coverlet.collector" Version="3.1.0">
19+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
20+
<PrivateAssets>all</PrivateAssets>
21+
</PackageReference>
22+
</ItemGroup>
23+
24+
<ItemGroup>
25+
<ProjectReference Include="..\..\src\Infrastructure\Persistance\CleanTemplate.Persistance.csproj" />
26+
</ItemGroup>
27+
28+
</Project>

0 commit comments

Comments
 (0)