public void PropertyValuesInitialized() { SettingsPropertyCollection props = new SettingsPropertyCollection(); SettingsProviderCollection provs = new SettingsProviderCollection(); MyProvider p = new MyProvider(); MySettings s = new MySettings(); int i; try { i = s.Foo; Assert.Fail("#1-2"); } catch (SettingsPropertyNotFoundException) { } s.Initialize(new SettingsContext(), props, provs); Assert.AreEqual(0, s.PropertyValues.Count, "#2-1"); Assert.AreEqual(0, s.Context.Count, "#2-2"); props.Add(new SettingsProperty("Foo", typeof(int), p, false, 10, SettingsSerializeAs.String, null, true, true)); // initialize w/o the provider s.Initialize(new SettingsContext(), props, provs); Assert.AreEqual(0, s.PropertyValues.Count, "#3-0"); Assert.AreEqual(100, s.Foo, "#3-1"); // ... !!! Assert.AreEqual(1, s.PropertyValues.Count, "#3-2"); SettingsPropertyValue v = s.PropertyValues ["Foo"]; Assert.AreEqual(100, v.PropertyValue, "#3-3"); Assert.AreEqual(0, s.Context.Count, "#3-4"); // initialize w/ the provider provs.Add(p); provs.Add(new MyProvider2("Bar", 25)); props.Add(new SettingsProperty("Bar", typeof(int), provs ["MyProvider2"], false, 10, SettingsSerializeAs.String, null, true, true)); s.Initialize(new SettingsContext(), props, provs); Assert.AreEqual(1, s.PropertyValues.Count, "#4-1"); Assert.AreEqual(100, s.Foo, "#4-2"); Assert.AreEqual(25, s.Bar, "#4-3"); // ... !!! Assert.AreEqual(2, s.PropertyValues.Count, "#4-3-2"); Assert.AreEqual(0, s.Context.Count, "#4-4"); // wrong provider props.Remove("Bar"); props.Add(new SettingsProperty("Bar", typeof(int), provs ["MyProvider"], false, 10, SettingsSerializeAs.String, null, true, true)); s = new MySettings(); s.Initialize(new SettingsContext(), props, provs); Assert.AreEqual(0, s.PropertyValues.Count, "#5-1"); Assert.AreEqual(100, s.Foo, "#5-2"); Assert.AreEqual(10, s.Bar, "#5-3"); }
public void ReadOnly_Remove() { SettingsPropertyCollection col = new SettingsPropertyCollection(); SettingsProperty test_prop = new SettingsProperty("test_prop"); col.Add(test_prop); col.SetReadOnly(); col.Remove("test_prop"); }
public void Remove_NonExistant() { SettingsPropertyCollection col = new SettingsPropertyCollection(); SettingsProperty test_prop = new SettingsProperty("test_prop"); col.Add(test_prop); Assert.AreEqual(1, col.Count, "A1"); col.Remove("test_prop2"); Assert.AreEqual(1, col.Count, "A2"); }
public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { var result = new SettingsPropertyValueCollection(); if (!this.Initialized) { return(result); } string userName = (string)context["UserName"]; if (string.IsNullOrEmpty(userName) || userName.Contains(@"\")) { return(result); } var relevantProperties = this.GetRelevantProperties(collection); if (relevantProperties.Count == 0) { return(result); } var userProperties = this.GetProperties(userName, this.SaleforcePropertyNames); foreach (SalesforceProfileProperty property in relevantProperties) { object value; if (userProperties.TryGetValue(property.SalesforceName, out value)) { value = this.ConvertProperty(value, property.PropertyType); } result.Add(new SettingsPropertyValue(property) { IsDirty = false, PropertyValue = value, }); collection.Remove(property.Name); } return(result); }
/// <summary> /// Returns the collection of settings property values for the specified application instance and settings property group. /// </summary> /// <param name="context">A <see cref="T:System.Configuration.SettingsContext"/> describing the current application use.</param> /// <param name="collection">A <see cref="T:System.Configuration.SettingsPropertyCollection"/> containing the settings property group whose values are to be retrieved.</param> /// <returns> /// A <see cref="T:System.Configuration.SettingsPropertyValueCollection"/> containing the values for the specified settings property group. /// </returns> /// <exception cref="ProviderException">Couldn't resolve CRM property type</exception> public override SettingsPropertyValueCollection GetPropertyValues(SettingsContext context, SettingsPropertyCollection collection) { if (this.initialized) { var spvc = new SettingsPropertyValueCollection(); var userName = (string)context["UserName"]; if (userName != string.Empty) { if ((!string.IsNullOrEmpty(userName)) && (!userName.Contains("\\"))) { var attributes = new List <string>(); SettingsPropertyCollection relevantProperties = this.GetRelevantProperties(collection); if (relevantProperties.Count > 0) { attributes.AddRange(this.ProcessProperties(relevantProperties, p => (p as CrmSettingsProperty).CrmName)); var propertyValues = this.profileRepository.GetUserProperties(userName, attributes.ToArray()); foreach (CrmSettingsProperty property in relevantProperties) { if (collection[property.Name] == null) { continue; } var crmPropertyValue = new CrmSettingsPropertyValue(collection[property.Name]) { PropertyValue = string.Empty }; collection.Remove(property.Name); crmPropertyValue.PropertyValue = propertyValues.ContainsKey(property.CrmName) ? propertyValues[property.CrmName] : string.Empty; crmPropertyValue.IsDirty = false; spvc.Add(crmPropertyValue); } } } } return(spvc); } return(new SettingsPropertyValueCollection()); }