コード例 #1
0
        public async Task InvokeMethodTimeoutTest()
        {
            DeviceMessageHandler deviceMessageHandler = this.GetDeviceMessageHandler();
            var methodRequest = new DirectMethodRequest("device10", "shutdown", null, TimeSpan.FromSeconds(2), TimeSpan.FromMilliseconds(10));

            Task <DirectMethodResponse> responseTask = deviceMessageHandler.InvokeMethodAsync(methodRequest);

            Assert.False(responseTask.IsCompleted);

            await Task.Delay(TimeSpan.FromSeconds(5));

            Assert.True(responseTask.IsCompleted);
            Assert.NotNull(responseTask.Result);
            Assert.Null(responseTask.Result.Data);
        }
コード例 #2
0
        public async Task InvokedMethodMismatchedResponseTest()
        {
            DeviceMessageHandler deviceMessageHandler = this.GetDeviceMessageHandler();
            var methodRequest = new DirectMethodRequest("device10", "shutdown", null, TimeSpan.FromSeconds(2), TimeSpan.FromMilliseconds(10));

            Task <DirectMethodResponse> responseTask = deviceMessageHandler.InvokeMethodAsync(methodRequest);

            Assert.False(responseTask.IsCompleted);

            IMessage message = new EdgeMessage.Builder(new byte[0]).Build();

            message.Properties[SystemProperties.CorrelationId] = methodRequest.CorrelationId + 1;
            message.Properties[SystemProperties.StatusCode]    = "200";
            await deviceMessageHandler.ProcessMethodResponseAsync(message);

            Assert.False(responseTask.IsCompleted);
        }