public async Task VerifyCertificateOperationError() { string issuerName = Recording.GenerateId(); string certName = Recording.GenerateId(); CertificateIssuer certIssuer = new CertificateIssuer(issuerName, "DigiCert") { AccountId = "test", Password = "******", OrganizationId = "test", }; await Client.CreateIssuerAsync(certIssuer); CertificateOperation operation = null; try { CertificatePolicy certificatePolicy = DefaultPolicy; certificatePolicy.IssuerName = issuerName; operation = await Client.StartCreateCertificateAsync(certName, certificatePolicy); operation = InstrumentOperation(operation); RegisterForCleanup(certName); using CancellationTokenSource cts = new CancellationTokenSource(TimeSpan.FromMinutes(2)); TimeSpan pollingInterval = Mode == RecordedTestMode.Playback ? TimeSpan.Zero : KeyVaultTestEnvironment.DefaultPollingInterval; while (!operation.HasCompleted) { await Task.Delay(pollingInterval, cts.Token); await operation.UpdateStatusAsync(cts.Token); } InvalidOperationException ex = Assert.Throws <InvalidOperationException>(() => { KeyVaultCertificateWithPolicy cert = operation.Value; }); StringAssert.StartsWith("The certificate operation failed: ", ex.Message); Assert.IsTrue(operation.HasCompleted); Assert.IsFalse(operation.HasValue); Assert.AreEqual(200, operation.GetRawResponse().Status); Assert.AreEqual("failed", operation.Properties.Status); } catch (TaskCanceledException) when(operation != null) { Assert.Inconclusive("Timed out while waiting for operation {0}", operation.Id); } finally { await Client.DeleteIssuerAsync(issuerName); } }