Esempio n. 1
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);
        }
Esempio n. 2
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);
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
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);
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }
Esempio n. 8
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);
        }
Esempio n. 9
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);
        }
        public void GetWorkspacesOrganizationScopeSupportsId()
        {
            // Arrange
            var id                 = Guid.NewGuid();
            var filter             = $"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.GetWorkspacesAsAdmin("users", filter, null, null)).Returns(expectedWorkspaces);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIWorkspace(initFactory)
            {
                Scope        = PowerBIUserScope.Organization,
                Id           = id,
                ParameterSet = "Id",
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            AssertExpectedUnitTestResults(expectedWorkspaces, initFactory);
        }
        public void GetWorkspacesIndividualScope_Throttled()
        {
            // Arrange
            var clientHandler = new FakeHttpClientHandler(new System.Net.Http.HttpResponseMessage((System.Net.HttpStatusCode) 429));
            var initFactory   = new TestPowerBICmdletInitFactory(clientHandler);
            var cmdlet        = new GetPowerBIWorkspace(initFactory);

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            Assert.Fail("Should not have reached this point");
        }
Esempio n. 12
0
        public void GetWorkspacesAllOrphanedWithGroup()
        {
            // Arrange
            var user1 = new WorkspaceUser {
                UserPrincipalName = "*****@*****.**", AccessRight = WorkspaceUserAccessRight.Member.ToString()
            };
            var user2 = new WorkspaceUser {
                UserPrincipalName = "*****@*****.**", AccessRight = WorkspaceUserAccessRight.Contributor.ToString()
            };
            var expectedOrphanedWorkspaceOne = new Workspace {
                Id = Guid.NewGuid(), Name = "TestOrphanedWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active, Users = new List <WorkspaceUser> {
                    user1, user2
                }
            };
            var expectedOrphanedWorkspaceTwo = new Workspace {
                Id = Guid.NewGuid(), Name = "TestDeletedWorkspace", Type = WorkspaceType.Group, State = WorkspaceState.Active, Users = new List <WorkspaceUser> {
                    user1
                }
            };

            var user = new WorkspaceUser {
                UserPrincipalName = "*****@*****.**", AccessRight = WorkspaceUserAccessRight.Admin.ToString()
            };
            var allWorkspaces = new List <Workspace> {
                new Workspace {
                    Id = Guid.NewGuid(), Name = "TestWorkspace", Type = WorkspaceType.Workspace, State = WorkspaceState.Active, Users = new List <WorkspaceUser> {
                        user
                    }
                }, expectedOrphanedWorkspaceOne, expectedOrphanedWorkspaceTwo
            };

            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,
                Orphaned = true
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            AssertExpectedUnitTestResults(new List <Workspace> {
                expectedOrphanedWorkspaceOne
            }, initFactory);
        }
Esempio n. 13
0
        public void GetWorkspacesIndividualScopeDoesNotSupportOrphaned()
        {
            // Arrange
            var client      = new Mock <IPowerBIApiClient>();
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIWorkspace(initFactory)
            {
                Scope    = PowerBIUserScope.Individual,
                Orphaned = true,
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            AssertGetWorkspacesNeverCalled(client, initFactory);
        }
        public void GetWorkspacesIndividualScope()
        {
            // Arrange
            var expectedWorkspaces = new List <Workspace> {
                new Workspace {
                    Id = Guid.NewGuid(), Name = "TestWorkspace"
                }
            };
            var client = new Mock <IPowerBIApiClient>();

            client.Setup(x => x.Workspaces.GetWorkspaces(null, null, null)).Returns(expectedWorkspaces);
            var initFactory = new TestPowerBICmdletInitFactory(client.Object);
            var cmdlet      = new GetPowerBIWorkspace(initFactory)
            {
                Scope = PowerBIUserScope.Individual,
            };

            // Act
            cmdlet.InvokePowerBICmdlet();

            // Assert
            AssertExpectedUnitTestResults(expectedWorkspaces, initFactory);
        }