public void SetOnPremisesDataGatewayClusterReturnsExpectedResults()
        {
            // Arrange
            var expectedResponse = new HttpResponseMessage();
            var gatewayClusterId = Guid.NewGuid();
            var client           = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Gateways
                         .PatchGatewayCluster(gatewayClusterId, It.IsAny <PatchGatewayClusterRequest>(), true))
            .ReturnsAsync(expectedResponse);

            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new SetOnPremisesDataGatewayCluster(initFactory)
            {
                GatewayClusterId            = gatewayClusterId,
                Name                        = "name",
                Department                  = "department",
                Description                 = "description",
                ContactInformation          = "contactInformation",
                AllowCloudDatasourceRefresh = true,
                AllowCustomConnectors       = true,
                LoadBalancingSelectorType   = "loadBalancingSelectorType"
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory);
        }
Beispiel #2
0
        public void AddPowerBIWorkspaceUserIndividualScope_IdParameterSet()
        {
            // Arrange
            var workspaceId = Guid.NewGuid();
            var user        = new WorkspaceUser {
                UserPrincipalName = "*****@*****.**", AccessRight = WorkspaceUserAccessRight.Member.ToString()
            };
            var expectedResponse = new object();
            var client           = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces
                         .AddWorkspaceUser(workspaceId, It.Is <WorkspaceUser>(u => u.UserPrincipalName == user.UserPrincipalName && u.AccessRight == user.AccessRight)))
            .Returns(expectedResponse);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new AddPowerBIWorkspaceUser(initFactory)
            {
                Scope             = PowerBIUserScope.Individual,
                Id                = workspaceId,
                UserPrincipalName = user.UserPrincipalName,
                AccessRight       = WorkspaceUserAccessRight.Member,
                ParameterSet      = "UserEmailWithId",
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory);
        }
Beispiel #3
0
        public void CopyPowerBITileTest()
        {
            // Arrange
            var dashboardId       = Guid.NewGuid().ToString();
            var targetDashboardId = Guid.NewGuid().ToString();
            var tileId            = Guid.NewGuid().ToString();
            var expectedResponse  = new Tile();
            var client            = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Reports
                         .CopyTile(Guid.Empty, dashboardId, tileId, targetDashboardId, null, null, null, null))
            .Returns(expectedResponse);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new CopyPowerBITile(initFactory)
            {
                WorkspaceId       = Guid.Empty,
                DashboardId       = dashboardId,
                TileId            = tileId,
                TargetDashboardId = targetDashboardId,
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory);
        }
Beispiel #4
0
        public void AddPowerBIEncryptionKey_WithDefaultParameterSet()
        {
            // 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.AddPowerBIEncryptionKey(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>())).Returns(tenantKey);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new AddPowerBIEncryptionKey(initFactory)
            {
                Name           = MockName,
                KeyVaultKeyUri = MockKeyVaultKeyUri,
                Default        = MockDefault
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            client.Verify(x => x.Admin.AddPowerBIEncryptionKey(MockName, MockKeyVaultKeyUri, MockDefault, false), Times.Once());
        }
Beispiel #5
0
        public void GetPowerBIActivityEvents_NonInteractive()
        {
            // Arrange
            object         obj1 = new object();
            object         obj2 = new object();
            object         obj3 = new object();
            IList <object> ActivityEventEntities = new List <object>
            {
                obj1,
                obj2,
                obj3
            };

            var activityEventResponse = new ActivityEventResponse();

            activityEventResponse.ActivityEventEntities = ActivityEventEntities;
            activityEventResponse.ContinuationToken     = null;

            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Admin.GetPowerBIActivityEvents($"'{StartDateTime}'", $"'{EndDateTime}'", null, null)).Returns(activityEventResponse);

            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIActivityEvent(initFactory)
            {
                StartDateTime = StartDateTime,
                EndDateTime   = EndDateTime,
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            AssertExpectedUnitTestResults(activityEventResponse, initFactory);
        }
Beispiel #6
0
        public void GetWorkspacesOrganizationScopeSupportsDeleted()
        {
            // Arrange
            var filter             = string.Format("state eq '{0}'", WorkspaceState.Deleted);
            var expectedWorkspaces = new List <Workspace> {
                new Workspace {
                    Id = Guid.NewGuid(), Name = "TestWorkspace"
                }
            };
            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", filter, It.IsAny <int>(), null)).Returns(expectedWorkspaces);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIWorkspace(initFactory)
            {
                Scope   = PowerBIUserScope.Organization,
                Deleted = true,
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            AssertExpectedUnitTestResults(expectedWorkspaces, initFactory);
        }
        public void GetPowerBIDatasourceOrganizationScope_ListParameterSet()
        {
            // Arrange
            var datasetId           = Guid.NewGuid();
            var expectedDatasources = new List <Datasource> {
                new Datasource {
                    DatasourceId = Guid.NewGuid().ToString(), Name = "TestDatasource", GatewayId = Guid.NewGuid().ToString()
                }
            };
            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Datasets.GetDatasourcesAsAdmin(datasetId)).Returns(expectedDatasources);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIDatasource(initFactory)
            {
                Scope        = PowerBIUserScope.Organization,
                DatasetId    = datasetId,
                ParameterSet = "List",
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            initFactory.AssertExpectedUnitTestResults(expectedDatasources);
        }
Beispiel #8
0
        public void RestorePowerBIWorkspaceOrganizationScope_IdParameterSet()
        {
            // Arrange
            var workspaceId    = Guid.NewGuid();
            var restoreRequest = new WorkspaceRestoreRequest {
                RestoredName = "Undeleted", AdminUserPrincipalName = "*****@*****.**"
            };
            var expectedResponse = new object();
            var client           = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces
                         .RestoreDeletedWorkspaceAsAdmin(workspaceId, It.Is <WorkspaceRestoreRequest>(r => r.RestoredName == restoreRequest.RestoredName && r.AdminUserPrincipalName == restoreRequest.AdminUserPrincipalName)))
            .Returns(expectedResponse);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new RestorePowerBIWorkspace(initFactory)
            {
                Scope                  = PowerBIUserScope.Organization,
                Id                     = workspaceId,
                RestoredName           = restoreRequest.RestoredName,
                AdminUserPrincipalName = restoreRequest.AdminUserPrincipalName,
                ParameterSet           = "Id",
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory);
        }
Beispiel #9
0
        public void RestorePowerBIWorkspaceIndividualScope()
        {
            // Arrange
            var client      = new Mock <IPowerBIApiClient>();
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new RestorePowerBIWorkspace(initFactory)
            {
                Scope = PowerBIUserScope.Individual,
                Id    = Guid.NewGuid(),
                AdminUserPrincipalName = "*****@*****.**",
            };

            try
            {
                // Act
                cmdlet.InvokePowerBICmdlet();

                Assert.Fail("Should not have reached this point");
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                // Assert
                Assert.AreEqual(ex.InnerException.GetType(), typeof(NotImplementedException));
            }
        }
Beispiel #10
0
        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());
        }
Beispiel #11
0
        public void GetOnPremisesDataGatewayTenantPolicyReturnsExpectedResults()
        {
            // Arrange
            var tenantId         = Guid.NewGuid().ToString();
            var expectedResponse = new GatewayTenant
            {
                TenantObjectId = tenantId,
                Policy         = TenantPolicy.None
            };

            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Gateways
                         .GetTenantPolicy())
            .ReturnsAsync(expectedResponse);

            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetOnPremisesDataGatewayTenantPolicy(initFactory);

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory);
        }
        public void SetPowerBIWorkspaceOrganizationScope_CapacityParameterSet()
        {
            // Arrange
            var workspaceId  = Guid.NewGuid();
            var capacityGuid = Guid.NewGuid();

            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces
                         .MigrateWorkspaceCapacity(workspaceId, capacityGuid));
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new SetPowerBIWorkspace(initFactory)
            {
                Scope        = PowerBIUserScope.Organization,
                ParameterSet = "Capacity",
                Id           = workspaceId,
                CapacityId   = capacityGuid,
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            TestUtilities.AssertExpectedUnitTestResults(null, client, initFactory);
        }
        public void GetPowerBIDataflowOrganizationScope_ListParameterSet()
        {
            // Arrange
            var expectedDataflows = new List <Dataflow> {
                new Dataflow {
                    Id = Guid.NewGuid(), Name = "TestDataflow1"
                }, new Dataflow {
                    Id = Guid.NewGuid(), Name = "TestDataflow2"
                }
            };

            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Dataflows.GetDataflowsAsAdmin(null, null, null)).Returns(expectedDataflows);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIDataflow(initFactory)
            {
                Scope        = PowerBIUserScope.Organization,
                ParameterSet = "List",
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            initFactory.AssertExpectedUnitTestResults(expectedDataflows);
        }
        public void GetPowerBIDataflowIndividualScope_ListParameterSet()
        {
            // Arrange
            var expectedDataflows = new List <Dataflow> {
                new Dataflow {
                    Id = Guid.NewGuid(), Name = "TestDataflow1"
                }, new Dataflow {
                    Id = Guid.NewGuid(), Name = "TestDataflow2"
                }
            };
            var workspaceId = Guid.NewGuid();

            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Dataflows.GetDataflows(workspaceId)).Returns(expectedDataflows);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIDataflow(initFactory)
            {
                Scope        = PowerBIUserScope.Individual,
                ParameterSet = "List",
                WorkspaceId  = workspaceId
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            initFactory.AssertExpectedUnitTestResults(expectedDataflows);
        }
Beispiel #15
0
        public void GetWorkspacesOrganizationScopeSupportsName()
        {
            // Arrange
            var name               = "Test";
            var filter             = $"tolower(name) eq '{name.ToLower()}'";
            var expectedWorkspaces = new List <Workspace> {
                new Workspace {
                    Id = Guid.NewGuid(), Name = name
                }
            };
            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", filter, It.IsAny <int>(), null)).Returns(expectedWorkspaces);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIWorkspace(initFactory)
            {
                Scope        = PowerBIUserScope.Organization,
                Name         = name,
                ParameterSet = "Name",
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            AssertExpectedUnitTestResults(expectedWorkspaces, initFactory);
        }
Beispiel #16
0
        public void SetPowerBIWorkspaceOrganizationScope_WorkspaceParameterSet()
        {
            // Arrange
            var workspace = new Workspace {
                Id = Guid.NewGuid(), Name = "UpdatedName", Description = "UpdatedDescription"
            };
            var expectedResponse = new object();
            var client           = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces
                         .UpdateWorkspaceAsAdmin(workspace.Id, It.Is <Workspace>(w => w.Name == workspace.Name && w.Description == workspace.Description)))
            .Returns(expectedResponse);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new SetPowerBIWorkspace(initFactory)
            {
                Scope        = PowerBIUserScope.Organization,
                Workspace    = workspace,
                ParameterSet = "Workspace",
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory);
        }
Beispiel #17
0
        public void GetWorkspacesOrganizationScopeSupportsUser()
        {
            // Arrange
            var user               = "******";
            var filter             = $"users/any(u: tolower(u/emailAddress) eq '{user.ToLower()}')";
            var expectedWorkspaces = new List <Workspace> {
                new Workspace {
                    Id = Guid.NewGuid(), Name = "TestWorkspace"
                }
            };
            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", filter, It.IsAny <int>(), null)).Returns(expectedWorkspaces);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIWorkspace(initFactory)
            {
                Scope = PowerBIUserScope.Organization,
                User  = user,
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            AssertExpectedUnitTestResults(expectedWorkspaces, initFactory);
        }
Beispiel #18
0
        public void GetWorkspacesOrganizationScopeSupportsOrphaned()
        {
            // Arrange
            var filter             = $"(state ne '{WorkspaceState.Deleted}') and ((not users/any()) or (not users/any(u: u/groupUserAccessRight eq Microsoft.PowerBI.ServiceContracts.Api.GroupUserAccessRight'Admin')))";
            var expectedWorkspaces = new List <Workspace> {
                new Workspace {
                    Id = Guid.NewGuid(), Name = "TestWorkspace"
                }
            };
            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", filter, It.IsAny <int>(), null)).Returns(expectedWorkspaces);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIWorkspace(initFactory)
            {
                Scope    = PowerBIUserScope.Organization,
                Orphaned = true,
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            AssertExpectedUnitTestResults(expectedWorkspaces, initFactory);
        }
Beispiel #19
0
        public void RemoveOnPremisesDataGatewayClusterReturnsExpectedResults()
        {
            // Arrange
            var expectedResponse  = new HttpResponseMessage();
            var gatewayClusterId  = Guid.NewGuid();
            var principalObjectId = Guid.NewGuid();

            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Gateways
                         .DeleteUserOnGatewayCluster(gatewayClusterId, principalObjectId, true))
            .ReturnsAsync(expectedResponse);

            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new RemoveOnPremisesDataGatewayClusterUser(initFactory)
            {
                GatewayClusterId  = gatewayClusterId,
                PrincipalObjectId = principalObjectId
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory);
        }
Beispiel #20
0
        public void GetWorkspacesIndividualScopeSupportsId()
        {
            // Arrange
            var id                 = Guid.NewGuid();
            var filter             = $"tolower(id) eq '{id}'";
            var expectedWorkspaces = new List <Workspace> {
                new Workspace {
                    Id = Guid.NewGuid(), Name = "TestWorkspace"
                }
            };
            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces.GetWorkspaces(filter, It.IsAny <int>(), null)).Returns(expectedWorkspaces);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIWorkspace(initFactory)
            {
                Scope        = PowerBIUserScope.Individual,
                Id           = id,
                ParameterSet = "Id",
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            AssertExpectedUnitTestResults(expectedWorkspaces, initFactory);
        }
        public void GetPowerBIDatasourceIndividualScope_ObjectAndListParameterSet()
        {
            // Arrange
            var testDataset = new Dataset {
                Id = Guid.NewGuid(), Name = "TestDataset"
            };
            var expectedDatasources = new List <Datasource> {
                new Datasource {
                    DatasourceId = Guid.NewGuid().ToString(), Name = "TestDatasource", GatewayId = Guid.NewGuid().ToString()
                }
            };
            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Datasets.GetDatasources(testDataset.Id, null)).Returns(expectedDatasources);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIDatasource(initFactory)
            {
                Scope        = PowerBIUserScope.Individual,
                Dataset      = testDataset,
                ParameterSet = "ObjectAndList",
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            initFactory.AssertExpectedUnitTestResults(expectedDatasources);
        }
Beispiel #22
0
        public void GetWorkspacesIndividualScopeDoesNotSupportUser()
        {
            // Arrange
            var user               = "******";
            var filter             = $"users/any(u: tolower(u/emailAddress) eq '{user.ToLower()}')";
            var expectedWorkspaces = new List <Workspace> {
                new Workspace {
                    Id = Guid.NewGuid(), Name = "TestWorkspace"
                }
            };
            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", filter, null, null)).Returns(expectedWorkspaces);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIWorkspace(initFactory)
            {
                Scope = PowerBIUserScope.Individual,
                User  = user,
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            AssertGetWorkspacesNeverCalled(client, initFactory);
        }
Beispiel #23
0
        public void GetPowerBIActivityEventsWithInvalidEndDateTime()
        {
            // Arrange
            var activityEventResponse = new ActivityEventResponse
            {
                ActivityEventEntities = new List <object>
                {
                    new object()
                },
                ContinuationToken = "next-page"
            };

            string invalidEndDateTime = "Some-invalid-endDateTime";
            var    client             = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Admin.GetPowerBIActivityEvents($"'{StartDateTime}'", $"'{invalidEndDateTime}'", null, null)).Returns(activityEventResponse);

            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIActivityEvent(initFactory)
            {
                StartDateTime = StartDateTime,
                EndDateTime   = invalidEndDateTime,
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            AssertGetActivityEventsNeverCalled(client, initFactory);
        }
Beispiel #24
0
        public void GetWorkspacesAllDeleted()
        {
            // Arrange
            var expectedWorkspace = new Workspace {
                Id = Guid.NewGuid(), Name = "TestDeletedWorkspace", State = WorkspaceState.Deleted
            };
            var allWorkspaces = new List <Workspace> {
                new Workspace {
                    Id = Guid.NewGuid(), Name = "TestWorkspace", State = WorkspaceState.Active
                }, expectedWorkspace
            };

            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", null, It.IsAny <int>(), It.IsAny <int>())).Returns(allWorkspaces);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIWorkspace(initFactory)
            {
                Scope   = PowerBIUserScope.Organization,
                All     = true,
                Deleted = true
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            AssertExpectedUnitTestResults(new List <Workspace> {
                expectedWorkspace
            }, initFactory);
        }
Beispiel #25
0
        public void GetReportsIndividualScope()
        {
            // Arrange
            var expectedReports = new List <Report> {
                new Report {
                    Id = Guid.NewGuid()
                }
            };
            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Reports.GetReports()).Returns(expectedReports);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIReport(initFactory);

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            Assert.IsFalse(initFactory.Logger.ErrorRecords.Any());
            var results = initFactory.Logger.Output.ToList();

            Assert.AreEqual(expectedReports.Count, results.Count());
            var reports = results.Cast <Report>().ToList();

            CollectionAssert.AreEqual(expectedReports, reports);
        }
Beispiel #26
0
        public void GetWorkspacesAllParameterLoopTest()
        {
            // Arrange
            var expectedWorkspaces = new List <Workspace>();

            for (int i = 1; i <= 10500; i++)
            {
                expectedWorkspaces.Add(new Workspace {
                    Id = Guid.NewGuid(), Name = "TestWorkspace_" + i
                });
            }

            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", It.IsAny <string>(), 5000, 0)).Returns(expectedWorkspaces.Take(5000));
            client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", It.IsAny <string>(), 5000, 5000)).Returns(expectedWorkspaces.GetRange(5000, 5000));
            client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", It.IsAny <string>(), 5000, 10000)).Returns(expectedWorkspaces.Skip(10000));
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIWorkspace(initFactory)
            {
                All   = true,
                Scope = PowerBIUserScope.Organization,
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            client.Verify(m => m.Workspaces.GetWorkspacesAsAdmin("users", It.IsAny <string>(), It.IsAny <int>(), It.IsAny <int>()), Times.Exactly(3));
            AssertExpectedUnitTestResults(expectedWorkspaces, initFactory);
        }
Beispiel #27
0
        public void AddPowerBIWorkspaceUser_PrincipalTypeGroup_WithId()
        {
            // Arrange
            var workspaceId = Guid.NewGuid();
            var groupId     = Guid.NewGuid();
            var user        = new WorkspaceUser {
                Identifier = groupId.ToString(), AccessRight = WorkspaceUserAccessRight.Viewer.ToString(), PrincipalType = WorkspaceUserPrincipalType.Group
            };
            var expectedResponse = new object();
            var client           = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces
                         .AddWorkspaceUser(workspaceId, It.Is <WorkspaceUser>(u => u.Identifier == user.Identifier && u.AccessRight == user.AccessRight && u.PrincipalType == user.PrincipalType)))
            .Returns(expectedResponse);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new AddPowerBIWorkspaceUser(initFactory)
            {
                Id            = workspaceId,
                Identifier    = user.Identifier,
                AccessRight   = WorkspaceUserAccessRight.Viewer,
                PrincipalType = WorkspaceUserPrincipalType.Group,
                ParameterSet  = "PrincipalTypeWithId",
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory);
        }
Beispiel #28
0
        public void GetWorkspacesOrganizationScopeSupportsFilterTopSkip()
        {
            // Arrange
            var filter             = "name eq 'n/a'";
            var first              = 2;
            var skip               = 5;
            var expectedWorkspaces = new List <Workspace> {
                new Workspace {
                    Id = Guid.NewGuid(), Name = "TestWorkspace"
                }
            };
            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces.GetWorkspacesAsAdmin("users", filter, first, skip)).Returns(expectedWorkspaces);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIWorkspace(initFactory)
            {
                Scope  = PowerBIUserScope.Organization,
                Filter = filter,
                First  = first,
                Skip   = skip,
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            AssertExpectedUnitTestResults(expectedWorkspaces, initFactory);
        }
Beispiel #29
0
        public void GetOnPremisesDataGatewayInstallerReturnsExpectedResults()
        {
            // Arrange
            var principalObjectId    = Guid.NewGuid().ToString();
            var gatewayTypeParameter = GatewayType.Personal;
            var expectedResponse     = new InstallerPrincipal {
                PrincipalObjectId = principalObjectId,
                GatewayType       = gatewayTypeParameter.ToString()
            };


            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Gateways
                         .GetInstallerPrincipals(gatewayTypeParameter))
            .ReturnsAsync(new[] { expectedResponse });

            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetOnPremisesDataGatewayInstaller(initFactory)
            {
                GatewayTypeParameter = gatewayTypeParameter
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory);
        }
        public void RemovePowerBIWorkspaceUserIndividualScope_IdParameterSet()
        {
            // Arrange
            var workspaceId       = Guid.NewGuid();
            var userPrincipalName = "*****@*****.**";
            var expectedResponse  = new object();
            var client            = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces
                         .RemoveWorkspaceUser(workspaceId, userPrincipalName))
            .Returns(expectedResponse);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new RemovePowerBIWorkspaceUser(initFactory)
            {
                Scope             = PowerBIUserScope.Individual,
                Id                = workspaceId,
                UserPrincipalName = userPrincipalName,
                ParameterSet      = "Id",
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            TestUtilities.AssertExpectedUnitTestResults(expectedResponse, client, initFactory);
        }