public async Task RegistryManager_Http_SasCredentialAuth_Renewed_Success() { // arrange string signature = TestConfiguration.IoTHub.GetIotHubSharedAccessSignature(TimeSpan.FromHours(-1)); var sasCredential = new AzureSasCredential(signature); using var registryManager = RegistryManager.Create( TestConfiguration.IoTHub.GetIotHubHostName(), sasCredential); var device = new Device(Guid.NewGuid().ToString()); // act try { await registryManager.AddDeviceAsync(device).ConfigureAwait(false); Assert.Fail("The SAS token is expired so the call should fail with an exception"); } catch (UnauthorizedException) { // Expected to be unauthorized exception. } signature = TestConfiguration.IoTHub.GetIotHubSharedAccessSignature(TimeSpan.FromHours(1)); sasCredential.Update(signature); Device createdDevice = await registryManager.AddDeviceAsync(device).ConfigureAwait(false); // assert Assert.IsNotNull(createdDevice); // cleanup await registryManager.RemoveDeviceAsync(device.Id).ConfigureAwait(false); }
public async Task RegistryManager_Http_TokenCredentialAuth_Success() { // arrange using var registryManager = RegistryManager.Create( Configuration.IoTHub.GetIotHubHostName(), Configuration.IoTHub.GetClientSecretCredential()); var device = new Device(Guid.NewGuid().ToString()); // act Device createdDevice = await registryManager.AddDeviceAsync(device).ConfigureAwait(false); // assert Assert.IsNotNull(createdDevice); // cleanup await registryManager.RemoveDeviceAsync(device.Id).ConfigureAwait(false); }
public async Task RegistryManager_Http_SasCredentialAuth_Success() { // arrange string signature = TestConfiguration.IoTHub.GetIotHubSharedAccessSignature(TimeSpan.FromHours(1)); using var registryManager = RegistryManager.Create( TestConfiguration.IoTHub.GetIotHubHostName(), new AzureSasCredential(signature)); var device = new Device(Guid.NewGuid().ToString()); // act Device createdDevice = await registryManager.AddDeviceAsync(device).ConfigureAwait(false); // assert Assert.IsNotNull(createdDevice); // cleanup await registryManager.RemoveDeviceAsync(device.Id).ConfigureAwait(false); }