public void UpdateDescription()
        {
            Group e = null;

            try
            {
                e = UnitTestControl.CreateGroup();

                CSEntryChange cs = CSEntryChange.Create();
                cs.ObjectModificationType = ObjectModificationType.Update;
                cs.DN         = e.Email;
                cs.ObjectType = SchemaConstants.Group;
                cs.AnchorAttributes.Add(AnchorAttribute.Create("id", e.Id));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("description"));

                CSEntryChangeResult result =
                    ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Group], UnitTestControl.TestParameters);

                if (result.ErrorCode != MAExportError.Success)
                {
                    Assert.Fail($"{result.ErrorName}\n{result.ErrorDetail}");
                }

                e = UnitTestControl.TestParameters.GroupsService.Get(e.Id);
                Assert.AreEqual(cs.DN, e.Email);
                Assert.AreEqual(true, e.AdminCreated);
                Assert.AreEqual(string.Empty, e.Description);
            }
            finally
            {
                UnitTestControl.Cleanup(e);
            }
        }
Esempio n. 2
0
        public void TestExternalManagerIsExternalMember()
        {
            Group e = null;

            try
            {
                e = UnitTestControl.CreateGroup();
                Thread.Sleep(1000);

                string member2 = "*****@*****.**";
                UnitTestControl.TestParameters.GroupsService.MemberFactory.AddMember(e.Email, new Member()
                {
                    Email = member2, 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 == "externalManager");
                AttributeChange member  = changes.First(t => t.Name == "externalMember");

                Assert.AreEqual(manager.ValueChanges.First().Value, member2);
                Assert.AreEqual(member.ValueChanges.First().Value, member2);
            }
            finally
            {
                UnitTestControl.Cleanup(e);
            }
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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 ReplaceMembers()
        {
            Group e       = null;
            Group member1 = null;
            Group member2 = null;
            Group member3 = null;
            Group member4 = null;

            try
            {
                e = UnitTestControl.CreateGroup();

                CSEntryChange cs = CSEntryChange.Create();
                cs.ObjectModificationType = ObjectModificationType.Update;
                cs.DN         = e.Email;
                cs.ObjectType = SchemaConstants.Group;
                cs.AnchorAttributes.Add(AnchorAttribute.Create("id", e.Id));

                member1 = UnitTestControl.CreateGroup();
                member2 = UnitTestControl.CreateGroup();
                member3 = UnitTestControl.CreateGroup();
                member4 = UnitTestControl.CreateGroup();
                UnitTestControl.TestParameters.GroupsService.MemberFactory.AddMember(e.Email, new Member()
                {
                    Email = member1.Email
                });
                UnitTestControl.TestParameters.GroupsService.MemberFactory.AddMember(e.Email, new Member()
                {
                    Email = member2.Email
                });

                Thread.Sleep(1000);

                cs.AttributeChanges.Add(AttributeChange.CreateAttributeReplace("member", new List <object>()
                {
                    member3.Email, member4.Email
                }));

                CSEntryChangeResult result =
                    ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Group], UnitTestControl.TestParameters);

                if (result.ErrorCode != MAExportError.Success)
                {
                    Assert.Fail(result.ErrorName);
                }

                Thread.Sleep(10000);

                CollectionAssert.AreEquivalent(new string[] { member3.Email, member4.Email }, UnitTestControl.TestParameters.GroupsService.MemberFactory.GetMembership(cs.DN).Members.ToArray());
            }
            finally
            {
                UnitTestControl.Cleanup(e, member1, member2, member3, member4);
            }
        }
Esempio n. 6
0
        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 RemoveMembers()
        {
            Group e       = null;
            Group member1 = null;
            Group member2 = null;

            try
            {
                e       = UnitTestControl.CreateGroup();
                member1 = UnitTestControl.CreateGroup();
                member2 = UnitTestControl.CreateGroup();

                UnitTestControl.TestParameters.GroupsService.MemberFactory.AddMember(e.Email, new Member()
                {
                    Email = member1.Email
                });
                UnitTestControl.TestParameters.GroupsService.MemberFactory.AddMember(e.Email, new Member()
                {
                    Email = member2.Email
                });

                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.Id));

                cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("member"));

                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);

                Assert.AreEqual(0, UnitTestControl.TestParameters.GroupsService.MemberFactory.GetMembership(cs.DN).Members.Count);
                Assert.AreEqual(0, UnitTestControl.TestParameters.GroupsService.MemberFactory.GetMembership(cs.DN).ExternalMembers.Count);
                Assert.AreEqual(0, UnitTestControl.TestParameters.GroupsService.MemberFactory.GetMembership(cs.DN).Managers.Count);
                Assert.AreEqual(0, UnitTestControl.TestParameters.GroupsService.MemberFactory.GetMembership(cs.DN).ExternalManagers.Count);
                Assert.AreEqual(0, UnitTestControl.TestParameters.GroupsService.MemberFactory.GetMembership(cs.DN).Owners.Count);
                Assert.AreEqual(0, UnitTestControl.TestParameters.GroupsService.MemberFactory.GetMembership(cs.DN).ExternalOwners.Count);
            }
            finally
            {
                UnitTestControl.Cleanup(e, member1, member2);
            }
        }
Esempio n. 8
0
        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);
                }
            }
        }
Esempio n. 9
0
        public void DowngradeOwnerToManager()
        {
            Group e = null;

            try
            {
                e = UnitTestControl.CreateGroup();

                string member2 = "*****@*****.**";
                Thread.Sleep(1000);

                UnitTestControl.TestParameters.GroupsService.MemberFactory.AddMember(e.Email, member2, "OWNER");

                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.Id));

                cs.AttributeChanges.Add(AttributeChange.CreateAttributeUpdate("externalOwner", new List <ValueChange>()
                {
                    new ValueChange(member2, ValueModificationType.Delete)
                }));

                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.ExternalOwners.Count);
                Assert.AreEqual(0, membership.Owners.Count);
                Assert.AreEqual(0, membership.Managers.Count);
                Assert.AreEqual(0, membership.Members.Count);
                CollectionAssert.AreEquivalent(new string[] { member2 }, membership.ExternalManagers.ToArray());
            }
            finally
            {
                UnitTestControl.Cleanup(e);
            }
        }
        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 ReplaceAliases()
        {
            Group e = null;

            try
            {
                e = UnitTestControl.CreateGroup();

                string alias1 = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";
                string alias2 = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";
                string alias3 = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";
                string alias4 = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";

                UnitTestControl.TestParameters.GroupsService.AddAlias(e.Id, alias1);
                UnitTestControl.TestParameters.GroupsService.AddAlias(e.Id, alias2);

                CSEntryChange cs = CSEntryChange.Create();
                cs.ObjectModificationType = ObjectModificationType.Update;
                cs.DN         = e.Email;
                cs.ObjectType = SchemaConstants.Group;
                cs.AnchorAttributes.Add(AnchorAttribute.Create("id", e.Id));

                cs.AttributeChanges.Add(AttributeChange.CreateAttributeReplace("aliases", new List <object>
                {
                    alias3, alias4
                }));

                CSEntryChangeResult result =
                    ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Group], UnitTestControl.TestParameters);

                if (result.ErrorCode != MAExportError.Success)
                {
                    Assert.Fail(result.ErrorName);
                }

                System.Threading.Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval);

                e = UnitTestControl.TestParameters.GroupsService.Get(e.Id);

                CollectionAssert.AreEquivalent(new string[] { alias3, alias4 }, e.Aliases.ToArray());
            }
            finally
            {
                UnitTestControl.Cleanup(e);
            }
        }
        public void Delete()
        {
            Group e = null;

            try
            {
                e = UnitTestControl.CreateGroup();

                CSEntryChange cs = CSEntryChange.Create();
                cs.ObjectModificationType = ObjectModificationType.Delete;
                cs.DN         = e.Email;
                cs.ObjectType = SchemaConstants.Group;
                cs.AnchorAttributes.Add(AnchorAttribute.Create("id", e.Id));
                CSEntryChangeResult result =
                    ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Group], UnitTestControl.TestParameters);

                if (result.ErrorCode != MAExportError.Success)
                {
                    Assert.Fail(result.ErrorName);
                }

                try
                {
                    System.Threading.Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval);
                    e = UnitTestControl.TestParameters.GroupsService.Get(e.Id);
                    Assert.Fail("The object did not get deleted");
                }
                catch (GoogleApiException ex)
                {
                    if (ex.HttpStatusCode == HttpStatusCode.NotFound)
                    {
                        e = null;
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            finally
            {
                UnitTestControl.Cleanup(e);
            }
        }
        public void DeleteAddMember()
        {
            Group e = null;

            try
            {
                e = UnitTestControl.CreateGroup();

                Thread.Sleep(1000);

                UnitTestControl.TestParameters.GroupsService.MemberFactory.AddMember(e.Id, "*****@*****.**", "MEMBER");
                UnitTestControl.TestParameters.GroupsService.MemberFactory.RemoveMember(e.Id, "*****@*****.**");
                Thread.Sleep(500);

                UnitTestControl.TestParameters.GroupsService.MemberFactory.AddMember(e.Id, "*****@*****.**", "MEMBER");
            }
            finally
            {
                UnitTestControl.Cleanup(e);
            }
        }
        public void Rename()
        {
            Group e = null;

            try
            {
                e = UnitTestControl.CreateGroup();

                CSEntryChange cs = CSEntryChange.Create();
                cs.ObjectModificationType = ObjectModificationType.Update;
                cs.ObjectType             = SchemaConstants.Group;
                cs.DN = e.Email;

                string newDN = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";

                cs.AttributeChanges.Add(AttributeChange.CreateAttributeUpdate("DN", new List <ValueChange>()
                {
                    ValueChange.CreateValueAdd(newDN), ValueChange.CreateValueDelete(e.Email)
                }));

                cs.AnchorAttributes.Add(AnchorAttribute.Create("id", e.Id));
                CSEntryChangeResult result =
                    ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Group], UnitTestControl.TestParameters);

                if (result.ErrorCode != MAExportError.Success)
                {
                    Assert.Fail(result.ErrorName);
                }

                System.Threading.Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval);
                e = UnitTestControl.TestParameters.GroupsService.Get(e.Id);
                Assert.AreEqual(newDN, e.Email);
            }
            finally
            {
                UnitTestControl.Cleanup(e);
            }
        }
        public void UpdateNoneCanPostOn()
        {
            Group e = null;

            try
            {
                e = UnitTestControl.CreateGroup();

                CSEntryChange cs = CSEntryChange.Create();
                cs.ObjectModificationType = ObjectModificationType.Update;
                cs.DN         = e.Email;
                cs.ObjectType = SchemaConstants.Group;
                cs.AnchorAttributes.Add(AnchorAttribute.Create("id", e.Id));

                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("whoCanPostMessage", "NONE_CAN_POST"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("primaryLanguage", "en-GB"));

                CSEntryChangeResult result =
                    ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Group], UnitTestControl.TestParameters);

                if (result.ErrorCode != MAExportError.Success)
                {
                    Assert.Fail($"{result.ErrorName}\n{result.ErrorDetail}");
                }

                e = UnitTestControl.TestParameters.GroupsService.Get(e.Id);
                Assert.AreEqual(cs.DN, e.Email);

                GroupSettings s = UnitTestControl.TestParameters.GroupsService.SettingsFactory.Get(cs.DN);

                Assert.AreEqual(true, s.ArchiveOnly);

                Assert.AreEqual("NONE_CAN_POST", s.WhoCanPostMessage);

                cs = CSEntryChange.Create();
                cs.ObjectModificationType = ObjectModificationType.Update;
                cs.DN         = e.Email;
                cs.ObjectType = SchemaConstants.Group;
                cs.AnchorAttributes.Add(AnchorAttribute.Create("id", e.Id));

                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("whoCanPostMessage", "ALL_IN_DOMAIN_CAN_POST"));

                result =
                    ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Group], UnitTestControl.TestParameters);

                if (result.ErrorCode != MAExportError.Success)
                {
                    Assert.Fail($"{result.ErrorName}\n{result.ErrorDetail}");
                }

                e = UnitTestControl.TestParameters.GroupsService.Get(e.Id);
                Assert.AreEqual(cs.DN, e.Email);

                s = UnitTestControl.TestParameters.GroupsService.SettingsFactory.Get(cs.DN);

                Assert.AreEqual(false, s.ArchiveOnly);

                Assert.AreEqual("ALL_IN_DOMAIN_CAN_POST", s.WhoCanPostMessage);
            }
            finally
            {
                UnitTestControl.Cleanup(e);
            }
        }
Esempio n. 16
0
        public void ChangeRoleForLargeNumberOfMembers()
        {
            return;

            Group e = null;

            try
            {
                e = UnitTestControl.CreateGroup();

                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.Id));

                List <object> addresses = new List <object>();

                for (int i = 0; i < 100; i++)
                {
                    string address = $"user{i}@lithnet.io";
                    addresses.Add(address);
                }

                //addresses.Add("notanaddress");

                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("externalMember", addresses));

                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);

                CollectionAssert.AreEquivalent(addresses.ToArray(), UnitTestControl.TestParameters.GroupsService.MemberFactory.GetMembership(cs.DN).ExternalMembers.ToArray());

                cs = CSEntryChange.Create();
                cs.ObjectModificationType = ObjectModificationType.Update;
                cs.DN         = e.Email;
                cs.ObjectType = SchemaConstants.Group;
                cs.AnchorAttributes.Add(AnchorAttribute.Create("id", e.Id));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("externalManager", addresses));

                result =
                    ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Group], UnitTestControl.TestParameters);

                if (result.ErrorCode != MAExportError.Success)
                {
                    Assert.Fail(result.ErrorName);
                }

                Thread.Sleep(1000);

                CollectionAssert.AreEquivalent(addresses.ToArray(), UnitTestControl.TestParameters.GroupsService.MemberFactory.GetMembership(cs.DN).ExternalManagers.ToArray());
            }
            finally
            {
                UnitTestControl.Cleanup(e);
            }
        }
Esempio n. 17
0
        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 Update()
        {
            Group e = null;

            try
            {
                e = UnitTestControl.CreateGroup();

                CSEntryChange cs = CSEntryChange.Create();
                cs.ObjectModificationType = ObjectModificationType.Update;
                cs.DN         = e.Email;
                cs.ObjectType = SchemaConstants.Group;
                cs.AnchorAttributes.Add(AnchorAttribute.Create("id", e.Id));

                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("name", "name"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("description", "description"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("allowExternalMembers", true));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("allowGoogleCommunication", true));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("allowWebPosting", true));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("archiveOnly", false));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("customReplyTo", "*****@*****.**"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("customFooterText", "custom footer"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("defaultMessageDenyNotificationText", "occupation"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("includeInGlobalAddressList", true));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("isArchived", false));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("includeCustomFooter", true));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("maxMessageBytes", 5000000L));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("membersCanPostAsTheGroup", true));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("messageDisplayFont", "DEFAULT_FONT"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("messageModerationLevel", "MODERATE_NEW_MEMBERS"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("primaryLanguage", "en-GB"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("sendMessageDenyNotification", true));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("showInGroupDirectory", true));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("spamModerationLevel", "SILENTLY_MODERATE"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("whoCanAdd", "ALL_MANAGERS_CAN_ADD"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("whoCanModerateMembers", "OWNERS_ONLY"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("whoCanContactOwner", "ANYONE_CAN_CONTACT"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("whoCanInvite", "NONE_CAN_INVITE"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("whoCanJoin", "CAN_REQUEST_TO_JOIN"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("replyTo", "REPLY_TO_CUSTOM"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("whoCanPostMessage", "ALL_MANAGERS_CAN_POST"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("whoCanViewGroup", "ALL_MANAGERS_CAN_VIEW"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("whoCanViewMembership", "ALL_MEMBERS_CAN_VIEW"));
                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("whoCanLeaveGroup", "ALL_MANAGERS_CAN_LEAVE"));

                string alias1 = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";
                string alias2 = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";

                cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("aliases", new List <object>()
                {
                    alias1, alias2
                }));

                CSEntryChangeResult result =
                    ExportProcessor.PutCSEntryChange(cs, UnitTestControl.Schema.GetSchema().Types[SchemaConstants.Group], UnitTestControl.TestParameters);

                if (result.ErrorCode != MAExportError.Success)
                {
                    Assert.Fail($"{result.ErrorName}\n{result.ErrorDetail}");
                }

                e = UnitTestControl.TestParameters.GroupsService.Get(e.Id);
                Assert.AreEqual(cs.DN, e.Email);

                Assert.AreEqual(true, e.AdminCreated);
                Assert.AreEqual("description", e.Description);
                Assert.AreEqual("name", e.Name);

                GroupSettings s = UnitTestControl.TestParameters.GroupsService.SettingsFactory.Get(cs.DN);
                Assert.AreEqual(true, s.AllowExternalMembers);
                Assert.AreEqual(true, s.AllowGoogleCommunication);
                Assert.AreEqual(true, s.AllowWebPosting);
                Assert.AreEqual(false, s.ArchiveOnly);
                Assert.AreEqual("*****@*****.**", s.CustomReplyTo);
                Assert.AreEqual("custom footer", s.CustomFooterText);
                Assert.AreEqual("occupation", s.DefaultMessageDenyNotificationText);
                Assert.AreEqual(true, s.IncludeInGlobalAddressList);
                Assert.AreEqual(true, s.IncludeCustomFooter);
                Assert.AreEqual(false, s.IsArchived);
                Assert.AreEqual(5000000, s.MaxMessageBytes);
                Assert.AreEqual(true, s.MembersCanPostAsTheGroup);
                Assert.AreEqual("DEFAULT_FONT", s.MessageDisplayFont);
                Assert.AreEqual("MODERATE_NEW_MEMBERS", s.MessageModerationLevel);
                Assert.AreEqual("en-GB", s.PrimaryLanguage);
                Assert.AreEqual(true, s.SendMessageDenyNotification);
                Assert.AreEqual(true, s.ShowInGroupDirectory);
                Assert.AreEqual("SILENTLY_MODERATE", s.SpamModerationLevel);
                Assert.AreEqual(true, s.ShowInGroupDirectory);
                Assert.AreEqual("ALL_MANAGERS_CAN_ADD", s.WhoCanAdd);
                Assert.AreEqual("OWNERS_ONLY", s.WhoCanModerateMembers);
                Assert.AreEqual("ANYONE_CAN_CONTACT", s.WhoCanContactOwner);
                Assert.AreEqual("NONE_CAN_INVITE", s.WhoCanInvite);
                Assert.AreEqual("CAN_REQUEST_TO_JOIN", s.WhoCanJoin);
                Assert.AreEqual("ALL_MANAGERS_CAN_LEAVE", s.WhoCanLeaveGroup);
                Assert.AreEqual("REPLY_TO_CUSTOM", s.ReplyTo);
                Assert.AreEqual("ALL_MANAGERS_CAN_POST", s.WhoCanPostMessage);
                Assert.AreEqual("ALL_MANAGERS_CAN_VIEW", s.WhoCanViewGroup);
                Assert.AreEqual("ALL_MEMBERS_CAN_VIEW", s.WhoCanViewMembership);

                CollectionAssert.AreEquivalent(new string[] { alias1, alias2 }, e.Aliases.ToArray());
            }
            finally
            {
                UnitTestControl.Cleanup(e);
            }
        }
        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>());
            }
        }