コード例 #1
0
        public async Task DeviceAuthenticationGoodAuthConfigTest2()
        {
            var deviceGoodAuthConfig = new Device("123")
            {
                ConnectionState = DeviceConnectionState.Connected,
                Authentication = new AuthenticationMechanism()
                {
                    SymmetricKey = null,
                    X509Thumbprint = new X509Thumbprint()
                    {
                        PrimaryThumbprint = "921BC9694ADEB8929D4F7FE4B9A3A6DE58B0790B",
                        SecondaryThumbprint = "921BC9694ADEB8929D4F7FE4B9A3A6DE58B0790B"
                    }
                }
            };

            var restOpMock = new Mock<IHttpClientHelper>();
            restOpMock.Setup(
                restOp =>
                    restOp.PutAsync(It.IsAny<Uri>(), It.IsAny<Device>(), It.IsAny<PutOperationType>(),
                        It.IsAny<IDictionary<HttpStatusCode, Func<HttpResponseMessage, Task<Exception>>>>(),
                        It.IsAny<CancellationToken>())).ReturnsAsync(deviceGoodAuthConfig);
            var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
            await registryManager.AddDeviceAsync(deviceGoodAuthConfig);
        }
コード例 #2
0
        public async Task RegisterDeviceAsyncTest()
        {
            var deviceToReturn = new Device("123") { ConnectionState = DeviceConnectionState.Connected };
            var restOpMock = new Mock<IHttpClientHelper>();
            restOpMock.Setup(restOp => restOp.PutAsync(It.IsAny<Uri>(), It.IsAny<Device>(), It.IsAny<PutOperationType>(), It.IsAny<IDictionary<HttpStatusCode, Func<HttpResponseMessage, Task<Exception>>>>(), It.IsAny<CancellationToken>())).ReturnsAsync(deviceToReturn);

            var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
            var returnedDevice = await registryManager.AddDeviceAsync(deviceToReturn);
            Assert.AreSame(deviceToReturn, returnedDevice);
            restOpMock.VerifyAll();
        }
コード例 #3
0
 public async Task RegisterDeviceAsyncWithETagSetTest()
 {
     var deviceToReturn = new Device("123") { ConnectionState = DeviceConnectionState.Connected, ETag = "123" };
     var restOpMock = new Mock<IHttpClientHelper>();
     var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
     await registryManager.AddDeviceAsync(deviceToReturn);
     Assert.Fail("RegisterDevice API did not throw exception when ETag was set.");
 }
コード例 #4
0
 public async Task RegisterDeviceAsyncWithDeviceIdNullTest()
 {
     var restOpMock = new Mock<IHttpClientHelper>();
     var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
     await registryManager.AddDeviceAsync(new Device());
     Assert.Fail("RegisterDevice API did not throw exception when the device's id was not set.");
 }
コード例 #5
0
 public async Task RegisterDeviceAsyncWithNullDeviceTest()
 {
     var restOpMock = new Mock<IHttpClientHelper>();
     var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
     await registryManager.AddDeviceAsync(null);
     Assert.Fail("RegisterDevice API did not throw exception when the device parameter was null.");
 }
コード例 #6
0
        public async Task DeviceAuthenticationBadAuthConfigTest7()
        {
            var deviceBadAuthConfig = new Device("123")
            {
                ConnectionState = DeviceConnectionState.Connected,
                Authentication = new AuthenticationMechanism()
                {
                    SymmetricKey = new SymmetricKey()
                    {
                        PrimaryKey = CryptoKeyGenerator.GenerateKey(32),
                        SecondaryKey = null
                    },
                    X509Thumbprint = null
                }
            };

            var restOpMock = new Mock<IHttpClientHelper>();
            restOpMock.Setup(
                restOp =>
                    restOp.PutAsync(It.IsAny<Uri>(), It.IsAny<Device>(), It.IsAny<PutOperationType>(),
                        It.IsAny<IDictionary<HttpStatusCode, Func<HttpResponseMessage, Task<Exception>>>>(),
                        It.IsAny<CancellationToken>())).ReturnsAsync(deviceBadAuthConfig);
            var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
            await registryManager.AddDeviceAsync(deviceBadAuthConfig);
        }