-
Notifications
You must be signed in to change notification settings - Fork 0
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
34f3762
commit e23325a
Showing
4 changed files
with
152 additions
and
0 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
71 changes: 71 additions & 0 deletions
71
tests/RabbitMQ.Next.Tests/Publisher/DelegatePublishMiddlewareTests.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,71 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using NSubstitute; | ||
using RabbitMQ.Next.Publisher; | ||
using Xunit; | ||
|
||
namespace RabbitMQ.Next.Tests.Publisher; | ||
|
||
public class DelegatePublishMiddlewareTests | ||
{ | ||
[Fact] | ||
public void ThrowsOnEmptyNext() | ||
{ | ||
var handler = Substitute.For<Action<object, IMessageBuilder>>(); | ||
|
||
Assert.Throws<ArgumentNullException>(() => new DelegatePublishMiddleware(null, handler)); | ||
} | ||
|
||
[Fact] | ||
public void ThrowsOnEmptyHandler() | ||
{ | ||
var next = Substitute.For<IPublishMiddleware>(); | ||
|
||
Assert.Throws<ArgumentNullException>(() => new DelegatePublishMiddleware(next, null)); | ||
} | ||
|
||
[Fact] | ||
public void ThrowsOnCancellation() | ||
{ | ||
var handler = Substitute.For<Action<object, IMessageBuilder>>(); | ||
var next = Substitute.For<IPublishMiddleware>(); | ||
|
||
var message = Substitute.For<IMessageBuilder>(); | ||
var middleware = new DelegatePublishMiddleware(next, handler); | ||
var cancellation = new CancellationTokenSource(); | ||
cancellation.Cancel(); | ||
|
||
Assert.ThrowsAnyAsync<TaskCanceledException>(async () => await middleware.InvokeAsync("test", message, cancellation.Token)); | ||
handler.DidNotReceive().Invoke(Arg.Any<object>(), Arg.Any<IMessageBuilder>()); | ||
next.DidNotReceive().InvokeAsync(Arg.Any<object>(), Arg.Any<IMessageBuilder>(), Arg.Any<CancellationToken>()); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldCallHandler() | ||
{ | ||
var handler = Substitute.For<Action<object, IMessageBuilder>>(); | ||
var next = Substitute.For<IPublishMiddleware>(); | ||
|
||
var message = Substitute.For<IMessageBuilder>(); | ||
var middleware = new DelegatePublishMiddleware(next, handler); | ||
|
||
await middleware.InvokeAsync("test", message, default); | ||
|
||
handler.Received().Invoke("test", message); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldCallNext() | ||
{ | ||
var handler = Substitute.For<Action<object, IMessageBuilder>>(); | ||
var next = Substitute.For<IPublishMiddleware>(); | ||
|
||
var message = Substitute.For<IMessageBuilder>(); | ||
var middleware = new DelegatePublishMiddleware(next, handler); | ||
|
||
await middleware.InvokeAsync("test", message, default); | ||
|
||
await next.Received().InvokeAsync("test", message, Arg.Any<CancellationToken>()); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
tests/RabbitMQ.Next.Tests/Publisher/DelegateReturnMiddlewareTests.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,71 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using NSubstitute; | ||
using RabbitMQ.Next.Publisher; | ||
using Xunit; | ||
|
||
namespace RabbitMQ.Next.Tests.Publisher; | ||
|
||
public class DelegateReturnMiddlewareTests | ||
{ | ||
[Fact] | ||
public void ThrowsOnEmptyNext() | ||
{ | ||
var handler = Substitute.For<Action<IReturnedMessage>>(); | ||
|
||
Assert.Throws<ArgumentNullException>(() => new DelegateReturnMiddleware(null, handler)); | ||
} | ||
|
||
[Fact] | ||
public void ThrowsOnEmptyHandler() | ||
{ | ||
var next = Substitute.For<IReturnMiddleware>(); | ||
|
||
Assert.Throws<ArgumentNullException>(() => new DelegateReturnMiddleware(next, null)); | ||
} | ||
|
||
[Fact] | ||
public void ThrowsOnCancellation() | ||
{ | ||
var handler = Substitute.For<Action<IReturnedMessage>>(); | ||
var next = Substitute.For<IReturnMiddleware>(); | ||
|
||
var message = Substitute.For<IReturnedMessage>(); | ||
var middleware = new DelegateReturnMiddleware(next, handler); | ||
var cancellation = new CancellationTokenSource(); | ||
cancellation.Cancel(); | ||
|
||
Assert.ThrowsAnyAsync<TaskCanceledException>(async () => await middleware.InvokeAsync(message, cancellation.Token)); | ||
handler.DidNotReceive().Invoke(Arg.Any<IReturnedMessage>()); | ||
next.DidNotReceive().InvokeAsync(Arg.Any<IReturnedMessage>(), Arg.Any<CancellationToken>()); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldCallHandler() | ||
{ | ||
var handler = Substitute.For<Action<IReturnedMessage>>(); | ||
var next = Substitute.For<IReturnMiddleware>(); | ||
|
||
var message = Substitute.For<IReturnedMessage>(); | ||
var middleware = new DelegateReturnMiddleware(next, handler); | ||
|
||
await middleware.InvokeAsync(message, default); | ||
|
||
handler.Received().Invoke(message); | ||
} | ||
|
||
[Fact] | ||
public async Task ShouldCallNext() | ||
{ | ||
var handler = Substitute.For<Action<IReturnedMessage>>(); | ||
var next = Substitute.For<IReturnMiddleware>(); | ||
|
||
var message = Substitute.For<IReturnedMessage>(); | ||
var middleware = new DelegateReturnMiddleware(next, handler); | ||
|
||
await middleware.InvokeAsync(message, default); | ||
|
||
await next.Received().InvokeAsync(message, Arg.Any<CancellationToken>()); | ||
} | ||
} |