public void AddRemoveMemberTest() { using (UndoContext context = UndoContext.Current) { context.Start(); //Arrange var client = new GraphTestBase(); Group group = client.CreateGroup(); User user = client.CreateUser(); //test client.AddMember(group, user); //Verify IList<string> groupIds = client.GetMemberGroups(user); string matched = groupIds.FirstOrDefault(p => p == group.ObjectId); Assert.Equal(matched, group.ObjectId); //Test client.RemoveMember(group, user); //Verify groupIds = client.GetMemberGroups(user); matched = groupIds.FirstOrDefault(p => p == group.ObjectId); Assert.True(string.IsNullOrEmpty(matched)); //Cleanup client.DeleteGroup(group.ObjectId); client.DeleteUser(user.ObjectId); } }
public void CreateDeleteApplicationTest() { using (UndoContext context = UndoContext.Current) { context.Start(); //Arrange var client = new GraphTestBase(); //Test var passwordCredential = client.CreatePasswordCredential(); var keyCredential = client.CreateKeyCredential(); var application = client.CreateApplication(passwordCredential, keyCredential); try { var newPasswordCredential = client.CreatePasswordCredential(); client.UpdateApplication(application.ObjectId, newPasswordCredential); } finally { client.DeleteApplication(application.ObjectId); } //verify the app has been deleted. Assert.Throws(typeof(CloudException), () => { client.GetpplicationByAppObjectId(application.ObjectId); }); } }
public void CreateDeleteServicePrincipalTest() { using (UndoContext context = UndoContext.Current) { context.Start(); //Arrange var client = new GraphTestBase(); ServicePrincipal sp = null; //Test var passwordCredential = client.CreatePasswordCredential(); var application = client.CreateApplication(passwordCredential); try { sp = client.CreateServicePrincipal(application.AppId); client.DeleteServicePrincipal(sp.ObjectId); } finally { client.DeleteApplication(application.ObjectId); } //verify the user has been deleted. Assert.Throws(typeof(CloudException), () => { client.SearchServicePrincipal(sp.ObjectId); }); } }
public void GetUserUsingSignInNameTest() { using (UndoContext context = UndoContext.Current) { //To run this test, you will need to prepare a tenant which contains a MSA based guest user, such as a live id. context.Start(); var graphTestBase = new GraphTestBase(); var client = graphTestBase.GraphClient; // Add this user through management portal before recording mocks string testLiveId = "auxtm596_live.com#EXT#@rbacCliTest.onmicrosoft.com"; var usersByLiveId = client.User.GetByUserPrincipalName(testLiveId); Assert.NotNull(usersByLiveId); Assert.NotNull(usersByLiveId.StatusCode == HttpStatusCode.OK); Assert.NotNull(usersByLiveId.Users); Assert.Equal(1, usersByLiveId.Users.Count()); string testOrgId = "test2@" + graphTestBase.Domain; var usersByOrgId = client.User.GetByUserPrincipalName(testOrgId); Assert.NotNull(usersByOrgId); Assert.NotNull(usersByOrgId.StatusCode == HttpStatusCode.OK); Assert.NotNull(usersByOrgId.Users); Assert.Equal(1, usersByOrgId.Users.Count()); } }
public void GetListApplicationTest() { using (UndoContext context = UndoContext.Current) { context.Start(); //Arrange var client = new GraphTestBase(); //Test var passwordCredential = client.CreatePasswordCredential(); var keyCredential = client.CreateKeyCredential(); var application = client.CreateApplication(passwordCredential, keyCredential); try { // Get Application by applicationObjectId var fetchedApplicationByAppObjectId = client.GetpplicationByAppObjectId(application.ObjectId); Assert.NotNull(fetchedApplicationByAppObjectId); Assert.Equal(application.ObjectId, fetchedApplicationByAppObjectId.ObjectId); //Get Application by applicationId var fetchedApplicationsByAppId = client.ListApplicationsByFilters(new ApplicationFilterParameters { AppId = Guid.Parse(application.AppId) }); Assert.NotNull(fetchedApplicationsByAppId); Assert.Equal(1, fetchedApplicationsByAppId.Count); Assert.Equal(application.AppId, fetchedApplicationsByAppId.First().AppId); // Get Application by identifierUri var fetchedApplicationsByIdentifierUri = client.ListApplicationsByFilters(new ApplicationFilterParameters { IdentifierUri = application.IdentifierUris.First() }); Assert.NotNull(fetchedApplicationsByIdentifierUri); Assert.Equal(1, fetchedApplicationsByIdentifierUri.Count); Assert.True(fetchedApplicationsByIdentifierUri.First().IdentifierUris.Contains(application.IdentifierUris.First())); // Get Application by startswith name var fetchedApplicationsByDisplayNamePrefix = client.ListApplicationsByFilters(new ApplicationFilterParameters { DisplayNameStartsWith = "adApplication" }); Assert.NotNull(fetchedApplicationsByDisplayNamePrefix); Assert.True(fetchedApplicationsByDisplayNamePrefix.Count >= 1); Assert.True(fetchedApplicationsByDisplayNamePrefix.All(a => a.DisplayName.StartsWith("adApplication"))); // Get Application by startswith name var fetchedApplicationsByDisplayNameExact = client.ListApplicationsByFilters(new ApplicationFilterParameters { DisplayNameStartsWith = application.DisplayName }); Assert.NotNull(fetchedApplicationsByDisplayNameExact); Assert.Equal(1, fetchedApplicationsByDisplayNameExact.Count); Assert.True(fetchedApplicationsByDisplayNameExact.First().DisplayName.StartsWith(application.DisplayName)); } finally { client.DeleteApplication(application.ObjectId); } Assert.Throws(typeof(CloudException), () => { client.GetpplicationByAppObjectId(application.ObjectId); }); } }
public void AddRemoveMemberTest() { using (UndoContext context = UndoContext.Current) { context.Start(); //Arrange var client = new GraphTestBase(); Group group = client.CreateGroup(); User user = client.CreateUser(); //test client.AddMember(group, user); //Verify IList <string> groupIds = client.GetMemberGroups(user); string matched = groupIds.FirstOrDefault(p => p == group.ObjectId); Assert.Equal(matched, group.ObjectId); //Test client.RemoveMember(group, user); //Verify groupIds = client.GetMemberGroups(user); matched = groupIds.FirstOrDefault(p => p == group.ObjectId); Assert.True(string.IsNullOrEmpty(matched)); //Cleanup client.DeleteGroup(group.ObjectId); client.DeleteUser(user.ObjectId); } }
public void CreateDeleteGroupTest() { using (UndoContext context = UndoContext.Current) { context.Start(); var client = new GraphTestBase(); //Test Group group = client.CreateGroup(); client.DeleteGroup(group.ObjectId); //verify the group has been deleted. Assert.Throws(typeof(CloudException), () => { client.SearchGroup(group.ObjectId); }); } }
public void CreateDeleteUserTest() { using (UndoContext context = UndoContext.Current) { context.Start(); //Arrange var client = new GraphTestBase(); //Test User user = client.CreateUser(); client.DeleteUser(user.UserPrincipalName); //verify the user has been deleted. Assert.Throws(typeof(CloudException), () => { client.SearchUser(user.UserPrincipalName); }); } }
public void ListPagedUsersTest() { using (UndoContext context = UndoContext.Current) { context.Start(); var graphTestBase = new GraphTestBase(); var client = graphTestBase.GraphClient; List <User> createdUsers = new List <User>(); for (int i = 0; i < PagenatedItemsCount; i++) { createdUsers.Add(graphTestBase.CreateUser()); } try { var firstPage = client.User.List(null, null); Assert.NotNull(firstPage); Assert.NotNull(firstPage.StatusCode == HttpStatusCode.OK); Assert.NotNull(firstPage.Users); Assert.NotNull(firstPage.NextLink); var nextPage = client.User.ListNext(firstPage.NextLink); Assert.NotNull(nextPage.StatusCode == HttpStatusCode.OK); Assert.NotNull(nextPage.Users); Assert.NotEqual(0, nextPage.Users.Count()); foreach (var user in nextPage.Users) { Assert.NotNull(user.ObjectId); Assert.NotNull(user.UserPrincipalName); Assert.NotNull(user.ObjectType); } } finally { foreach (var user in createdUsers) { graphTestBase.DeleteUser(user.UserPrincipalName); } } } }
public void ListPagedGroupsTest() { using (MockContext context = MockContext.Start(this.GetType().FullName)) { var graphTestBase = new GraphTestBase(); var client = GetGraphClient(context); List <ADGroup> createdGroups = new List <ADGroup>(); for (int i = 0; i < PagenatedItemsCount; i++) { createdGroups.Add(graphTestBase.CreateGroup(context)); } try { var firstPage = client.Groups.List(); Assert.NotNull(firstPage); Assert.NotNull(firstPage.NextPageLink); var nextPage = client.Groups.ListNext(firstPage.NextPageLink); Assert.NotNull(nextPage); Assert.NotEmpty(nextPage); foreach (var group in nextPage) { Assert.NotNull(group.ObjectId); Assert.NotNull(group.ObjectType); } } finally { foreach (var group in createdGroups) { graphTestBase.DeleteGroup(context, group.ObjectId); } } } }
public void GetUserUsingSignInNameTest() { using (UndoContext context = UndoContext.Current) { //To run this test, you will need to prepare a tenant which contains a MSA based guest user, such as a live id. context.Start(); var graphTestBase = new GraphTestBase(); var client = graphTestBase.GraphClient; // Add this user through management portal before recording mocks string testLiveId = "*****@*****.**"; var usersByLiveId = client.User.GetBySignInName(testLiveId); Assert.NotNull(usersByLiveId); Assert.NotNull(usersByLiveId.StatusCode == HttpStatusCode.OK); Assert.NotNull(usersByLiveId.Users); Assert.Equal(1, usersByLiveId.Users.Count()); string testOrgId = "test2@" + graphTestBase.Domain; var usersByOrgId = client.User.GetBySignInName(testOrgId); Assert.NotNull(usersByOrgId); Assert.NotNull(usersByOrgId.StatusCode == HttpStatusCode.OK); Assert.NotNull(usersByOrgId.Users); Assert.Equal(1, usersByOrgId.Users.Count()); } }
public void ListPagedGroupsTest() { using (UndoContext context = UndoContext.Current) { context.Start(); var graphTestBase = new GraphTestBase(); var client = graphTestBase.GraphClient; List<Group> createdGroups = new List<Group>(); for(int i=0; i<PagenatedItemsCount; i++) { createdGroups.Add(graphTestBase.CreateGroup()); } try { var firstPage = client.Group.List(null, null); Assert.NotNull(firstPage); Assert.NotNull(firstPage.StatusCode == HttpStatusCode.OK); Assert.NotNull(firstPage.Groups); Assert.NotNull(firstPage.NextLink); var nextPage = client.Group.ListNext(firstPage.NextLink); Assert.NotNull(nextPage.StatusCode == HttpStatusCode.OK); Assert.NotNull(nextPage.Groups); Assert.NotEqual(0, nextPage.Groups.Count()); foreach (var group in nextPage.Groups) { Assert.NotNull(group.ObjectId); Assert.NotNull(group.ObjectType); } } finally { foreach (var group in createdGroups) { graphTestBase.DeleteGroup(group.ObjectId); } } } }