Skip to content

Commit

Permalink
Merge pull request #748 from rafaelsc/tests/impoveCoverge
Browse files Browse the repository at this point in the history
Improve Test Code Coverage
  • Loading branch information
jbogard authored May 31, 2022
2 parents 163ae5d + ac06930 commit 7788599
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
29 changes: 29 additions & 0 deletions test/MediatR.Tests/CreateStreamTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace MediatR.Tests;

using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
Expand Down Expand Up @@ -128,4 +129,32 @@ public async Task Should_resolve_main_handler_by_specific_interface()

i.ShouldBe(1);
}

[Fact]
public void Should_raise_execption_on_null_request()
{
var container = new Container(cfg =>
{
cfg.For<ServiceFactory>().Use<ServiceFactory>(ctx => t => ctx.GetInstance(t));
cfg.For<IMediator>().Use<Mediator>();
});

var mediator = container.GetInstance<IMediator>();

Should.Throw<ArgumentNullException>(() => mediator.CreateStream((Ping) null));
}

[Fact]
public void Should_raise_execption_on_null_request_via_dynamic_dispatch()
{
var container = new Container(cfg =>
{
cfg.For<ServiceFactory>().Use<ServiceFactory>(ctx => t => ctx.GetInstance(t));
cfg.For<IMediator>().Use<Mediator>();
});

var mediator = container.GetInstance<IMediator>();

Should.Throw<ArgumentNullException>(() => mediator.CreateStream((object) null));
}
}
16 changes: 16 additions & 0 deletions test/MediatR.Tests/SendTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace MediatR.Tests;

using System;
using System.Threading.Tasks;
using Shouldly;
using StructureMap;
Expand Down Expand Up @@ -98,4 +99,19 @@ public async Task Should_resolve_main_handler_by_specific_interface()

response.Message.ShouldBe("Ping Pong");
}


[Fact]
public async Task Should_raise_execption_on_null_request()
{
var container = new Container(cfg =>
{
cfg.For<ServiceFactory>().Use<ServiceFactory>(ctx => t => ctx.GetInstance(t));
cfg.For<ISender>().Use<Mediator>();
});

var mediator = container.GetInstance<ISender>();

await Should.ThrowAsync<ArgumentNullException>(async () => await mediator.Send(null));
}
}

0 comments on commit 7788599

Please sign in to comment.