Skip to content

Instantly share code, notes, and snippets.

@derekgreer
Created August 18, 2017 21:23
Show Gist options
  • Save derekgreer/f29e5a783b0a3b00b14c49bf13a5d99c to your computer and use it in GitHub Desktop.
Save derekgreer/f29e5a783b0a3b00b14c49bf13a5d99c to your computer and use it in GitHub Desktop.
Test Spy API
public class RetryConsumerFilterSpecs
{
[Subject("Message Retry")]
public class when_a_handler_throws_an_exception_that_should_not_be_retried
{
static Action<IConsumeContext<string>> _nextStub;
static RetryConsumerFilter _filter;
static Exception _exception;
static Spy<IConsumeContext<string>> _consumeContextSpy;
Establish context = () =>
{
_nextStub = c => throw new Exception();
_consumeContextSpy = new Spy<IConsumeContext<string>>().Configure((spy, inquiries) =>
{
spy.Setup(x => x.RetryCount).Returns(0);
spy.Setup(x => x.RetryLater()).Callback(() => inquiries.Answer("was enqueued?", true));
});
_filter = new RetryConsumerFilter(new MessageBusOptions { MaxRetryCount = 0 });
};
Because of = () => _exception = Catch.Exception(() => _filter.Consume(_consumeContextSpy.Object, _nextStub));
It should_rethrow_the_exception = () => _exception.ShouldNotBeNull();
It should_not_enqueue_the_message = () => _consumeContextSpy.Ask<bool>("was enqueued?").ShouldBeFalse();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment