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["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 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 TestFromCSEntryChangeUpdate() { IAttributeAdapter schemaItem = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "aliases"); CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Update; List <ValueChange> changes = new List <ValueChange>(); changes.Add(ValueChange.CreateValueAdd("*****@*****.**")); changes.Add(ValueChange.CreateValueDelete("*****@*****.**")); x.AttributeChanges.Add(AttributeChange.CreateAttributeUpdate("aliases", changes)); UserUpdateTemplate ux = new UserUpdateTemplate(); ux.Aliases = new List <string>() { "*****@*****.**", "*****@*****.**" }; schemaItem.UpdateField(x, ux); CollectionAssert.AreEqual(new string[] { "*****@*****.**", "*****@*****.**" }, ux.Aliases.ToArray()); }
public void TestFromCSEntryChangeUpdate() { IAttributeAdapter schemaItem = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "websites"); CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Update; x.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("websites_home", "http://home.com")); x.AttributeChanges.Add(AttributeChange.CreateAttributeUpdate("websites_work", "http://work.com")); User ux = new User(); ux.Websites = new List <Website>() { new Website() { Primary = false, Type = "work", Value = "http://notwork.com" } }; 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); }
public void TestFromCSEntryChangeAdd() { IAttributeAdapter schemaItem = UnitTestControl.Schema["contact"].GetAdapterForMmsAttribute("organizations"); ContactEntry e = new ContactEntry(); CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Add; x.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("organizations_work_name", "myorg")); x.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("organizations_work_department", "department")); x.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("organizations_work_jobDescription", "jobdescription")); x.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("organizations_work_location", "location")); x.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("organizations_work_symbol", "symbol")); x.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("organizations_work_title", "title")); schemaItem.UpdateField(x, e); Organization o = e.Organizations.First(t => t.Rel == "http://schemas.google.com/g/2005#work"); Assert.AreEqual("myorg", o.Name); Assert.AreEqual("department", o.Department); Assert.AreEqual("jobdescription", o.JobDescription); Assert.AreEqual("location", o.Location); Assert.AreEqual("symbol", o.Symbol); Assert.AreEqual("title", o.Title); Assert.AreEqual(true, o.Primary); }
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 IAttributeAdapter TryGetAdapter(Attribute target, IStringLocalizer localizer) { IAttributeAdapter retVal = null; if (constructs.TryGetValue(target.GetType(), out var del)) { retVal = (IAttributeAdapter)del.DynamicInvoke(target, localizer); } return(retVal); }
public void TestFromCSEntryChangeAdd() { IAttributeAdapter schemaItem = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "orgUnitPath"); CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Add; x.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("orgUnitPath", "/Test")); User ux = new User(); schemaItem.UpdateField(x, ux); Assert.AreEqual("/Test", ux.OrgUnitPath); }
public void TestFromCSEntryChangeDelete() { IAttributeAdapter schemaItem = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "orgUnitPath"); CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Update; x.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("orgUnitPath")); User ux = new User(); schemaItem.UpdateField(x, ux); Assert.AreEqual(Constants.NullValuePlaceholder, ux.OrgUnitPath); }
public void TestFromCSEntryChangeAdd() { IAttributeAdapter schemaItem = UnitTestControl.Schema["contact"].GetAdapterForMmsAttribute("externalIds"); ContactEntry e = new ContactEntry(); CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Add; x.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("externalIds_work", "myorg")); schemaItem.UpdateField(x, e); ExternalId o = e.ExternalIds.First(t => t.Label == "work"); Assert.AreEqual("myorg", o.Value); }
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 TestFromCSEntryChangeAdd() { IAttributeAdapter schemaItem = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "name"); CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Add; x.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("name_givenName", "Bob")); x.AttributeChanges.Add(AttributeChange.CreateAttributeAdd("name_familyName", "Smith")); User ux = new User(); schemaItem.UpdateField(x, ux); Assert.AreEqual("Bob", ux.Name.GivenName); Assert.AreEqual("Smith", ux.Name.FamilyName); }
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 TestFromCSEntryChangeDelete() { IAttributeAdapter schemaItem = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "name"); CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Update; x.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("name_givenName")); User ux = new User(); ux.Name.GivenName = "Bob"; ux.Name.FamilyName = "Smith"; schemaItem.UpdateField(x, ux); Assert.AreEqual(Constants.NullValuePlaceholder, ux.Name.GivenName); Assert.AreEqual("Smith", ux.Name.FamilyName); }
public void TestFromCSEntryChangeDelete() { IAttributeAdapter schemaItem = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "aliases"); CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Update; x.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("aliases")); UserUpdateTemplate ux = new UserUpdateTemplate(); ux.Aliases = new List <string>() { "*****@*****.**", "*****@*****.**" }; schemaItem.UpdateField(x, ux); Assert.AreEqual(0, ux.Aliases.Count); }
public void TestFromCSEntryChangeUpdateDeleteLastValue() { IAttributeAdapter schemaItem = UnitTestControl.Schema["user"].AttributeAdapters.First(t => t.FieldName == "organizations"); CSEntryChange x = CSEntryChange.Create(); x.ObjectModificationType = ObjectModificationType.Update; x.AttributeChanges.Add(AttributeChange.CreateAttributeDelete("organizations_work_location")); User ux = new User(); ux.Organizations = new List <Organization>() { new Organization() { Primary = true, Location = "Caulfield" } }; schemaItem.UpdateField(x, ux); Assert.AreEqual(0, ux.Organizations.Count); }
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 virtual IAttributeAdapter GetAttributeAdapter(ValidationAttribute attribute, IStringLocalizer stringLocalizer) { if (attribute == null) { throw new ArgumentNullException(nameof(attribute)); } IAttributeAdapter adapter = null; var type = attribute.GetType(); if (type == typeof(RequiredAttribute)) { adapter = new LocalizedRequiredAttributeAdapter((RequiredAttribute)attribute, stringLocalizer); } if (type == typeof(RequiredTranslateAttribute)) { adapter = new LocalizedRequiredAttributeAdapter((RequiredTranslateAttribute)attribute, stringLocalizer); } return(adapter); }
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 IAttributeAdapter GetAttributeAdapter(ValidationAttribute attribute, IStringLocalizer stringLocalizer) { if (attribute == null) { throw new ArgumentNullException(nameof(attribute)); } IAttributeAdapter adapter = null; var type = attribute.GetType(); //.NET Core 2.2 //if (attribute is RegularExpressionAttribute) //{ // adapter = new RegularExpressionAttributeAdapter((RegularExpressionAttribute)attribute, stringLocalizer); //} //else if (attribute is MaxLengthAttribute) //{ // adapter = new MaxLengthAttributeAdapter((MaxLengthAttribute)attribute, stringLocalizer); //} //else if (attribute is RequiredAttribute) //{ // adapter = new Microsoft.AspNetCore.Mvc.DataAnnotations.Internal.RequiredAttributeAdapter((RequiredAttribute)attribute, stringLocalizer); //} //else if (attribute is CompareAttribute) //{ // adapter = new CompareAttributeAdapter((CompareAttribute)attribute, stringLocalizer); //} //else if (attribute is MinLengthAttribute) //{ // adapter = new MinLengthAttributeAdapter((MinLengthAttribute)attribute, stringLocalizer); //} //else if (attribute is CreditCardAttribute) //{ // adapter = new DataTypeAttributeAdapter((DataTypeAttribute)attribute, "data-val-creditcard", stringLocalizer); //} //else if (attribute is StringLengthAttribute) //{ // adapter = new StringLengthAttributeAdapter((StringLengthAttribute)attribute, stringLocalizer); //} //else if (attribute is RangeAttribute) //{ // adapter = new RangeAttributeAdapter((RangeAttribute)attribute, stringLocalizer); //} //else if (attribute is EmailAddressAttribute) //{ // adapter = new DataTypeAttributeAdapter((DataTypeAttribute)attribute, "data-val-email", stringLocalizer); //} //else if (attribute is PhoneAttribute) //{ // adapter = new DataTypeAttributeAdapter((DataTypeAttribute)attribute, "data-val-phone", stringLocalizer); //} //else if (attribute is UrlAttribute) //{ // adapter = new DataTypeAttributeAdapter((DataTypeAttribute)attribute, "data-val-url", stringLocalizer); //} //else if (attribute is FileExtensionsAttribute) //{ // adapter = new FileExtensionsAttributeAdapter((FileExtensionsAttribute)attribute, stringLocalizer); //} //else //{ // adapter = defaultClientModelValidatorProvider.GetAttributeAdapter(attribute, stringLocalizer); //} if (attribute is RegularExpressionAttribute) { adapter = (IAttributeAdapter)Activator.CreateInstance(Type.GetType("Microsoft.AspNetCore.Mvc.DataAnnotations.RegularExpressionAttributeAdapter, Microsoft.AspNetCore.Mvc.DataAnnotations"), (RegularExpressionAttribute)attribute, stringLocalizer); } else if (attribute is MaxLengthAttribute) { adapter = (IAttributeAdapter)Activator.CreateInstance(Type.GetType("Microsoft.AspNetCore.Mvc.DataAnnotations.MaxLengthAttributeAdapter, Microsoft.AspNetCore.Mvc.DataAnnotations"), (MaxLengthAttribute)attribute, stringLocalizer); } else if (attribute is RequiredAttribute) { adapter = new RequiredAttributeAdapter((RequiredAttribute)attribute, stringLocalizer); } else if (attribute is CompareAttribute) { adapter = (IAttributeAdapter)Activator.CreateInstance(Type.GetType("Microsoft.AspNetCore.Mvc.DataAnnotations.CompareAttributeAdapter, Microsoft.AspNetCore.Mvc.DataAnnotations"), (CompareAttribute)attribute, stringLocalizer); } else if (attribute is MinLengthAttribute) { adapter = (IAttributeAdapter)Activator.CreateInstance(Type.GetType("Microsoft.AspNetCore.Mvc.DataAnnotations.MinLengthAttributeAdapter, Microsoft.AspNetCore.Mvc.DataAnnotations"), (MinLengthAttribute)attribute, stringLocalizer); } else if (attribute is CreditCardAttribute) { adapter = (IAttributeAdapter)Activator.CreateInstance(Type.GetType("Microsoft.AspNetCore.Mvc.DataAnnotations.DataTypeAttributeAdapter, Microsoft.AspNetCore.Mvc.DataAnnotations"), (DataTypeAttribute)attribute, "data-val-creditcard", stringLocalizer); } else if (attribute is StringLengthAttribute) { adapter = (IAttributeAdapter)Activator.CreateInstance(Type.GetType("Microsoft.AspNetCore.Mvc.DataAnnotations.StringLengthAttributeAdapter, Microsoft.AspNetCore.Mvc.DataAnnotations"), (StringLengthAttribute)attribute, stringLocalizer); } else if (attribute is RangeAttribute) { adapter = (IAttributeAdapter)Activator.CreateInstance(Type.GetType("Microsoft.AspNetCore.Mvc.DataAnnotations.RangeAttributeAdapter, Microsoft.AspNetCore.Mvc.DataAnnotations"), (RangeAttribute)attribute, stringLocalizer); } else if (attribute is EmailAddressAttribute) { adapter = (IAttributeAdapter)Activator.CreateInstance(Type.GetType("Microsoft.AspNetCore.Mvc.DataAnnotations.DataTypeAttributeAdapter, Microsoft.AspNetCore.Mvc.DataAnnotations"), (DataTypeAttribute)attribute, "data-val-email", stringLocalizer); } else if (attribute is PhoneAttribute) { adapter = (IAttributeAdapter)Activator.CreateInstance(Type.GetType("Microsoft.AspNetCore.Mvc.DataAnnotations.DataTypeAttributeAdapter, Microsoft.AspNetCore.Mvc.DataAnnotations"), (DataTypeAttribute)attribute, "data-val-phone", stringLocalizer); } else if (attribute is UrlAttribute) { adapter = (IAttributeAdapter)Activator.CreateInstance(Type.GetType("Microsoft.AspNetCore.Mvc.DataAnnotations.DataTypeAttributeAdapter, Microsoft.AspNetCore.Mvc.DataAnnotations"), (DataTypeAttribute)attribute, "data-val-url", stringLocalizer); } else if (attribute is FileExtensionsAttribute) { adapter = (IAttributeAdapter)Activator.CreateInstance(Type.GetType("Microsoft.AspNetCore.Mvc.DataAnnotations.FileExtensionsAttributeAdapter, Microsoft.AspNetCore.Mvc.DataAnnotations"), (FileExtensionsAttribute)attribute, stringLocalizer); } else { adapter = defaultClientModelValidatorProvider.GetAttributeAdapter(attribute, stringLocalizer); } return(adapter); }
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); }
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); }