public void SetPowerBICapacityEncryptionKey_WithSetEncryptionKeyApiThrowingException() { // Arrange var client = new Mock <IPowerBIApiClient>(); var encryptionKeys = SetupPowerBIEncryptionKeyMock(client); client.Setup(x => x.Admin.SetPowerBICapacityEncryptionKey(It.IsAny <Guid>(), It.IsAny <Guid>())) .Throws(new Exception("Some exception")); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new SetPowerBICapacityEncryptionKey(initFactory) { KeyName = encryptionKeys[0].Name, CapacityId = MockCapacityId }; // Act cmdlet.InvokePowerBICmdlet(); // Assert var throwingErrorRecords = initFactory.Logger.ThrowingErrorRecords; Assert.AreEqual(throwingErrorRecords.Count(), 1); Assert.AreEqual(throwingErrorRecords.First().ToString(), "Some exception"); client.Verify(x => x.Admin.GetPowerBIEncryptionKeys(), Times.Once()); client.Verify(x => x.Admin.SetPowerBICapacityEncryptionKey(encryptionKeys[0].Id, MockCapacityId), Times.Once()); }
public void SetPowerBICapacityEncryptionKey_KeyNameAndCapacityIdParameterSet() { // Arrange var client = new Mock <IPowerBIApiClient>(); var encryptionKeys = SetupPowerBIEncryptionKeyMock(client); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new SetPowerBICapacityEncryptionKey(initFactory) { KeyName = encryptionKeys[0].Name, CapacityId = MockCapacityId }; // Act cmdlet.InvokePowerBICmdlet(); // Assert client.Verify(x => x.Admin.GetPowerBIEncryptionKeys(), Times.Once()); client.Verify(x => x.Admin.SetPowerBICapacityEncryptionKey(encryptionKeys[0].Id, MockCapacityId), Times.Once()); Assert.IsFalse(initFactory.Logger.ErrorRecords.Any()); }
public void SetPowerBICapacityEncryptionKey_WithNoMatchingEncryptionKeys() { // Arrange var client = new Mock <IPowerBIApiClient>(); var encryptionKeys = SetupPowerBIEncryptionKeyMock(client); var initFactory = new TestPowerBICmdletInitFactory(client.Object); var cmdlet = new SetPowerBICapacityEncryptionKey(initFactory) { KeyName = "RandomKeyName", CapacityId = MockCapacityId }; // Act cmdlet.InvokePowerBICmdlet(); // Assert var throwingErrorRecords = initFactory.Logger.ThrowingErrorRecords; Assert.AreEqual(throwingErrorRecords.Count(), 1); Assert.AreEqual(throwingErrorRecords.First().ToString(), "No matching encryption keys found"); client.Verify(x => x.Admin.GetPowerBIEncryptionKeys(), Times.Once()); client.Verify(x => x.Admin.SetPowerBICapacityEncryptionKey(It.IsAny <Guid>(), It.IsAny <Guid>()), Times.Never); }