Esempio 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),
     });
 }
Esempio n. 2
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");
        }