Ejemplo n.º 1
0
 /// <summary>
 /// Returns a set of 4 devices the first two being non-edge
 /// </summary>
 /// <returns></returns>
 private IEnumerable <Device> CreateTestListOfDevices()
 {
     return(new List <Device>()
     {
         DevicesTest.CreateTestDevice("device0", false),
         DevicesTest.CreateTestDevice("device1", false),
         DevicesTest.CreateTestDevice("device2", true),
         DevicesTest.CreateTestDevice("device3", true),
     });
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Returns a set of edge and non-edge twins
 /// </summary>
 /// <returns></returns>
 private List <Twin> CreateTestListOfTwins()
 {
     return(new List <Twin>()
     {
         DevicesTest.CreateTestTwin(0, false),
         DevicesTest.CreateTestTwin(1, false),
         DevicesTest.CreateTestTwin(2, true),
         DevicesTest.CreateTestTwin(3, true)
     });
 }
Ejemplo n.º 3
0
        public async Task GetEdgeDeviceTest()
        {
            // Arrange
            var nonEdgeDevice      = "nonEdgeDevice";
            var edgeDevice         = "edgeDevice";
            var edgeDeviceFromTwin = "edgeDeviceFromTwin";

            this.registryMock
            .Setup(x => x.CreateQuery(It.IsAny <string>()))
            .Returns(new ResultQuery(0));

            this.registryMock
            .Setup(x => x.GetTwinAsync(nonEdgeDevice))
            .ReturnsAsync(DevicesTest.CreateTestTwin(0));
            this.registryMock
            .Setup(x => x.GetTwinAsync(edgeDevice))
            .ReturnsAsync(DevicesTest.CreateTestTwin(1));
            this.registryMock
            .Setup(x => x.GetTwinAsync(edgeDeviceFromTwin))
            .ReturnsAsync(DevicesTest.CreateTestTwin(2, true));

            this.registryMock
            .Setup(x => x.GetDeviceAsync(nonEdgeDevice))
            .ReturnsAsync(DevicesTest.CreateTestDevice("nonEdgeDevice", false));
            this.registryMock
            .Setup(x => x.GetDeviceAsync(edgeDevice))
            .ReturnsAsync(DevicesTest.CreateTestDevice("edgeDevice", true));
            this.registryMock
            .Setup(x => x.GetDeviceAsync(edgeDeviceFromTwin))
            .ReturnsAsync(DevicesTest.CreateTestDevice("edgeDeviceFromTwin", false));

            // Act
            var dvc1 = await this.devices.GetAsync(nonEdgeDevice);

            var dvc2 = await this.devices.GetAsync(edgeDevice);

            var dvc3 = await this.devices.GetAsync(edgeDeviceFromTwin);

            // Assert
            Assert.False(dvc1.IsEdgeDevice, "Non-edge device reporting edge device");
            Assert.True(dvc2.IsEdgeDevice, "Edge device reported not edge device");

            // When using getDevices method which is deprecated it doesn't return IsEdgeDevice
            // capabilities properly so we support grabbing this from the device twin as well.
            Assert.True(dvc3.IsEdgeDevice, "Edge device from twin reporting not edge device");
        }
Ejemplo n.º 4
0
        public async Task GetModuleTwinTest(string deviceId, string moduleId, bool throwsException)
        {
            if (throwsException)
            {
                // Act & Assert
                await Assert.ThrowsAsync <InvalidInputException>(async() =>
                                                                 await this.devices.GetModuleTwinAsync(deviceId, moduleId));
            }
            else
            {
                // Arrange
                this.registryMock
                .Setup(x => x.GetTwinAsync(deviceId, moduleId))
                .ReturnsAsync(DevicesTest.CreateTestTwin(0));

                // Act
                var twinSvcModel = await this.devices.GetModuleTwinAsync(deviceId, moduleId);

                // Assert
                Assert.Equal("value0", twinSvcModel.ReportedProperties["test"].ToString());
                Assert.Equal("value0", twinSvcModel.DesiredProperties["test"].ToString());
            }
        }