Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add Tests to Guard Checks
  • Loading branch information
rafaelsc committed May 29, 2022
commit ac06930ea8ac60a89c13d5c6c827ef06cc777862
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));
}
}