public void TestToCSEntryChangeUpdate() { IAttributeAdapter schemaItem = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "orgUnitPath"); User u = new User { OrgUnitPath = "/Test" }; CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Update; IList <AttributeChange> result = schemaItem.CreateAttributeChanges(x.DN, x.ObjectModificationType, u).ToList(); AttributeChange change = result.FirstOrDefault(t => t.Name == "orgUnitPath"); Assert.IsNotNull(change); Assert.AreEqual("/Test", change.GetValueAdd <string>()); Assert.AreEqual(AttributeModificationType.Replace, change.ModificationType); x.AttributeChanges.Add(change); User ux = new User(); schemaItem.UpdateField(x, ux); Assert.AreEqual("/Test", ux.OrgUnitPath); }
public void TestToCSEntryChangeUpdate() { IAttributeAdapter schemaItem = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "aliases"); UserUpdateTemplate u = new UserUpdateTemplate { Aliases = new List <string>() { "*****@*****.**", "*****@*****.**" } }; CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Update; IList <AttributeChange> result = schemaItem.CreateAttributeChanges(x.DN, x.ObjectModificationType, u).ToList(); AttributeChange change = result.FirstOrDefault(t => t.Name == "aliases"); Assert.IsNotNull(change); CollectionAssert.AreEqual(new string[] { "*****@*****.**", "*****@*****.**" }, change.GetValueAdds <string>().ToArray()); Assert.AreEqual(AttributeModificationType.Replace, change.ModificationType); }
public void TestToCSEntryChangeUpdate() { IAttributeAdapter schemaItem = UnitTestControl.Schema["contact"].GetAdapterForMmsAttribute("externalIds"); ContactEntry e = new ContactEntry(); e.ExternalIds.Add(new ExternalId() { Value = "id", Label = "work" }); CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Update; IList <AttributeChange> result = schemaItem.CreateAttributeChanges(x.DN, x.ObjectModificationType, e).ToList(); AttributeChange change; change = result.FirstOrDefault(t => t.Name == "externalIds_work"); Assert.IsNotNull(change); Assert.AreEqual("id", change.GetValueAdd <string>()); Assert.AreEqual(AttributeModificationType.Replace, change.ModificationType); x.AttributeChanges.Add(change); }
public void TestToCSEntryChangeAdd() { IAttributeAdapter schemaItem = UnitTestControl.Schema["contact"].GetAdapterForMmsAttribute("organizations"); ContactEntry e = new ContactEntry(); e.Organizations.Add(new Organization() { Name = "myorg", Department = "department", JobDescription = "jobdescription", Location = "location", Symbol = "symbol", Title = "title", Rel = "http://schemas.google.com/g/2005#work" }); CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Add; IList <AttributeChange> result = schemaItem.CreateAttributeChanges(x.DN, x.ObjectModificationType, e).ToList(); AttributeChange change; change = result.FirstOrDefault(t => t.Name == "organizations_work_name"); Assert.IsNotNull(change); Assert.AreEqual("myorg", change.GetValueAdd <string>()); x.AttributeChanges.Add(change); change = result.FirstOrDefault(t => t.Name == "organizations_work_department"); Assert.IsNotNull(change); Assert.AreEqual("department", change.GetValueAdd <string>()); x.AttributeChanges.Add(change); change = result.FirstOrDefault(t => t.Name == "organizations_work_jobDescription"); Assert.IsNotNull(change); Assert.AreEqual("jobdescription", change.GetValueAdd <string>()); x.AttributeChanges.Add(change); change = result.FirstOrDefault(t => t.Name == "organizations_work_location"); Assert.IsNotNull(change); Assert.AreEqual("location", change.GetValueAdd <string>()); x.AttributeChanges.Add(change); change = result.FirstOrDefault(t => t.Name == "organizations_work_symbol"); Assert.IsNotNull(change); Assert.AreEqual("symbol", change.GetValueAdd <string>()); x.AttributeChanges.Add(change); change = result.FirstOrDefault(t => t.Name == "organizations_work_title"); Assert.IsNotNull(change); Assert.AreEqual("title", change.GetValueAdd <string>()); x.AttributeChanges.Add(change); }
public IList <AttributeChange> GetChanges(string dn, ObjectModificationType modType, SchemaType type, object source) { List <AttributeChange> attributeChanges = new List <AttributeChange>(); if (!(type.HasAttribute(this.attributeName))) { return(attributeChanges); } IAttributeAdapter typeDef = ManagementAgent.Schema[this.typeName].AttributeAdapters.First(t => t.Api == this.Api); List <string> delegates = this.config.GmailService.GetDelegates(((User)source).PrimaryEmail).ToList(); attributeChanges.AddRange(typeDef.CreateAttributeChanges(dn, modType, new { Delegates = delegates })); return(attributeChanges); }
public IList <AttributeChange> GetChanges(string dn, ObjectModificationType modType, SchemaType type, object source) { List <AttributeChange> attributeChanges = new List <AttributeChange>(); if (!type.HasAttribute(this.attributeName)) { return(attributeChanges); } IAttributeAdapter typeDef = ManagementAgent.Schema[this.typeName].AttributeAdapters.First(t => t.Api == this.Api); IList <string> sendAsAddresses = this.GetNonPrimarySendAsFormattedAddresses(((User)source).PrimaryEmail); attributeChanges.AddRange(typeDef.CreateAttributeChanges(dn, modType, new { SendAs = sendAsAddresses })); return(attributeChanges); }
public void TestToCSEntryChangeUpdate() { IAttributeAdapter schemaItem = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "websites"); User u = new User { Websites = new List <Website>() { new Website() { Primary = true, Type = "work", Value = "http://work.com" }, new Website() { Primary = false, Type = "home", Value = "http://home.com" } } }; CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Update; IList <AttributeChange> result = schemaItem.CreateAttributeChanges(x.DN, x.ObjectModificationType, u).ToList(); AttributeChange change = result.FirstOrDefault(t => t.Name == "websites_work"); Assert.IsNotNull(change); Assert.AreEqual("http://work.com", change.GetValueAdd <string>()); Assert.AreEqual(AttributeModificationType.Replace, change.ModificationType); x.AttributeChanges.Add(change); change = result.FirstOrDefault(t => t.Name == "websites_home"); Assert.IsNotNull(change); Assert.AreEqual("http://home.com", change.GetValueAdd <string>()); Assert.AreEqual(AttributeModificationType.Replace, change.ModificationType); x.AttributeChanges.Add(change); }
public void TestToCSEntryChangeUpdate() { IAttributeAdapter schemaItem = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "name"); User u = new User { Name = new UserName { GivenName = "Bob", FamilyName = "Smith" } }; CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Update; IList <AttributeChange> result = schemaItem.CreateAttributeChanges(x.DN, x.ObjectModificationType, u).ToList(); AttributeChange change = result.FirstOrDefault(t => t.Name == "name_givenName"); Assert.IsNotNull(change); Assert.AreEqual("Bob", change.GetValueAdd <string>()); Assert.AreEqual(AttributeModificationType.Replace, change.ModificationType); x.AttributeChanges.Add(change); change = result.FirstOrDefault(t => t.Name == "name_familyName"); Assert.IsNotNull(change); Assert.AreEqual("Smith", change.GetValueAdd <string>()); Assert.AreEqual(AttributeModificationType.Replace, change.ModificationType); x.AttributeChanges.Add(change); User ux = new User(); schemaItem.UpdateField(x, ux); Assert.AreEqual("Bob", ux.Name.GivenName); Assert.AreEqual("Smith", ux.Name.FamilyName); }
public void TestNotes() { IAttributeAdapter schemaItem = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "notes"); User u = new User { Notes = new Notes { ContentType = "text", Value = "something" } }; IList <AttributeChange> result = schemaItem.CreateAttributeChanges(null, ObjectModificationType.Add, u).ToList(); AttributeChange notesValue = result.FirstOrDefault(t => t.Name == "notes_value"); Assert.IsNotNull(notesValue); Assert.AreEqual("something", notesValue.GetValueAdd <string>()); AttributeChange notesType = result.FirstOrDefault(t => t.Name == "notes_contentType"); Assert.IsNotNull(notesType); Assert.AreEqual("text", notesType.GetValueAdd <string>()); CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Add; x.AttributeChanges.Add(result.First()); x.AttributeChanges.Add(result.Last()); User ux = new User(); schemaItem.UpdateField(x, ux); Assert.AreEqual("something", ux.Notes.Value); Assert.AreEqual("text", ux.Notes.ContentType); }
public void TestStandaloneAttributes() { IAttributeAdapter orgUnitPath = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "orgUnitPath"); IAttributeAdapter includeInGlobalAddressList = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "includeInGlobalAddressList"); IAttributeAdapter suspended = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "suspended"); IAttributeAdapter changePasswordAtNextLogin = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "changePasswordAtNextLogin"); IAttributeAdapter ipWhitelisted = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "ipWhitelisted"); IAttributeAdapter customerId = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "customerId"); IAttributeAdapter primaryEmail = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "primaryEmail"); IAttributeAdapter id = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "id"); User u = new User { OrgUnitPath = "/Test", IncludeInGlobalAddressList = true, Suspended = true, ChangePasswordAtNextLogin = true, IpWhitelisted = true, CustomerId = "mytest", PrimaryEmail = "*****@*****.**", Id = "testid" }; CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Add; IList <AttributeChange> result = orgUnitPath.CreateAttributeChanges(x.DN, ObjectModificationType.Add, u).ToList(); AttributeChange change = result.FirstOrDefault(t => t.Name == "orgUnitPath"); Assert.IsNotNull(change); Assert.AreEqual("/Test", change.GetValueAdd <string>()); x.AttributeChanges.Add(result.First()); result = includeInGlobalAddressList.CreateAttributeChanges(x.DN, ObjectModificationType.Add, u).ToList(); change = result.FirstOrDefault(t => t.Name == "includeInGlobalAddressList"); Assert.IsNotNull(change); Assert.AreEqual(true, change.GetValueAdd <bool>()); x.AttributeChanges.Add(result.First()); result = suspended.CreateAttributeChanges(x.DN, ObjectModificationType.Add, u).ToList(); change = result.FirstOrDefault(t => t.Name == "suspended"); Assert.IsNotNull(change); Assert.AreEqual(true, change.GetValueAdd <bool>()); x.AttributeChanges.Add(result.First()); result = changePasswordAtNextLogin.CreateAttributeChanges(x.DN, ObjectModificationType.Add, u).ToList(); change = result.FirstOrDefault(t => t.Name == "changePasswordAtNextLogin"); Assert.IsNotNull(change); Assert.AreEqual(true, change.GetValueAdd <bool>()); x.AttributeChanges.Add(result.First()); result = ipWhitelisted.CreateAttributeChanges(x.DN, ObjectModificationType.Add, u).ToList(); change = result.FirstOrDefault(t => t.Name == "ipWhitelisted"); Assert.IsNotNull(change); Assert.AreEqual(true, change.GetValueAdd <bool>()); x.AttributeChanges.Add(result.First()); result = customerId.CreateAttributeChanges(x.DN, ObjectModificationType.Add, u).ToList(); change = result.FirstOrDefault(t => t.Name == "customerId"); Assert.IsNotNull(change); Assert.AreEqual("mytest", change.GetValueAdd <string>()); x.AttributeChanges.Add(result.First()); result = primaryEmail.CreateAttributeChanges(x.DN, ObjectModificationType.Add, u).ToList(); change = result.FirstOrDefault(t => t.Name == "primaryEmail"); Assert.IsNotNull(change); Assert.AreEqual("*****@*****.**", change.GetValueAdd <string>()); x.AttributeChanges.Add(result.First()); result = id.CreateAttributeChanges(x.DN, ObjectModificationType.Add, u).ToList(); change = result.FirstOrDefault(t => t.Name == "id"); Assert.IsNotNull(change); Assert.AreEqual("testid", change.GetValueAdd <string>()); x.AttributeChanges.Add(result.First()); User ux = new User(); changePasswordAtNextLogin.UpdateField(x, ux); suspended.UpdateField(x, ux); includeInGlobalAddressList.UpdateField(x, ux); orgUnitPath.UpdateField(x, ux); Assert.AreEqual(true, ux.ChangePasswordAtNextLogin); Assert.AreEqual(true, ux.Suspended); Assert.AreEqual(true, ux.IncludeInGlobalAddressList); Assert.AreEqual("/Test", ux.OrgUnitPath); }
public void TestWebSites() { IAttributeAdapter schemaItem = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "websites"); User u = new User { Websites = new List <Website>() { new Website() { Primary = true, Type = "work", Value = "http://work.com" }, new Website() { Primary = false, Type = "home", Value = "http://home.com" } } }; CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Add; IList <AttributeChange> result = schemaItem.CreateAttributeChanges(x.DN, ObjectModificationType.Add, u).ToList(); AttributeChange change = result.FirstOrDefault(t => t.Name == "websites_work"); Assert.IsNotNull(change); Assert.AreEqual("http://work.com", change.GetValueAdd <string>()); x.AttributeChanges.Add(change); change = result.FirstOrDefault(t => t.Name == "websites_home"); Assert.IsNotNull(change); Assert.AreEqual("http://home.com", change.GetValueAdd <string>()); x.AttributeChanges.Add(change); User ux = new User(); schemaItem.UpdateField(x, ux); Assert.AreEqual("http://work.com", ux.Websites.First(t => t.Type == "work").Value); Assert.AreEqual(true, ux.Websites.First(t => t.Type == "work").IsPrimary); Assert.AreEqual("http://home.com", ux.Websites.First(t => t.Type == "home").Value); Assert.AreEqual(false, ux.Websites.First(t => t.Type == "home").IsPrimary); x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Update; change = result.FirstOrDefault(t => t.Name == "websites_home"); x.AttributeChanges.Remove(change); x.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("websites_home")); schemaItem.UpdateField(x, ux); x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Update; change = result.FirstOrDefault(t => t.Name == "websites_other"); x.AttributeChanges.Remove(change); x.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("websites_other", "http://other.com")); schemaItem.UpdateField(x, ux); }