예제 #1
0
        public async Task GetModuleTwinsTest(string query, string continuationToken)
        {
            const string resultToken = "nextToken";

            var twinList = new List <TwinServiceModel>()
            {
                ModulesControllerTest.CreateTestTwin("d", "m")
            };
            var twins = new TwinServiceListModel(twinList, resultToken);

            this.devicesMock.Setup(x => x.GetModuleTwinsByQueryAsync(query, continuationToken))
            .ReturnsAsync(twins);
            this.httpContext.Request.Headers.Add(
                ContinuationTokenName,
                new StringValues(continuationToken));

            // Act
            var moduleTwins = await this.controller.GetModuleTwinsAsync(query);

            // Assert
            var moduleTwin = moduleTwins.Items[0];

            Assert.Equal("d", moduleTwin.DeviceId);
            Assert.Equal("m", moduleTwin.ModuleId);
            Assert.Equal(resultToken, moduleTwins.ContinuationToken);
            Assert.Equal("v2", moduleTwin.Desired["version"]);
            Assert.Equal("v1", moduleTwin.Reported["version"]);
        }
예제 #2
0
        public async Task GetSingleModuleTwinTest(string deviceId, string moduleId, bool throwsException)
        {
            if (throwsException)
            {
                await Assert.ThrowsAsync <InvalidInputException>(async() =>
                                                                 await this.controller.GetModuleTwinAsync(deviceId, moduleId));
            }
            else
            {
                // Arrange
                var twinResult = ModulesControllerTest.CreateTestTwin(deviceId, moduleId);
                this.devicesMock.Setup(x => x.GetModuleTwinAsync(deviceId, moduleId))
                .ReturnsAsync(twinResult);

                // Act
                var module = await this.controller.GetModuleTwinAsync(deviceId, moduleId);

                // Assert
                Assert.Equal(moduleId, module.ModuleId);
                Assert.Equal(deviceId, module.DeviceId);
                Assert.Equal("v2", module.Desired["version"]);
                Assert.Equal("v1", module.Reported["version"]);
            }
        }