/// <summary> /// Will pass an incoming message to the <see cref="Handler"/> for processing. /// </summary> /// <param name="message"></param> /// <param name="cancellationToken"></param> protected async Task ReceiveMessageAsync(Message message, CancellationToken cancellationToken) { try { ProcessingMessage.Wait(cancellationToken); var combined = CancellationTokenSource .CreateLinkedTokenSource(cancellationToken, StopProcessingMessageToken).Token; await _receiver.ReceiveMessageAsync(message, combined); } finally { ProcessingMessage.Release(); } }
public async Task When_Message_Triggered_Send_To_Handler() { //Dummy message var message = new Message(); // Get added handler to ReceiverClient Func <Message, CancellationToken, Task> handler = null; A.CallTo(() => _receiverClient.RegisterMessageHandler( A <Func <Message, CancellationToken, Task> > ._, A <MessageHandlerOptions> ._)) .Invokes(call => { handler = call.GetArgument <Func <Message, CancellationToken, Task> >(0); }); await _sut.OpenAsync(CancellationToken.None); //Send message from ReceiverClient await handler(message, CancellationToken.None); // Assert that added message handler gets triggered on message A.CallTo(() => _receiver.ReceiveMessageAsync(A <Message> .That.IsSameAs(message), A <CancellationToken> ._)) .MustHaveHappenedOnceExactly(); }
private Task ReceiveMessageAsync(Message message, CancellationToken token) { return(_serviceBusMessageReceiver.ReceiveMessageAsync(message)); }