public void TestManagerIsMember() { Group e = null; User user = null; try { e = UnitTestControl.CreateGroup(); Thread.Sleep(1000); user = UserTests.CreateUser(); UnitTestControl.TestParameters.GroupsService.MemberFactory.AddMember(e.Email, new Member() { Email = user.PrimaryEmail, Role = "MANAGER" }); Thread.Sleep(5000); GroupMembership members = UnitTestControl.TestParameters.GroupsService.MemberFactory.GetMembership(e.Email); ApiInterfaceGroupMembership i = new ApiInterfaceGroupMembership(UnitTestControl.TestParameters); IList <AttributeChange> changes = i.GetChanges(e.Email, ObjectModificationType.Add, UnitTestControl.MmsSchema.Types["group"], members); AttributeChange manager = changes.First(t => t.Name == "manager"); AttributeChange member = changes.First(t => t.Name == "member"); Assert.AreEqual(manager.ValueChanges.First().Value, user.PrimaryEmail); Assert.AreEqual(member.ValueChanges.First().Value, user.PrimaryEmail); } finally { UnitTestControl.Cleanup(e, user); } }
public void Delete() { string id = null; User owner = null; try { owner = UserTests.CreateUser(); Course e = new Course { Name = "name", OwnerId = owner.Id }; e = UnitTestControl.TestParameters.ClassroomService.Add(e); id = e.Id; CSEntryChange cs = CSEntryChange.Create(); cs.ObjectModificationType = ObjectModificationType.Delete; cs.DN = id; cs.ObjectType = SchemaConstants.Course; cs.AnchorAttributes.Add(AnchorAttribute.Create("id", id)); CSEntryChangeResult result = ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Course], UnitTestControl.TestParameters); if (result.ErrorCode != MAExportError.Success) { Assert.Fail(result.ErrorName); } try { System.Threading.Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval); e = UnitTestControl.TestParameters.ClassroomService.GetCourse(id); Assert.Fail("The object did not get deleted"); } catch (GoogleApiException ex) { if (ex.HttpStatusCode == HttpStatusCode.NotFound) { id = null; } else { throw; } } } finally { UnitTestControl.Cleanup(owner); if (id != null) { UnitTestControl.TestParameters.ClassroomService.Delete(id); } } }
public void DowngradeManagersToMembers() { Group e = null; User member1 = null; User member2 = null; User member3 = null; User member4 = null; try { e = UnitTestControl.CreateGroup(); member1 = UserTests.CreateUser(); member2 = UserTests.CreateUser(); member3 = UserTests.CreateUser(); member4 = UserTests.CreateUser(); UnitTestControl.TestParameters.GroupsService.MemberFactory.AddMember(e.Email, member1.PrimaryEmail, "MANAGER"); UnitTestControl.TestParameters.GroupsService.MemberFactory.AddMember(e.Email, member2.PrimaryEmail, "MANAGER"); UnitTestControl.TestParameters.GroupsService.MemberFactory.AddMember(e.Email, member3.PrimaryEmail, "MEMBER"); UnitTestControl.TestParameters.GroupsService.MemberFactory.AddMember(e.Email, member4.PrimaryEmail, "MEMBER"); Thread.Sleep(1000); CSEntryChange cs = CSEntryChange.Create(); cs.ObjectModificationType = ObjectModificationType.Update; cs.DN = e.Email; cs.ObjectType = SchemaConstants.Group; cs.AnchorAttributes.Add(AnchorAttribute.Create("id", e.Email)); cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("manager")); CSEntryChangeResult result = ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Group], UnitTestControl.TestParameters); if (result.ErrorCode != MAExportError.Success) { Assert.Fail(result.ErrorName); } Thread.Sleep(1000); GroupMembership membership = UnitTestControl.TestParameters.GroupsService.MemberFactory.GetMembership(cs.DN); Assert.AreEqual(0, membership.ExternalManagers.Count); Assert.AreEqual(0, membership.Managers.Count); Assert.AreEqual(0, membership.ExternalMembers.Count); CollectionAssert.AreEquivalent(new string[] { member1.PrimaryEmail, member2.PrimaryEmail, member3.PrimaryEmail, member4.PrimaryEmail }, membership.Members.ToArray()); } finally { UnitTestControl.Cleanup(e, member1, member2, member3, member4); } }
public void Update() { User owner = null; string id = null; try { owner = UserTests.CreateUser(); Course e = new Course { Name = "name", OwnerId = owner.Id }; e = UnitTestControl.TestParameters.ClassroomService.Add(e); id = e.Id; CSEntryChange cs = CSEntryChange.Create(); cs.ObjectModificationType = ObjectModificationType.Update; cs.DN = id; cs.ObjectType = SchemaConstants.Course; cs.AnchorAttributes.Add(AnchorAttribute.Create("id", id)); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("name", "name2")); CSEntryChangeResult result = ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Course], UnitTestControl.TestParameters); if (result.ErrorCode != MAExportError.Success) { Assert.Fail(result.ErrorName); } System.Threading.Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval); e = UnitTestControl.TestParameters.ClassroomService.GetCourse(id); Assert.AreEqual("name2", e.Name); } finally { UnitTestControl.Cleanup(owner); if (id != null) { UnitTestControl.TestParameters.ClassroomService.Delete(id); } } }
public void AddGroupWithMembers() { Group member1 = null; Group member2 = null; User member3 = null; try { string dn = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}"; CSEntryChange cs = CSEntryChange.Create(); cs.ObjectModificationType = ObjectModificationType.Add; cs.DN = dn; cs.ObjectType = SchemaConstants.Group; cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("name", Guid.NewGuid().ToString())); member1 = UnitTestControl.CreateGroup(); member2 = UnitTestControl.CreateGroup(); member3 = UserTests.CreateUser(); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("member", new List <object>() { member1.Email, member2.Email })); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("owner", new List <object>() { member3.PrimaryEmail })); CSEntryChangeResult result = null; result = ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Group], UnitTestControl.TestParameters); if (result.ErrorCode != MAExportError.Success) { Assert.Fail(result.ErrorName); } Thread.Sleep(5000); CollectionAssert.AreEquivalent(new string[] { member1.Email, member2.Email }, UnitTestControl.TestParameters.GroupsService.MemberFactory.GetMembership(cs.DN).Members.ToArray()); } finally { UnitTestControl.Cleanup(member1, member2, member3); } }
public void TakeAdmin() { User e = UserTests.CreateUser(); try { UnitTestControl.TestParameters.UsersService.MakeAdmin(true, e.Id); CSEntryChange cs = CSEntryChange.Create(); cs.ObjectModificationType = ObjectModificationType.Update; cs.DN = e.PrimaryEmail; cs.ObjectType = SchemaConstants.User; cs.AnchorAttributes.Add(AnchorAttribute.Create("id", e.Id)); cs.AttributeChanges.Add(AttributeChange.CreateAttributeReplace("isAdmin", false)); CSEntryChangeResult result = ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.User], UnitTestControl.TestParameters); if (result.ErrorCode != MAExportError.Success) { Assert.Fail(result.ErrorName); } System.Threading.Thread.Sleep(5000); e = UnitTestControl.TestParameters.UsersService.Get(e.Id); Assert.AreEqual(false, e.IsAdmin); } finally { if (e.Id != null) { UnitTestControl.TestParameters.UsersService.Delete(e.Id); } } }
public void DeleteStringValuesAsAttributeDeleteOnObjectUpdate() { User u = UserTests.CreateUser(); // Create the initial object CSEntryChange cs = CSEntryChange.Create(); cs.ObjectModificationType = ObjectModificationType.Update; cs.DN = u.PrimaryEmail; cs.ObjectType = SchemaConstants.User; cs.AnchorAttributes.Add(AnchorAttribute.Create("id", u.Id)); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd($"{TestSchemaName}_TestSVString", "string1")); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd($"{TestSchemaName}_TestMVString", new List <object> { "test2", "test3" })); try { CSEntryChangeResult result = ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.User], UnitTestControl.TestParameters); if (result.ErrorCode != MAExportError.Success) { Assert.Fail(result.ErrorName); } Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval); User e = UnitTestControl.TestParameters.UsersService.Get(u.Id); Assert.AreEqual(cs.DN, e.PrimaryEmail); Assert.AreEqual("string1", (string)e.CustomSchemas[TestSchemaName]["TestSVString"]); CollectionAssert.AreEquivalent(new List <object> { "test2", "test3" }, GetReturnedValues <string>("TestMVString", e)); // Remove all the values with an 'attribute delete' cs = CSEntryChange.Create(); cs.ObjectModificationType = ObjectModificationType.Update; cs.DN = u.PrimaryEmail; cs.ObjectType = SchemaConstants.User; cs.AnchorAttributes.Add(AnchorAttribute.Create("id", u.Id)); cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete($"{TestSchemaName}_TestSVString")); cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete($"{TestSchemaName}_TestMVString")); result = ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.User], UnitTestControl.TestParameters); if (result.ErrorCode != MAExportError.Success) { Assert.Fail(result.ErrorName); } Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval); e = UnitTestControl.TestParameters.UsersService.Get(u.Id); Assert.AreEqual(cs.DN, e.PrimaryEmail); if (e.CustomSchemas != null && e.CustomSchemas.ContainsKey(TestSchemaName)) { Assert.IsFalse(e.CustomSchemas[TestSchemaName].ContainsKey("TestSVString")); Assert.IsFalse(e.CustomSchemas[TestSchemaName].ContainsKey("TestMVString")); } } finally { if (u?.Id != null) { UnitTestControl.TestParameters.UsersService.Delete(u.Id); } } }
public void AddValuesOnObjectUpdate() { User u = UserTests.CreateUser(); CSEntryChange cs = CSEntryChange.Create(); cs.ObjectModificationType = ObjectModificationType.Update; cs.DN = u.PrimaryEmail; cs.ObjectType = SchemaConstants.User; cs.AnchorAttributes.Add(AnchorAttribute.Create("id", u.Id)); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd($"{TestSchemaName}_TestSVString", "string1")); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd($"{TestSchemaName}_TestSVBool", true)); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd($"{TestSchemaName}_TestSVDate", "2018-01-03")); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd($"{TestSchemaName}_TestSVDouble", "1.9999")); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd($"{TestSchemaName}_TestSVEmail", "*****@*****.**")); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd($"{TestSchemaName}_TestSVInt", 899L)); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd($"{TestSchemaName}_TestSVPhone", "555-1234")); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd($"{TestSchemaName}_TestMVString", new List <object> { "test2", "test3" })); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd($"{TestSchemaName}_TestMVDouble", new List <object> { "2.99999", "3.99999" })); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd($"{TestSchemaName}_TestMVDate", new List <object> { "2018-02-02", "2018-03-03" })); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd($"{TestSchemaName}_TestMVEmail", new List <object> { "*****@*****.**", "*****@*****.**" })); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd($"{TestSchemaName}_TestMVPhone", new List <object> { "555-6789", "555-9512" })); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd($"{TestSchemaName}_TestMVInt", new List <object> { 555L, 444L })); try { CSEntryChangeResult result = ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.User], UnitTestControl.TestParameters); if (result.ErrorCode != MAExportError.Success) { Assert.Fail(result.ErrorName); } Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval); User e = UnitTestControl.TestParameters.UsersService.Get(u.Id); Assert.AreEqual(cs.DN, e.PrimaryEmail); Assert.AreEqual("string1", (string)e.CustomSchemas[TestSchemaName]["TestSVString"]); Assert.AreEqual(true, (bool)e.CustomSchemas[TestSchemaName]["TestSVBool"]); Assert.AreEqual("2018-01-03", (string)e.CustomSchemas[TestSchemaName]["TestSVDate"]); Assert.AreEqual(1.9999D, (double)e.CustomSchemas[TestSchemaName]["TestSVDouble"]); Assert.AreEqual("*****@*****.**", (string)e.CustomSchemas[TestSchemaName]["TestSVEmail"]); Assert.AreEqual("899", e.CustomSchemas[TestSchemaName]["TestSVInt"]); Assert.AreEqual("555-1234", (string)e.CustomSchemas[TestSchemaName]["TestSVPhone"]); CollectionAssert.AreEquivalent(new List <object> { "test2", "test3" }, GetReturnedValues <string>("TestMVString", e)); CollectionAssert.AreEquivalent(new List <object> { "2018-02-02", "2018-03-03" }, GetReturnedValues <string>("TestMVDate", e)); CollectionAssert.AreEquivalent(new List <object> { "*****@*****.**", "*****@*****.**" }, GetReturnedValues <string>("TestMVEmail", e)); CollectionAssert.AreEquivalent(new List <object> { "555-6789", "555-9512" }, GetReturnedValues <string>("TestMVPhone", e)); CollectionAssert.AreEquivalent(new List <object> { "555", "444" }, GetReturnedValues <string>("TestMVInt", e)); CollectionAssert.AreEquivalent(new List <object> { "2.99999", "3.99999" }, GetReturnedValues <string>("TestMVDouble", e)); } finally { if (u?.Id != null) { UnitTestControl.TestParameters.UsersService.Delete(u.Id); } } }
public void Add() { CSEntryChange cs = CSEntryChange.Create(); cs.ObjectModificationType = ObjectModificationType.Add; cs.DN = $"{Guid.NewGuid()}"; cs.ObjectType = SchemaConstants.Course; User t1 = UserTests.CreateUser(); User t2 = UserTests.CreateUser(); User s1 = UserTests.CreateUser(); User s2 = UserTests.CreateUser(); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("name", "name")); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("ownerId", new List <object>() { t1.PrimaryEmail })); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("teachers", new List <object>() { t1.PrimaryEmail, t2.PrimaryEmail })); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("students", new List <object>() { s1.PrimaryEmail, s2.PrimaryEmail })); cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("courseState", "ACTIVE")); string id = null; try { CSEntryChangeResult result = ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Course], UnitTestControl.TestParameters); id = result.AnchorAttributes["id"].GetValueAdd <string>(); if (result.ErrorCode != MAExportError.Success) { Assert.Fail(result.ErrorName); } System.Threading.Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval); Course e = UnitTestControl.TestParameters.ClassroomService.GetCourse(id); Assert.AreEqual("name", e.Name); Assert.AreEqual("ACTIVE", e.CourseState); CollectionAssert.AreEquivalent(new string[] { s1.Id, s2.Id }, UnitTestControl.TestParameters.ClassroomService.StudentFactory.GetCourseStudents(id).GetAllStudents().ToArray()); CollectionAssert.AreEquivalent(new string[] { t1.Id, t2.Id }, UnitTestControl.TestParameters.ClassroomService.TeacherFactory.GetCourseTeachers(id).GetAllTeachers().ToArray()); } finally { UnitTestControl.Cleanup(t1, t2, s1, s2); if (id != null) { UnitTestControl.TestParameters.ClassroomService.Delete(id); } } }
public void TriggerBackOff() { return; List <Group> groups = new List <Group>(); try { List <CSEntryChange> changes = new List <CSEntryChange>(); for (int i = 0; i < 50; i++) { Group e = UnitTestControl.CreateGroup(); groups.Add(e); CSEntryChange cs = GroupMemberTests.CreateCSEntryUpdate(e); List <object> addresses = new List <object>(); for (int j = 0; j < 100; j++) { string address = $"user-{Guid.NewGuid()}@lithnet.io"; addresses.Add(address); } cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("externalMember", addresses)); changes.Add(cs); } int directoryServicePoolSize = 30; int threadCount = 0; Task q = new Task(() => { Parallel.For(0, 1000, u => { User x = UserTests.CreateUser(); Trace.WriteLine($"Created user {x.PrimaryEmail}"); UnitTestControl.TestParameters.UsersService.Delete(x.Id); }); }); q.Start(); ParallelOptions op = new ParallelOptions(); op.MaxDegreeOfParallelism = directoryServicePoolSize; Parallel.ForEach(changes, op, t => { int threadID = Interlocked.Increment(ref threadCount); Trace.WriteLine($"Thread count {threadID}"); try { CSEntryChangeResult result = ExportProcessor.PutCSEntryChange(t, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Group], UnitTestControl.TestParameters); if (result.ErrorCode != MAExportError.Success) { Assert.Fail(result.ErrorName); } } finally { Interlocked.Decrement(ref threadCount); } }); } finally { UnitTestControl.Cleanup(groups.ToArray <object>()); } }