Exemplo n.º 1
0
        public async void GetDeviceKeysAsync()
        {
            var deviceId = fixture.Create <string>();
            var device   = new Device(deviceId);
            var auth     = new AuthenticationMechanism();

            auth.SymmetricKey              = new SymmetricKey();
            auth.SymmetricKey.PrimaryKey   = "1fLjiNCMZF37LmHnjZDyVQ ==";
            auth.SymmetricKey.SecondaryKey = "fbsIV6w7gfVUyoRIQFSVgw ==";
            device.Authentication          = auth;
            deviceManagerMock.Setup(dm => dm.GetDeviceAsync(deviceId))
            .ReturnsAsync(device);

            var keys = await iotHubRepository.GetDeviceKeysAsync(deviceId);

            Assert.NotNull(keys);
            deviceId = fixture.Create <string>();
            deviceManagerMock.Setup(dm => dm.GetDeviceAsync(deviceId))
            .ReturnsAsync(null);

            keys = await iotHubRepository.GetDeviceKeysAsync(deviceId);

            Assert.Null(keys);
        }
 /// <summary>
 /// Retrieves the IoT Hub keys for the given device
 /// </summary>
 /// <param name="deviceId">ID of the device to retrieve</param>
 /// <returns>Primary and Secondary keys from the IoT Hub</returns>
 public async Task <SecurityKeys> GetIoTHubKeysAsync(string deviceId)
 {
     return(await _iotHubRepository.GetDeviceKeysAsync(deviceId));
 }