Skip to content

Commit a1ddc71

Browse files
committed
Add tests
1 parent 7fb6a83 commit a1ddc71

File tree

6 files changed

+40
-1
lines changed

6 files changed

+40
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![codecov](https://codecov.io/gh/Sergi0Martin/OpenMediator/graph/badge.svg?token=MYOEKIL20M)](https://codecov.io/gh/Sergi0Martin/OpenMediator)
2+
13
# OpenMediator
24
Alternative for those who do not want to pay for a mediator implementation.
35

src/OpenMediator.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<PackageTags>mediator;mediator-pattern</PackageTags>
1212
<Description>Alternative for those who do not want to pay for a mediator implementation.</Description>
1313
<Authors>Sergio Martin</Authors>
14-
<Version>1.1.1</Version>
14+
<Version>1.1.2</Version>
1515
<RepositoryUrl>https://github.com/Sergi0Martin/OpenMediator</RepositoryUrl>
1616
<PackageProjectUrl>https://sergi0martin.github.io/OpenMediator</PackageProjectUrl>
1717
<PackageReadmeFile>README.md</PackageReadmeFile>

test/OpenMediator.Shared.Test/MediatorMiddlewares/CustomMediatorMiddleware.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using OpenMediator.Middlewares;
2+
using System.Diagnostics.CodeAnalysis;
23

34
namespace OpenMediator.Shared.Test.MediatorMiddlewares;
45

6+
[ExcludeFromCodeCoverage]
57
public class CustomMediatorMiddleware(TestDependency testDependency) : IMediatorMiddleware
68
{
79
public async Task ExecuteAsync<TCommand>(TCommand command, Func<Task> next)

test/OpenMediator.Shared.Test/MediatorMiddlewares/SecondCustomMediatorMiddleware.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
using OpenMediator.Middlewares;
2+
using System.Diagnostics.CodeAnalysis;
23

34
namespace OpenMediator.Shared.Test.MediatorMiddlewares;
45

6+
[ExcludeFromCodeCoverage]
57
public class SecondCustomMediatorMiddleware(TestDependency testDependency) : IMediatorMiddleware
68
{
79
public async Task ExecuteAsync<TCommand>(TCommand command, Func<Task> next)

test/OpenMediator.Unit.Test/Commands/CommandResponseTest.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,21 @@ public async Task Send_Command_With_Response_Works()
3333
Assert.Equal(result, expectedResult);
3434
Assert.True(_testDependency.Called);
3535
}
36+
37+
[Fact]
38+
public async Task Send_Command_With_Response_Throw_If_Not_Registered()
39+
{
40+
// Arrange
41+
var command = new GetCarModelCommand(1);
42+
43+
// Act
44+
Func<Task> action = async () => await _fixture.Mediator.SendAsync<GetCarModelCommand, string>(command);
45+
46+
// Assert
47+
var exception = await Assert.ThrowsAsync<InvalidOperationException>(action);
48+
Assert.Equal("Handler not found for command GetCarModelCommand", exception.Message);
49+
}
50+
51+
public record GetCarModelCommand(int Id) : ICommand<string>;
52+
3653
}

test/OpenMediator.Unit.Test/Commands/CommandTest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,20 @@ public async Task Send_Command_Works()
2828
// Assert
2929
Assert.True(_testDependency.Called);
3030
}
31+
32+
[Fact]
33+
public async Task Send_Command_Throw_If_Not_Registered()
34+
{
35+
// Arrange
36+
var command = new CreateCarCommand(1);
37+
38+
// Act
39+
Func<Task> action = async () => await _fixture.Mediator.SendAsync(command);
40+
41+
// Assert
42+
var exception = await Assert.ThrowsAsync<InvalidOperationException>(action);
43+
Assert.Equal("Handler not found for command CreateCarCommand", exception.Message);
44+
}
45+
46+
public record CreateCarCommand(int Id) : ICommand;
3147
}

0 commit comments

Comments
 (0)