コード例 #1
0
        public async Task TestSettingDesiredPropertyToNullAndCheckReported1()
        {
            var harness    = new ModuleHostHarness();
            var controller = new TestController1();
            await harness.RunTestAsync(controller.YieldReturn(),
                                       async (deviceId, moduleId, services) => {
                var hub  = services.Resolve <IIoTHubTwinServices>();
                var twin = await hub.GetAsync(deviceId, moduleId);

                // TODO : Assert precondition
                // Assert.True(twin.Properties.Reported.TryGetValue(nameof(TestController1.TestSetting3), out var pre));

                // Act
                await hub.UpdatePropertyAsync(deviceId, moduleId,
                                              nameof(TestController1.TestSetting3), null);
                twin = await hub.GetAsync(deviceId, moduleId);

                // Assert
                Assert.True(controller._applyCalled);
                Assert.Null(controller.TestSetting3);
                Assert.False(twin.Properties.Reported.TryGetValue(nameof(TestController1.TestSetting3), out var post));
                Assert.Null(post);
                Assert.True((bool)twin.Properties.Reported[TwinProperty.kConnected]);
            });
        }
コード例 #2
0
        public async Task TestSetting3DesiredPropertyAndCheckReported1()
        {
            var harness    = new ModuleHostHarness();
            var controller = new TestController1();
            await harness.RunTestAsync(controller.YieldReturn(),
                                       async (deviceId, moduleId, services) => {
                // Act
                var hub = services.Resolve <IIoTHubTwinServices>();
                await hub.UpdatePropertyAsync(deviceId, moduleId,
                                              nameof(TestController1.TestSetting1), "test");
                await hub.UpdatePropertyAsync(deviceId, moduleId,
                                              nameof(TestController1.TestSetting2), "test2");
                await hub.UpdatePropertyAsync(deviceId, moduleId,
                                              nameof(TestController1.TestSetting3), "test3");
                var twin = await hub.GetAsync(deviceId, moduleId);

                // Assert
                Assert.True(controller._applyCalled);
                Assert.Equal("test", controller.TestSetting1);
                Assert.Equal("test2", controller.TestSetting2);
                Assert.Equal("test3", controller.TestSetting3);
                Assert.Equal("test", twin.Properties.Reported[nameof(TestController1.TestSetting1)]);
                Assert.Equal("test2", twin.Properties.Reported[nameof(TestController1.TestSetting2)]);
                Assert.Equal("test3", twin.Properties.Reported[nameof(TestController1.TestSetting3)]);
                Assert.True((bool)twin.Properties.Reported[TwinProperty.kConnected]);
            });
        }
コード例 #3
0
        public async Task TestSettingDesiredPropertyAndCheckReported2()
        {
            var harness    = new ModuleHostHarness();
            var controller = new TestController2();
            await harness.RunTestAsync(controller.YieldReturn(),
                                       async (deviceId, moduleId, services) => {
                var hub      = services.Resolve <IIoTHubTwinServices>();
                var expected = new Test {
                    Item1 = "test",
                    Item2 = 5454,
                    Item3 = DateTime.Now
                };

                // Act
                await hub.UpdatePropertyAsync(deviceId, moduleId,
                                              nameof(TestController2.TestSetting), JObject.FromObject(expected));
                var twin = await hub.GetAsync(deviceId, moduleId);

                // Assert
                Assert.True(controller._applyCalled);
                Assert.Equal(expected, controller.TestSetting);
                Assert.True(JToken.DeepEquals(JObject.FromObject(expected),
                                              twin.Properties.Reported[nameof(TestController2.TestSetting)]));
                Assert.True((bool)twin.Properties.Reported[TwinProperty.kConnected]);
            });
        }
コード例 #4
0
        public async Task TestTestNoReturnInvocationNoReturnUsingMethodClient()
        {
            var harness = new ModuleHostHarness();
            await harness.RunTestAsync(GetControllers(), async (device, module, services) => {
                var hub = services.Resolve <IMethodClient>();

                var response = await hub.CallMethodAsync(device, module, "TestNoReturn_V1",
                                                         JsonConvertEx.SerializeObject(nameof(TestControllerV1.TestNoReturnAsync)));

                Assert.Null(response);
            });
        }
コード例 #5
0
        public async Task TestTestNoParametersInvocationNullParamUsingMethodClient()
        {
            var harness = new ModuleHostHarness();
            await harness.RunTestAsync(GetControllers(), async (device, module, services) => {
                var hub = services.Resolve <IMethodClient>();

                var response = await hub.CallMethodAsync(device, module, "TestNoParameters_V1",
                                                         null);

                var returned = JsonConvertEx.DeserializeObject <string>(response);
                Assert.Equal(nameof(TestControllerV1.TestNoParametersAsync), returned);
            });
        }
コード例 #6
0
        public async Task TestTestNoParametersAndNoReturnInvocationNoParamAndNoReturnUsingMethodClient()
        {
            var harness    = new ModuleHostHarness();
            var controller = new TestControllerV1();
            await harness.RunTestAsync(controller.YieldReturn(), async (device, module, services) => {
                var hub = services.Resolve <IMethodClient>();

                var response = await hub.CallMethodAsync(device, module, "TestNoParametersAndNoReturn_V1",
                                                         JsonConvertEx.SerializeObject(null));

                Assert.Null(response);
                Assert.True(controller._noparamcalled);
            });
        }
コード例 #7
0
        public async Task TestTestNoReturnInvocationNoReturn()
        {
            var harness = new ModuleHostHarness();
            await harness.RunTestAsync(GetControllers(), async (device, module, services) => {
                var hub = services.Resolve <IIoTHubTwinServices>();

                var response = await hub.CallMethodAsync(device, module, new MethodParameterModel {
                    Name        = "TestNoReturn_V1",
                    JsonPayload = JsonConvertEx.SerializeObject(nameof(TestControllerV1.TestNoReturnAsync))
                });

                Assert.Null(response.JsonPayload);
                Assert.Equal(200, response.Status);
            });
        }
コード例 #8
0
        public async Task TestTestNoParametersInvocationNoParam()
        {
            var harness = new ModuleHostHarness();
            await harness.RunTestAsync(GetControllers(), async (device, module, services) => {
                var hub = services.Resolve <IIoTHubTwinServices>();

                var response = await hub.CallMethodAsync(device, module, new MethodParameterModel {
                    Name        = "TestNoParameters_V1",
                    JsonPayload = _serializer.SerializeToString(null)
                });

                var returned = _serializer.Deserialize <string>(response.JsonPayload);
                Assert.Equal(nameof(TestControllerV1.TestNoParametersAsync), returned);
                Assert.Equal(200, response.Status);
            });
        }
コード例 #9
0
        public async Task TestTest2InvocationWithLargeBufferUsingMethodClient()
        {
            var harness = new ModuleHostHarness();
            await harness.RunTestAsync(GetControllers(), async (device, module, services) => {
                var hub = services.Resolve <IMethodClient>();

                var buffer = new byte[300809];
                r.NextBytes(buffer);

                var response = await hub.CallMethodAsync(device, module, "Test2_V1",
                                                         JsonConvertEx.SerializeObject(buffer));

                var returned = JsonConvertEx.DeserializeObject <byte[]>(response);
                Assert.True(buffer.SequenceEqual(returned));
            });
        }
コード例 #10
0
        public async Task TestTest1InvocationWithSmallBufferUsingMethodClient()
        {
            var harness = new ModuleHostHarness();
            await harness.RunTestAsync(GetControllers(), async (device, module, services) => {
                var hub = services.Resolve <IMethodClient>();

                var buffer = new byte[1049];
                kRand.NextBytes(buffer);
                var expected = new TestModel {
                    Test = buffer
                };
                var response = await hub.CallMethodAsync(device, module, "Test1_V1",
                                                         _serializer.SerializeToString(expected));
                var returned = _serializer.Deserialize <TestModel>(response);
                Assert.Equal(expected.Test, returned.Test);
            });
        }
コード例 #11
0
        public async Task TestPresetSettingIsReportedOnModuleStart()
        {
            var harness    = new ModuleHostHarness();
            var controller = new TestController1();
            await harness.RunTestAsync(controller.YieldReturn(),
                                       async (deviceId, moduleId, services) => {
                // Act
                var hub  = services.Resolve <IIoTHubTwinServices>();
                var twin = await hub.GetAsync(deviceId, moduleId);

                // Assert
                Assert.Equal("yearn", controller.TestSetting3);

                // TODO : Should report initial state of setting if not null
                // Assert.Equal("yearn", twin.Properties.Reported[nameof(TestController1.TestSetting3)]);
            });
        }
コード例 #12
0
        public async Task TestTestNoParametersAndNoReturnInvocationNoParamAndNoReturn()
        {
            var harness    = new ModuleHostHarness();
            var controller = new TestControllerV1();
            await harness.RunTestAsync(controller.YieldReturn(), async (device, module, services) => {
                var hub = services.Resolve <IIoTHubTwinServices>();

                var response = await hub.CallMethodAsync(device, module, new MethodParameterModel {
                    Name        = "TestNoParametersAndNoReturn_V1",
                    JsonPayload = _serializer.SerializeToString(null)
                });

                Assert.Null(response.JsonPayload);
                Assert.Equal(200, response.Status);
                Assert.True(controller._noparamcalled);
            });
        }
コード例 #13
0
        public async Task TestTest1InvocationWithLargeBufferUsingMethodClient()
        {
            var harness = new ModuleHostHarness();
            await harness.RunTestAsync(GetControllers(), async (device, module, services) => {
                var hub = services.Resolve <IMethodClient>();

                var buffer = new byte[300809];
                r.NextBytes(buffer);
                var expected = new TestModel {
                    Test = buffer
                };
                var response = await hub.CallMethodAsync(device, module, "Test1_V1",
                                                         JsonConvertEx.SerializeObject(expected));
                var returned = JsonConvertEx.DeserializeObject <TestModel>(response);
                Assert.Equal(expected.Test, returned.Test);
            });
        }
コード例 #14
0
        public async Task TestTest2Invocation()
        {
            var harness = new ModuleHostHarness();
            await harness.RunTestAsync(GetControllers(), async (device, module, services) => {
                var hub = services.Resolve <IIoTHubTwinServices>();

                var buffer = new byte[1049];
                r.NextBytes(buffer);

                var response = await hub.CallMethodAsync(device, module, new MethodParameterModel {
                    Name        = "Test2_V1",
                    JsonPayload = JsonConvertEx.SerializeObject(buffer)
                });

                var returned = JsonConvertEx.DeserializeObject <byte[]>(response.JsonPayload);
                Assert.True(buffer.SequenceEqual(returned));
                Assert.Equal(200, response.Status);
            });
        }
コード例 #15
0
        public async Task TestSettingDesiredPropertyAndCheckReported1()
        {
            var harness    = new ModuleHostHarness();
            var controller = new TestController1();
            await harness.RunTestAsync(controller.YieldReturn(),
                                       async (deviceId, moduleId, services) => {
                var test = _serializer.FromObject("test4");
                // Act
                var hub = services.Resolve <IIoTHubTwinServices>();
                await hub.UpdatePropertyAsync(deviceId, moduleId,
                                              nameof(TestController1.TestSetting1), test);
                var twin = await hub.GetAsync(deviceId, moduleId);

                // Assert
                Assert.True(controller._applyCalled);
                Assert.Equal("test4", controller.TestSetting1);
                Assert.Equal(test, twin.Properties.Reported[nameof(TestController1.TestSetting1)]);
            });
        }
コード例 #16
0
        public async Task TestTest3InvocationWithLargeBufferUsingMethodClient()
        {
            var harness = new ModuleHostHarness();
            await harness.RunTestAsync(GetControllers(), async (device, module, services) => {
                var hub = services.Resolve <IMethodClient>();

                var buffer = new byte[300809];
                kRand.NextBytes(buffer);

                var response = await hub.CallMethodAsync(device, module, "Test3_V1",
                                                         _serializer.SerializeToString(new {
                    request = buffer,
                    value   = 55
                })
                                                         );

                var returned = _serializer.Deserialize <byte[]>(response);
                Assert.True(buffer.SequenceEqual(returned));
            });
        }
コード例 #17
0
        public async Task TestTest3InvocationV2WithLargeBufferUsingMethodClient()
        {
            var harness = new ModuleHostHarness();
            await harness.RunTestAsync(GetControllers(), async (device, module, services) => {
                var hub = services.Resolve <IMethodClient>();

                var buffer = new byte[300809];
                r.NextBytes(buffer);
                var expected = 3254;

                var response = await hub.CallMethodAsync(device, module, "Test3_V2",
                                                         JsonConvertEx.SerializeObject(new {
                    request = buffer,
                    value   = expected
                })
                                                         );

                var returned = JsonConvertEx.DeserializeObject <int>(response);
                Assert.Equal(expected, returned);
            });
        }
コード例 #18
0
        public async Task TestTest3Invocation()
        {
            var harness = new ModuleHostHarness();
            await harness.RunTestAsync(GetControllers(), async (device, module, services) => {
                var hub = services.Resolve <IIoTHubTwinServices>();

                var buffer = new byte[1049];
                kRand.NextBytes(buffer);

                var response = await hub.CallMethodAsync(device, module, new MethodParameterModel {
                    Name        = "Test3_V1",
                    JsonPayload = _serializer.SerializeToString(new {
                        request = buffer,
                        value   = 55
                    })
                });

                var returned = _serializer.Deserialize <byte[]>(response.JsonPayload);
                Assert.True(buffer.SequenceEqual(returned));
                Assert.Equal(200, response.Status);
            });
        }
コード例 #19
0
        public async Task TestTest1Invocation()
        {
            var harness = new ModuleHostHarness();
            await harness.RunTestAsync(GetControllers(), async (device, module, services) => {
                var hub = services.Resolve <IIoTHubTwinServices>();

                var buffer = new byte[1049];
                kRand.NextBytes(buffer);
                var expected = new TestModel {
                    Test = buffer
                };

                var response = await hub.CallMethodAsync(device, module, new MethodParameterModel {
                    Name        = "Test1_V1",
                    JsonPayload = JsonConvertEx.SerializeObject(expected)
                });

                var returned = JsonConvertEx.DeserializeObject <TestModel>(response.JsonPayload);
                Assert.Equal(expected.Test, returned.Test);
                Assert.Equal(200, response.Status);
            });
        }
コード例 #20
0
        public async Task TestTest3InvocationV2()
        {
            var harness = new ModuleHostHarness();
            await harness.RunTestAsync(GetControllers(), async (device, module, services) => {
                var hub = services.Resolve <IIoTHubTwinServices>();

                var buffer = new byte[1049];
                r.NextBytes(buffer);
                var expected = 3254;

                var response = await hub.CallMethodAsync(device, module, new MethodParameterModel {
                    Name        = "Test3_v2",
                    JsonPayload = JsonConvertEx.SerializeObject(new {
                        request = buffer,
                        value   = expected
                    })
                });

                var returned = JsonConvertEx.DeserializeObject <int>(response.JsonPayload);
                Assert.Equal(expected, returned);
                Assert.Equal(200, response.Status);
            });
        }