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);
        }
 public async Task GetDeviceAsyncWithNullDeviceIdTest()
 {
     var restOpMock = new Mock<IHttpClientHelper>();
     var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
     await registryManager.GetDeviceAsync(null);
     Assert.Fail("Calling GetDeviceAsync with null device id did not throw an exception.");
 }
        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();
        }
        public async Task GetDeviceAsyncTest()
        {
            const string DeviceId = "123";
            var deviceToReturn = new Device(DeviceId) { ConnectionState = DeviceConnectionState.Connected };
            var restOpMock = new Mock<IHttpClientHelper>();
            restOpMock.Setup(restOp => restOp.GetAsync<Device>(It.IsAny<Uri>(), It.IsAny<IDictionary<HttpStatusCode, Func<HttpResponseMessage, Task<Exception>>>>(), null, false, It.IsAny<CancellationToken>())).ReturnsAsync(deviceToReturn);

            var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
            var device = await registryManager.GetDeviceAsync(DeviceId);
            Assert.AreSame(deviceToReturn, device);
            restOpMock.VerifyAll();
        }
 public async Task DeleteDeviceAsyncWithNullIdTest()
 {
     var restOpMock = new Mock<IHttpClientHelper>();
     var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
     await registryManager.RemoveDeviceAsync(string.Empty);
     Assert.Fail("Delete API did not throw exception when the device id was null.");
 }
 public async Task DeleteDeviceAsyncTest()
 {
     var restOpMock = new Mock<IHttpClientHelper>();
     var mockETag = new ETagHolder() { ETag = "*" };
     restOpMock.Setup(restOp => restOp.DeleteAsync(It.IsAny<Uri>(), mockETag, It.IsAny<IDictionary<HttpStatusCode, Func<HttpResponseMessage, Task<Exception>>>>(), null, It.IsAny<CancellationToken>())).Returns(Task.FromResult(0));
     var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
     await registryManager.RemoveDeviceAsync(new Device());
     restOpMock.VerifyAll();
 }
 public async Task UpdateDeviceWithDeviceIdNullTest()
 {
     var restOpMock = new Mock<IHttpClientHelper>();
     var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
     await registryManager.UpdateDeviceAsync(new Device() { ETag = "*" });
     Assert.Fail("UpdateDevice api did not throw exception when the device's id was null.");
 }
 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.");
 }
 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.");
 }
Ejemplo n.º 10
0
 public async Task DeleteDevices2AsyncWithNullDeviceListTest()
 {
     var restOpMock = new Mock<IHttpClientHelper>();
     var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
     await registryManager.RemoveDevices2Async(new List<Device>());
     Assert.Fail("DeleteDevices API did not throw exception when Null device list was used.");
 }
Ejemplo n.º 11
0
 public async Task DeleteDevicesAsyncWithInvalidDeviceIdTest()
 {
     var goodDevice = new Device("123") { ConnectionState = DeviceConnectionState.Connected };
     var badDevice = new Device("/baddevice") { ConnectionState = DeviceConnectionState.Connected };
     var restOpMock = new Mock<IHttpClientHelper>();
     var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
     await registryManager.RemoveDevicesAsync(new List<Device>() { goodDevice, badDevice });
     Assert.Fail("DeleteDevices API did not throw exception when bad deviceid was used.");
 }
Ejemplo n.º 12
0
        public async Task UpdateDevicesAsyncForceUpdateMissingETagTest()
        {
            var badDevice1 = new Device("123") { ConnectionState = DeviceConnectionState.Connected };
            var badDevice2 = new Device("234") { ConnectionState = DeviceConnectionState.Connected };
            var restOpMock = new Mock<IHttpClientHelper>();
            restOpMock.Setup(restOp => restOp.PostAsync<IEnumerable<ExportImportDevice>, Task<string[]>>(It.IsAny<Uri>(), It.IsAny<IEnumerable<ExportImportDevice>>(), It.IsAny<IDictionary<HttpStatusCode, Func<HttpResponseMessage, Task<Exception>>>>(), It.IsAny<IDictionary<string, string>>(), It.IsAny<CancellationToken>())).ReturnsAsync(null);

            var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
            await registryManager.UpdateDevicesAsync(new List<Device>() { badDevice1, badDevice2 }, false, CancellationToken.None);
        }
Ejemplo n.º 13
0
 public async Task UpdateDevices2AsyncWithNullDeviceTest()
 {
     var goodDevice = new Device("123") { ConnectionState = DeviceConnectionState.Connected, ETag = "234" };
     Device badDevice = null;
     var restOpMock = new Mock<IHttpClientHelper>();
     var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
     await registryManager.UpdateDevices2Async(new List<Device>() { goodDevice, badDevice });
     Assert.Fail("UpdateDevices API did not throw exception when Null device was used.");
 }
Ejemplo n.º 14
0
 public async Task UpdateDeviceWithInvalidDeviceIdTest()
 {
     var restOpMock = new Mock<IHttpClientHelper>();
     var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
     // '/' is not a valid char in DeviceId
     await registryManager.UpdateDeviceAsync(new Device("/baddevice") { ETag = "*" });
     Assert.Fail("UpdateDevice api did not throw exception when the deviceid was invalid.");
 }
Ejemplo n.º 15
0
 public async Task RegisterDevices2AsyncWithETagsSetTest()
 {
     var goodDevice = new Device("123") { ConnectionState = DeviceConnectionState.Connected };
     var badDevice = new Device("234") { ConnectionState = DeviceConnectionState.Connected, ETag = "234" };
     var restOpMock = new Mock<IHttpClientHelper>();
     var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
     await registryManager.AddDevices2Async(new List<Device>() { goodDevice, badDevice });
     Assert.Fail("RegisterDevices API did not throw exception when ETag was used.");
 }
Ejemplo n.º 16
0
 public async Task DeleteDevices2AsyncWithDeviceIdNullTest()
 {
     var goodDevice = new Device("123") { ConnectionState = DeviceConnectionState.Connected, ETag = "234" };
     var badDevice = new Device();
     var restOpMock = new Mock<IHttpClientHelper>();
     var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
     await registryManager.RemoveDevices2Async(new List<Device>() { goodDevice, badDevice });
     Assert.Fail("DeleteDevices API did not throw exception when deviceId was null.");
 }
Ejemplo n.º 17
0
        public async Task DeleteDevices2AsyncForceDeleteFalseTest()
        {
            var goodDevice1 = new Device("123") { ConnectionState = DeviceConnectionState.Connected, ETag = "234" };
            var goodDevice2 = new Device("234") { ConnectionState = DeviceConnectionState.Connected, ETag = "123" };
            var restOpMock = new Mock<IHttpClientHelper>();
            restOpMock.Setup(restOp => restOp.PostAsync<IEnumerable<ExportImportDevice>, Task<BulkRegistryOperationResult>>(It.IsAny<Uri>(), It.IsAny<IEnumerable<ExportImportDevice>>(), It.IsAny<IDictionary<HttpStatusCode, Func<HttpResponseMessage, Task<Exception>>>>(), It.IsAny<IDictionary<string, string>>(), It.IsAny<CancellationToken>())).ReturnsAsync(null);

            var registryManager = new HttpRegistryManager(restOpMock.Object, IotHubName);
            await registryManager.RemoveDevices2Async(new List<Device>() { goodDevice1, goodDevice2 }, false, CancellationToken.None);
        }
 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.");
 }
        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);
        }