public void RotatePowerBIEncryptionKey_WithNoMatchingEncryptionKeys() { // Arrange var client = new Mock <IPowerBIApiClient>(); var tenantKey = new EncryptionKey() { Id = Guid.NewGuid(), Name = MockName, KeyVaultKeyIdentifier = new Uri(MockKeyVaultKeyUri), IsDefault = MockDefault, CreatedAt = new DateTime(1995, 1, 1), UpdatedAt = new DateTime(1995, 1, 1) }; client.Setup(x => x.Admin.GetPowerBIEncryptionKeys()).Returns(new List <EncryptionKey>()); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new SwitchPowerBIEncryptionKey(initFactory) { Name = MockName, KeyVaultKeyUri = MockKeyVaultKeyUri }; // Act cmdlet.InvokePowerBICmdlet(); // Assert var throwingErrorRecords = initFactory.Logger.ThrowingErrorRecords; Assert.IsTrue(throwingErrorRecords.Count() > 0, "Should throw Exception"); Assert.AreEqual(throwingErrorRecords.First().ToString(), "No encryption keys are set"); }
public void RotatePowerBIEncryptionKey_WithAllValidParameters() { // Arrange var tenantKey1 = new EncryptionKey() { Id = Guid.NewGuid(), Name = "KeyName1", KeyVaultKeyIdentifier = new Uri("http://www.contoso1.com/"), IsDefault = true, CreatedAt = new DateTime(1995, 1, 1), UpdatedAt = new DateTime(1995, 1, 1) }; var tenantKey2 = new EncryptionKey() { Id = Guid.NewGuid(), Name = "KeyName2", KeyVaultKeyIdentifier = new Uri("http://www.contoso2.com/"), IsDefault = false, CreatedAt = new DateTime(1995, 1, 1), UpdatedAt = new DateTime(1995, 1, 1) }; var rotatedTenantKey = new EncryptionKey() { Id = Guid.NewGuid(), Name = "KeyName1", KeyVaultKeyIdentifier = new Uri("http://www.contoso3.com/"), IsDefault = true, CreatedAt = new DateTime(1995, 1, 1), UpdatedAt = new DateTime(1995, 1, 1) }; var tenantKeys = new List <EncryptionKey>() { tenantKey1, tenantKey2 }; var client = new Mock <IPowerBIApiClient>(); client.Setup(x => x.Admin.GetPowerBIEncryptionKeys()).Returns(tenantKeys); client.Setup(x => x.Admin.RotatePowerBIEncryptionKey(It.IsAny <Guid>(), It.IsAny <string>())).Returns(rotatedTenantKey); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new SwitchPowerBIEncryptionKey(initFactory) { Name = "KeyName1", KeyVaultKeyUri = "http://www.contoso3.com/" }; // Act cmdlet.InvokePowerBICmdlet(); // Assert client.Verify(x => x.Admin.GetPowerBIEncryptionKeys(), Times.Once()); client.Verify(x => x.Admin.RotatePowerBIEncryptionKey(tenantKey1.Id, "http://www.contoso3.com/"), Times.Once()); AssertExpectedUnitTestResults(rotatedTenantKey, initFactory); }