public async Task ModuleClient_SetDefaultReceiveCallbackAsync_SetCallback_Amqp() { var moduleClient = ModuleClient.CreateFromConnectionString(FakeConnectionString, TransportType.Amqp_Tcp_Only); IDelegatingHandler innerHandler = Substitute.For <IDelegatingHandler>(); moduleClient.InnerHandler = innerHandler; await moduleClient.SetMessageHandlerAsync((message, context) => Task.FromResult(MessageResponse.Completed), "custom data").ConfigureAwait(false); await innerHandler.Received(1).EnableEventReceiveAsync(false, Arg.Any <CancellationToken>()).ConfigureAwait(false); await innerHandler.DidNotReceiveWithAnyArgs().EnableReceiveMessageAsync(Arg.Any <CancellationToken>()).ConfigureAwait(false); await innerHandler.DidNotReceiveWithAnyArgs().DisableEventReceiveAsync(false, Arg.Any <CancellationToken>()).ConfigureAwait(false); }
public async Task ModuleClient_SetReceiveCallbackAsync_SetCallback_Amqp() { ModuleClient moduleClient = await CreateAmqpModuleClientAsync(); IDelegatingHandler innerHandler = Substitute.For <IDelegatingHandler>(); moduleClient.InnerHandler = innerHandler; await moduleClient.SetInputMessageHandlerAsync("endpoint1", (message, context) => Task.FromResult(MessageResponse.Completed), "custom data").ConfigureAwait(false); await innerHandler.Received(1).EnableEventReceiveAsync(true, Arg.Any <CancellationToken>()).ConfigureAwait(false); await innerHandler.DidNotReceiveWithAnyArgs().EnableReceiveMessageAsync(Arg.Any <CancellationToken>()).ConfigureAwait(false); await innerHandler.DidNotReceiveWithAnyArgs().DisableEventReceiveAsync(true, Arg.Any <CancellationToken>()).ConfigureAwait(false); }
// Tests_SRS_DEVICECLIENT_33_004: [** It shall call DisableEventReceiveAsync when the last delegate has been removed. **]** public async Task ModuleClient_SetReceiveCallbackAsync_RemoveCallback_Mqtt() { var transportType = TransportType.Mqtt_Tcp_Only; var moduleClient = ModuleClient.CreateFromConnectionString(FakeConnectionString, transportType); IDelegatingHandler innerHandler = Substitute.For <IDelegatingHandler>(); moduleClient.InnerHandler = innerHandler; await moduleClient.SetInputMessageHandlerAsync("endpoint1", (message, context) => Task.FromResult(MessageResponse.Completed), "custom data").ConfigureAwait(false); await moduleClient.SetInputMessageHandlerAsync("endpoint2", (message, context) => Task.FromResult(MessageResponse.Completed), "custom data").ConfigureAwait(false); await innerHandler.Received(1).EnableEventReceiveAsync(false, Arg.Any <CancellationToken>()).ConfigureAwait(false); await innerHandler.DidNotReceiveWithAnyArgs().EnableReceiveMessageAsync(Arg.Any <CancellationToken>()).ConfigureAwait(false); await innerHandler.DidNotReceiveWithAnyArgs().DisableEventReceiveAsync(false, Arg.Any <CancellationToken>()).ConfigureAwait(false); await innerHandler.DidNotReceiveWithAnyArgs().DisableReceiveMessageAsync(Arg.Any <CancellationToken>()).ConfigureAwait(false); await moduleClient.SetInputMessageHandlerAsync("endpoint1", null, null).ConfigureAwait(false); await innerHandler.Received(1).EnableEventReceiveAsync(false, Arg.Any <CancellationToken>()).ConfigureAwait(false); await innerHandler.DidNotReceiveWithAnyArgs().EnableReceiveMessageAsync(Arg.Any <CancellationToken>()).ConfigureAwait(false); await innerHandler.DidNotReceiveWithAnyArgs().DisableEventReceiveAsync(false, default).ConfigureAwait(false); await innerHandler.DidNotReceiveWithAnyArgs().DisableReceiveMessageAsync(Arg.Any <CancellationToken>()).ConfigureAwait(false); await moduleClient.SetInputMessageHandlerAsync("endpoint2", null, null).ConfigureAwait(false); await innerHandler.Received(1).EnableEventReceiveAsync(false, Arg.Any <CancellationToken>()).ConfigureAwait(false); await innerHandler.DidNotReceiveWithAnyArgs().EnableReceiveMessageAsync(Arg.Any <CancellationToken>()).ConfigureAwait(false); await innerHandler.Received(1).DisableEventReceiveAsync(false, Arg.Any <CancellationToken>()).ConfigureAwait(false); await innerHandler.DidNotReceiveWithAnyArgs().DisableReceiveMessageAsync(Arg.Any <CancellationToken>()).ConfigureAwait(false); }