public async Task ModuleClient_SetReceiveCallbackAsync_RemoveCallback_Amqp()
        {
            var moduleClient = ModuleClient.CreateFromConnectionString(FakeConnectionString, TransportType.Amqp_Tcp_Only);
            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, 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);
        }
Esempio n. 2
0
        public async Task ModuleClient_SetReceiveCallbackAsync_RemoveCallback_Mqtt()
        {
            ModuleClient moduleClient = await CreateMqttModuleClient();

            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(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);

            await innerHandler.DidNotReceiveWithAnyArgs().DisableReceiveMessageAsync(Arg.Any <CancellationToken>()).ConfigureAwait(false);

            await moduleClient.SetInputMessageHandlerAsync("endpoint1", null, null).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(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(true, Arg.Any <CancellationToken>()).ConfigureAwait(false);

            await innerHandler.DidNotReceiveWithAnyArgs().EnableReceiveMessageAsync(Arg.Any <CancellationToken>()).ConfigureAwait(false);

            await innerHandler.Received(1).DisableEventReceiveAsync(true, Arg.Any <CancellationToken>()).ConfigureAwait(false);

            await innerHandler.DidNotReceiveWithAnyArgs().DisableReceiveMessageAsync(Arg.Any <CancellationToken>()).ConfigureAwait(false);
        }
Esempio n. 3
0
        public async Task ModuleClient_SetDefaultReceiveCallbackAsync_SetCallback_Amqp()
        {
            ModuleClient moduleClient = await CreateAmqpModuleClientAsync();

            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(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_003: [** It shall EnableEventReceiveAsync when called for the first time. **]**
        public async Task ModuleClient_SetDefaultReceiveCallbackAsync_SetCallback_Mqtt()
        {
            var transportType = TransportType.Mqtt_Tcp_Only;
            var moduleClient  = ModuleClient.CreateFromConnectionString(FakeConnectionString, transportType);
            IDelegatingHandler innerHandler = Substitute.For <IDelegatingHandler>();

            moduleClient.InnerHandler = innerHandler;

            await moduleClient.SetMessageHandlerAsync((message, context) => Task.FromResult(MessageResponse.Completed), "custom data").ConfigureAwait(false);

            await innerHandler.Received().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);
        }