public void SilentlyRemoveNonExistentAlias()
        {
            string id = null;
            string dn = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";
            User   e  = new User
            {
                PrimaryEmail = dn,
                Password     = Guid.NewGuid().ToString(),
                Name         = new UserName
                {
                    GivenName  = "gn",
                    FamilyName = "sn"
                }
            };

            e  = UnitTestControl.TestParameters.UsersService.Add(e);
            id = e.Id;

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

            UnitTestControl.TestParameters.UsersService.AddAlias(id, alias1);
            UnitTestControl.TestParameters.UsersService.AddAlias(id, alias2);

            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectModificationType = ObjectModificationType.Update;
            cs.DN         = dn;
            cs.ObjectType = SchemaConstants.User;
            cs.AnchorAttributes.Add(AnchorAttribute.Create("id", id));

            cs.AttributeChanges.Add(AttributeChange.CreateAttributeUpdate("aliases", new List <ValueChange>
            {
                new ValueChange($"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}", ValueModificationType.Delete)
            }));

            try
            {
                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(UnitTestControl.PostGoogleOperationSleepInterval);

                e = UnitTestControl.TestParameters.UsersService.Get(id);

                CollectionAssert.AreEquivalent(new string[] { alias1, alias2 }, e.Aliases);
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.UsersService.Delete(id);
                }
            }
        }
        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);
            }
        }
Exemple #3
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 Delete()
        {
            string id = null;

            try
            {
                string dn = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";
                User   e  = new User
                {
                    PrimaryEmail = dn,
                    Password     = Guid.NewGuid().ToString(),
                    Name         =
                    {
                        GivenName  = "test",
                        FamilyName = "test"
                    }
                };

                e  = UnitTestControl.TestParameters.UsersService.Add(e);
                id = e.Id;

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

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

                try
                {
                    System.Threading.Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval);
                    e = UnitTestControl.TestParameters.UsersService.Get(id);
                    Assert.Fail("The object did not get deleted");
                }
                catch (GoogleApiException ex)
                {
                    if (ex.HttpStatusCode == HttpStatusCode.NotFound)
                    {
                        id = null;
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.UsersService.Delete(id);
                }
            }
        }
Exemple #5
0
        public void UpdateBuildingClearValues()
        {
            Building building = new Building();

            building.BuildingId   = "test-building";
            building.BuildingName = "My building";
            building.Description  = "some description";
            building.FloorNames   = new List <string>()
            {
                "B1", "B2", "G"
            };
            building.Coordinates = new BuildingCoordinates()
            {
                Latitude = -66, Longitude = 44
            };


            UnitTestControl.TestParameters.ResourcesService.AddBuilding(UnitTestControl.TestParameters.CustomerID, building);

            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectModificationType = ObjectModificationType.Update;
            cs.DN         = $"{building.BuildingId}{ApiInterfaceBuilding.DNSuffix}";
            cs.ObjectType = SchemaConstants.Building;
            cs.AnchorAttributes.Add(AnchorAttribute.Create("id", building.BuildingId));

            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("description"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("coordinates_latitude"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("coordinates_longitude"));

            string id = building.BuildingId;

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

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

                Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval);

                Building c = UnitTestControl.TestParameters.ResourcesService.GetBuilding(UnitTestControl.TestParameters.CustomerID, id);
                Assert.AreEqual("test-building", c.BuildingId);
                Assert.IsTrue(string.IsNullOrEmpty(c.Description));
                Assert.IsNull(c.Coordinates?.Longitude);
                Assert.IsNull(c.Coordinates?.Latitude);
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.ResourcesService.DeleteBuilding(UnitTestControl.TestParameters.CustomerID, id);
                }
            }
        }
Exemple #6
0
        public void CreateCalendar()
        {
            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectModificationType = ObjectModificationType.Add;
            cs.DN         = Guid.NewGuid().ToString();
            cs.ObjectType = SchemaConstants.Calendar;

            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("name", "test-name"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("buildingId", "testbuilding1"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("capacity", 33L));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("floorName", "G"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("floorSection", "33B"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("resourceCategory", "CONFERENCE_ROOM"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("resourceDescription", "internal description"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("userVisibleDescription", "user description"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("features", new List <object> {
                "Test1", "Test2"
            }));

            string id = null;

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

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

                id = result.AnchorAttributes["id"].GetValueAdd <string>();

                Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval);

                CalendarResource c = UnitTestControl.TestParameters.ResourcesService.GetCalendar(UnitTestControl.TestParameters.CustomerID, id);
                Assert.AreEqual("test-name", c.ResourceName);
                Assert.IsNotNull(c.ResourceEmail);
                Assert.AreEqual("testbuilding1", c.BuildingId);
                Assert.AreEqual(33, c.Capacity);
                Assert.AreEqual("G", c.FloorName);
                Assert.AreEqual("33B", c.FloorSection);
                Assert.AreEqual("CONFERENCE_ROOM", c.ResourceCategory);
                Assert.AreEqual("internal description", c.ResourceDescription);
                Assert.AreEqual("user description", c.UserVisibleDescription);
                CollectionAssert.AreEquivalent(new string[] { "Test1", "Test2" }, ApiInterfaceCalendar.GetFeatureNames(c).ToList());
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.ResourcesService.DeleteCalendar(UnitTestControl.TestParameters.CustomerID, id);
                }
            }
        }
        public void Rename()
        {
            string id = null;

            try
            {
                string dn = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";
                User   e  = new User
                {
                    PrimaryEmail = dn,
                    Password     = Guid.NewGuid().ToString(),
                    Name         =
                    {
                        GivenName  = "test",
                        FamilyName = "test"
                    }
                };

                e  = UnitTestControl.TestParameters.UsersService.Add(e);
                id = e.Id;
                System.Threading.Thread.Sleep(2000);

                CSEntryChange cs = CSEntryChange.Create();
                cs.ObjectModificationType = ObjectModificationType.Update;
                cs.DN         = dn;
                cs.ObjectType = SchemaConstants.User;

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

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

                cs.AnchorAttributes.Add(AnchorAttribute.Create("id", id));
                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(2000);
                e = UnitTestControl.TestParameters.UsersService.Get(id);
                Assert.AreEqual(newDN, e.PrimaryEmail);
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.UsersService.Delete(id);
                }
            }
        }
Exemple #8
0
        public void ContactDelete()
        {
            string id = null;

            try
            {
                string       dn = Guid.NewGuid().ToString();
                ContactEntry e  = new ContactEntry
                {
                    BillingInformation = "test"
                };

                e.ExtendedProperties.Add(new ExtendedProperty(dn, ApiInterfaceContact.DNAttributeName));

                e  = UnitTestControl.TestParameters.ContactsService.Add(e, UnitTestControl.TestParameters.Domain);
                id = e.SelfUri.Content;

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

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

                try
                {
                    System.Threading.Thread.Sleep(5000);
                    e = UnitTestControl.TestParameters.ContactsService.GetContact(id);
                    Assert.Fail("The object did not get deleted");
                }
                catch (GDataRequestException ex)
                {
                    if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound)
                    {
                        id = null;
                    }
                    else
                    {
                        throw;
                    }
                }
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.ContactsService.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);
            }
        }
Exemple #10
0
        public void ContactRename()
        {
            string id = null;

            try
            {
                string       dn = Guid.NewGuid().ToString();
                ContactEntry e  = new ContactEntry();

                e.Emails.Add(new EMail()
                {
                    Address = "*****@*****.**", Label = "work"
                });

                e.ExtendedProperties.Add(new ExtendedProperty(dn, ApiInterfaceContact.DNAttributeName));

                e  = UnitTestControl.TestParameters.ContactsService.Add(e, UnitTestControl.TestParameters.Domain);
                id = e.SelfUri.Content;

                CSEntryChange cs = CSEntryChange.Create();
                cs.ObjectModificationType = ObjectModificationType.Update;
                cs.DN         = dn;
                cs.ObjectType = SchemaConstants.Contact;

                string newDN = Guid.NewGuid().ToString();

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

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

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

                System.Threading.Thread.Sleep(5000);
                e = UnitTestControl.TestParameters.ContactsService.GetContact(id);
                Assert.AreEqual(newDN, e.ExtendedProperties.Single(t => t.Name == ApiInterfaceContact.DNAttributeName).Value);
                var x = CSEntryChangeQueue.Take();
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.ContactsService.Delete(id);
                }
            }
        }
        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);
            }
        }
Exemple #12
0
        public void CreateCalendarWithAcls()
        {
            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectModificationType = ObjectModificationType.Add;
            cs.DN         = Guid.NewGuid().ToString();
            cs.ObjectType = SchemaConstants.Calendar;

            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("name", "test-name"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("buildingId", "testbuilding1"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("capacity", 33L));

            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("owner", new List <object> {
                this.CreateAddress("owner1"), this.CreateAddress("owner2")
            }));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("reader", this.CreateAddress("reader")));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("writer", this.CreateAddress("writer")));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("freeBusyReader", this.CreateAddress("freebusyreader")));

            string id = null;

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

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

                id = result.AnchorAttributes["id"].GetValueAdd <string>();

                Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval);

                CalendarResource c = UnitTestControl.TestParameters.ResourcesService.GetCalendar(UnitTestControl.TestParameters.CustomerID, id);

                List <AclRule> acls = UnitTestControl.TestParameters.ResourcesService.GetCalendarAclRules(UnitTestControl.TestParameters.CustomerID, c.ResourceEmail).ToList();

                Assert.IsNotNull(acls.FirstOrDefault(t => t.Role == "owner" && t.Scope.Value == this.CreateAddress("owner1")));
                Assert.IsNotNull(acls.FirstOrDefault(t => t.Role == "owner" && t.Scope.Value == this.CreateAddress("owner2")));
                Assert.IsNotNull(acls.FirstOrDefault(t => t.Role == "reader" && t.Scope.Value == this.CreateAddress("reader")));
                Assert.IsNotNull(acls.FirstOrDefault(t => t.Role == "writer" && t.Scope.Value == this.CreateAddress("writer")));
                Assert.IsNotNull(acls.FirstOrDefault(t => t.Role == "freeBusyReader" && t.Scope.Value == this.CreateAddress("freebusyreader")));
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.ResourcesService.DeleteCalendar(UnitTestControl.TestParameters.CustomerID, id);
                }
            }
        }
Exemple #13
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 MakeAdmin()
        {
            string id = null;
            string dn = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";
            User   e  = new User
            {
                PrimaryEmail = dn,
                Password     = Guid.NewGuid().ToString(),
                Name         = new UserName
                {
                    GivenName  = "gn",
                    FamilyName = "sn"
                }
            };

            e  = UnitTestControl.TestParameters.UsersService.Add(e);
            id = e.Id;

            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectModificationType = ObjectModificationType.Update;
            cs.DN         = dn;
            cs.ObjectType = SchemaConstants.User;
            cs.AnchorAttributes.Add(AnchorAttribute.Create("id", id));

            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("isAdmin", true));

            try
            {
                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(UnitTestControl.PostGoogleOperationSleepInterval);

                e = UnitTestControl.TestParameters.UsersService.Get(id);

                Assert.AreEqual(true, e.IsAdmin);
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.UsersService.Delete(id);
                }
            }
        }
Exemple #15
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);
                }
            }
        }
Exemple #16
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);
            }
        }
Exemple #19
0
        public void CreateBuilding()
        {
            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectModificationType = ObjectModificationType.Add;
            cs.DN         = "*****@*****.**";
            cs.ObjectType = SchemaConstants.Building;

            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("buildingName", "My building"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("description", "my description"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("coordinates_latitude", "1"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("coordinates_longitude", "-99"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("floorNames", "B2,B1,G,1,2,3,4,5"));

            string id = null;

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

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

                id = result.AnchorAttributes["id"].GetValueAdd <string>();

                Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval);

                Building c = UnitTestControl.TestParameters.ResourcesService.GetBuilding(UnitTestControl.TestParameters.CustomerID, id);
                Assert.AreEqual("new-building", c.BuildingId);
                Assert.AreEqual("My building", c.BuildingName);
                Assert.AreEqual("my description", c.Description);
                Assert.AreEqual(1D, c.Coordinates?.Latitude);
                Assert.AreEqual(-99D, c.Coordinates?.Longitude);
                CollectionAssert.AreEqual(new string[] { "B2", "B1", "G", "1", "2", "3", "4", "5" }, c.FloorNames.ToArray());
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.ResourcesService.DeleteBuilding(UnitTestControl.TestParameters.CustomerID, id);
                }
            }
        }
        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 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 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 CreateFeature()
        {
            Guid g = Guid.NewGuid();

            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectModificationType = ObjectModificationType.Add;
            cs.DN         = $"my-feature{g:N}{ApiInterfaceFeature.DNSuffix}";
            cs.ObjectType = SchemaConstants.Feature;

            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("name", "My feature 2"));

            string id = null;

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

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

                id = result.AnchorAttributes["id"].GetValueAdd <string>();

                Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval);

                Feature c = UnitTestControl.TestParameters.ResourcesService.GetFeature(UnitTestControl.TestParameters.CustomerID, id);
                Assert.AreEqual($"my-feature{g:N}", c.Name);
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.ResourcesService.DeleteFeature(UnitTestControl.TestParameters.CustomerID, id);
                }
            }
        }
Exemple #24
0
        public void UpdateCalendar()
        {
            CalendarResource calendar = new CalendarResource();

            calendar.ResourceId             = Guid.NewGuid().ToString("n");
            calendar.ResourceName           = "test-name";
            calendar.BuildingId             = "testbuilding2";
            calendar.Capacity               = 9;
            calendar.FloorName              = "G";
            calendar.FloorSection           = "39b";
            calendar.ResourceCategory       = "OTHER";
            calendar.ResourceDescription    = "internal description 1";
            calendar.UserVisibleDescription = "my description 2";
            calendar.FeatureInstances       = new List <FeatureInstance>()
            {
                new FeatureInstance()
                {
                    Feature = new Feature()
                    {
                        Name = "Test1"
                    }
                },
                new FeatureInstance()
                {
                    Feature = new Feature()
                    {
                        Name = "Test2"
                    }
                },
            };

            UnitTestControl.TestParameters.ResourcesService.AddCalendar(UnitTestControl.TestParameters.CustomerID, calendar);

            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectModificationType = ObjectModificationType.Update;
            cs.DN         = "*****@*****.**";
            cs.ObjectType = SchemaConstants.Calendar;
            cs.AnchorAttributes.Add(AnchorAttribute.Create("id", calendar.ResourceId));

            cs.AttributeChanges.Add(AttributeChange.CreateAttributeUpdate("buildingId", new List <ValueChange>()
            {
                ValueChange.CreateValueAdd("testbuilding1")
            }));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeReplace("capacity", 33L));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeReplace("floorName", "G"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeReplace("floorSection", "33B"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeReplace("resourceCategory", "CONFERENCE_ROOM"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeReplace("resourceDescription", "internal description"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeReplace("userVisibleDescription", "user description"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeUpdate("features", new List <ValueChange>()
            {
                ValueChange.CreateValueAdd("Test3"),
                ValueChange.CreateValueDelete("Test1"),
            }));

            string id = calendar.ResourceId;

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

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

                Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval);

                CalendarResource c = UnitTestControl.TestParameters.ResourcesService.GetCalendar(UnitTestControl.TestParameters.CustomerID, id);
                Assert.AreEqual(cs.DN, "*****@*****.**");
                Assert.AreEqual("test-name", c.ResourceName);
                Assert.AreEqual("testbuilding1", c.BuildingId);
                Assert.AreEqual(33, c.Capacity);
                Assert.AreEqual("G", c.FloorName);
                Assert.AreEqual("33B", c.FloorSection);
                Assert.AreEqual("CONFERENCE_ROOM", c.ResourceCategory);
                Assert.AreEqual("internal description", c.ResourceDescription);
                Assert.AreEqual("user description", c.UserVisibleDescription);
                CollectionAssert.AreEquivalent(new string[] { "Test2", "Test3" }, ApiInterfaceCalendar.GetFeatureNames(c).ToList());
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.ResourcesService.DeleteCalendar(UnitTestControl.TestParameters.CustomerID, id);
                }
            }
        }
Exemple #25
0
        public void UpdateCalendarClearValues()
        {
            CalendarResource calendar = new CalendarResource();

            calendar.ResourceId             = Guid.NewGuid().ToString("n");
            calendar.ResourceName           = "test-name";
            calendar.BuildingId             = "testbuilding2";
            calendar.Capacity               = 9;
            calendar.FloorName              = "G";
            calendar.FloorSection           = "39b";
            calendar.ResourceCategory       = "OTHER";
            calendar.ResourceDescription    = "internal description 1";
            calendar.UserVisibleDescription = "my description 2";
            calendar.FeatureInstances       = new List <FeatureInstance>()
            {
                new FeatureInstance()
                {
                    Feature = new Feature()
                    {
                        Name = "Test1"
                    }
                },
                new FeatureInstance()
                {
                    Feature = new Feature()
                    {
                        Name = "Test2"
                    }
                },
            };

            UnitTestControl.TestParameters.ResourcesService.AddCalendar(UnitTestControl.TestParameters.CustomerID, calendar);

            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectModificationType = ObjectModificationType.Update;
            cs.DN         = "*****@*****.**";
            cs.ObjectType = SchemaConstants.Calendar;
            cs.AnchorAttributes.Add(AnchorAttribute.Create("id", calendar.ResourceId));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("buildingId"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("capacity"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("floorName"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("floorSection"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("resourceDescription"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("userVisibleDescription"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("features"));

            string id = calendar.ResourceId;

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

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

                Thread.Sleep(UnitTestControl.PostGoogleOperationSleepInterval);

                CalendarResource c = UnitTestControl.TestParameters.ResourcesService.GetCalendar(UnitTestControl.TestParameters.CustomerID, id);
                Assert.IsNull(c.BuildingId);
                Assert.IsNull(c.Capacity);
                Assert.IsNull(c.FloorName);
                Assert.IsNull(c.FloorSection);
                Assert.IsNull(c.ResourceDescription);
                Assert.IsNull(c.UserVisibleDescription);
                Assert.IsNull(c.FeatureInstances);
            }
            finally
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.ResourcesService.DeleteCalendar(UnitTestControl.TestParameters.CustomerID, id);
                }
            }
        }
        public void Add()
        {
            CSEntryChange cs = CSEntryChange.Create();

            cs.ObjectModificationType = ObjectModificationType.Add;
            cs.DN         = $"{Guid.NewGuid()}@{UnitTestControl.TestParameters.Domain}";
            cs.ObjectType = SchemaConstants.Group;

            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("description", "description"));
            cs.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("name", "name"));

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

            string id = null;

            try
            {
                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}");
                }

                id = result.AnchorAttributes["id"].GetValueAdd <string>();

                Group e = UnitTestControl.TestParameters.GroupsService.Get(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
            {
                if (id != null)
                {
                    UnitTestControl.TestParameters.GroupsService.Delete(id);
                }
            }
        }
        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);
            }
        }
        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);
                }
            }
        }
Exemple #30
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);
            }
        }