public void GetPowerBICapacity_IndividualScope()
        {
            // Arrange
            var client      = new Mock <IPowerBIApiClient>();
            var capacities  = SetupPowerBICapacityMock(client);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBICapacity(initFactory);

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            client.Verify(x => x.Capacities.GetCapacities(), Times.Once());
            client.Verify(x => x.Capacities.GetCapacitiesAsAdmin(null), Times.Never);
            AssertExpectedUnitTestResults(capacities.Item1, initFactory);
            Assert.IsFalse(initFactory.Logger.ErrorRecords.Any());
        }
        public void GetPowerBICapacity_WithGetCapacitiesApiThrowingException()
        {
            // Arrange
            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Capacities.GetCapacities()).Throws(new Exception("Some exception"));
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBICapacity(initFactory);

            // 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.Capacities.GetCapacities(), Times.Once());
        }
        public void GetPowerBICapacity_IndividualScope_WithShowEncryptionKey()
        {
            // Arrange
            var client      = new Mock <IPowerBIApiClient>();
            var capacities  = SetupPowerBICapacityMock(client);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBICapacity(initFactory)
            {
                ShowEncryptionKey = true
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            var throwingErrorRecords = initFactory.Logger.ThrowingErrorRecords;

            Assert.AreEqual(throwingErrorRecords.Count(), 1);
            Assert.AreEqual(throwingErrorRecords.First().ToString(), "-ShowEncryptionKey is only applied when -Scope is set to Organization");
        }
        public void GetPowerBICapacity_OrganizationScope_WithShowEncryptionKey()
        {
            // Arrange
            var client      = new Mock <IPowerBIApiClient>();
            var capacities  = SetupPowerBICapacityMock(client);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBICapacity(initFactory)
            {
                Scope             = PowerBIUserScope.Organization,
                ShowEncryptionKey = true
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            client.Verify(x => x.Capacities.GetCapacities(), Times.Never);
            client.Verify(x => x.Capacities.GetCapacitiesAsAdmin("tenantKey"), Times.Once());
            AssertExpectedUnitTestResults(capacities.Item2, initFactory);
            Assert.IsFalse(initFactory.Logger.ErrorRecords.Any());
        }