コード例 #1
0
        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");
        }
コード例 #2
0
        public void AddDuplicate()
        {
            SettingsPropertyCollection col       = new SettingsPropertyCollection();
            SettingsProperty           test_prop = new SettingsProperty("test_prop");

            col.Add(test_prop);

            Assert.AreEqual(1, col.Count, "A1");

            test_prop = new SettingsProperty("test_prop");

            col.Add(test_prop);

            Assert.AreEqual(1, col.Count, "A2");
        }
コード例 #3
0
        public void ExceptionalGetPropertyValues()
        {
            SettingsPropertyCollection props = new SettingsPropertyCollection();
            SettingsProviderCollection provs = new SettingsProviderCollection();

            MyProvider3 p = new MyProvider3();
            MySettings  s = new MySettings();

            props.Add(new SettingsProperty("Foo", typeof(string), p, false, 10, SettingsSerializeAs.String, null, true, true));
            provs.Add(p);

            s.Initialize(new SettingsContext(), props, provs);
            Assert.AreEqual(0, s.Context.Count, "#0");
            try
            {
                Assert.AreEqual(100, s.Foo, "#1");
                Assert.Fail("#2");
#if !TARGET_JVM
            }
            catch (Win32Exception)
            {
#else
            }
            catch (CustomerException)
            {
#endif
            }
        }
コード例 #4
0
        public void AuthenticatedDateTime()
        {
            ProfileBase profile = ProfileBase.Create("foo", true);

            ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider);
            DateTime date = DateTime.Now;

            profile["BirthDate"] = date;
            profile.Save();

            SettingsPropertyCollection getProps = new SettingsPropertyCollection();
            SettingsProperty           getProp1 = new SettingsProperty("BirthDate");

            getProp1.PropertyType = typeof(DateTime);
            getProp1.SerializeAs  = SettingsSerializeAs.Xml;
            getProps.Add(getProp1);

            MySQLProfileProvider provider = InitProfileProvider();
            SettingsContext      ctx      = new SettingsContext();

            ctx.Add("IsAuthenticated", true);
            ctx.Add("UserName", "foo");

            SettingsPropertyValueCollection getValues = provider.GetPropertyValues(ctx, getProps);

            Assert.AreEqual(1, getValues.Count);
            SettingsPropertyValue getValue1 = getValues["BirthDate"];

            Assert.AreEqual(date, getValue1.PropertyValue);
        }
コード例 #5
0
        public void AuthenticatedStringProperty()
        {
            ProfileBase profile = ProfileBase.Create("foo", true);

            ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider);
            profile["Name"] = "Fred Flintstone";
            profile.Save();

            SettingsPropertyCollection getProps = new SettingsPropertyCollection();
            SettingsProperty           getProp1 = new SettingsProperty("Name");

            getProp1.PropertyType = typeof(String);
            getProps.Add(getProp1);

            MySQLProfileProvider provider = InitProfileProvider();
            SettingsContext      ctx      = new SettingsContext();

            ctx.Add("IsAuthenticated", true);
            ctx.Add("UserName", "foo");

            SettingsPropertyValueCollection getValues = provider.GetPropertyValues(ctx, getProps);

            Assert.AreEqual(1, getValues.Count);
            SettingsPropertyValue getValue1 = getValues["Name"];

            Assert.AreEqual("Fred Flintstone", getValue1.PropertyValue);
        }
コード例 #6
0
        public void GivenConfirmedUsersWhenGetPropertyValuesWithInvalidColumnsThenNoException(
            string providerName, string membershipProviderName)
        {
            // arrange
            var testClass   = this.WithProvider(providerName);
            var memProvider = this.WithMembershipProvider(membershipProviderName);
            var user        = memProvider.WithConfirmedUser().Value;
            var context     = new SettingsContext();

            context["UserName"] = user.UserName;
            var properties = new SettingsPropertyCollection
            {
                new SettingsProperty("invalidColumn")
                {
                    PropertyType = typeof(string)
                }
            };

            if (memProvider.AsBetter().HasEmailColumnDefined)
            {
                properties.Add(
                    new SettingsProperty(memProvider.AsBetter().UserEmailColumn)
                {
                    PropertyType = typeof(string)
                });
            }

            // act // assert
            Assert.DoesNotThrow(() => testClass.GetPropertyValues(context, properties));
        }
コード例 #7
0
        public void GetUserScopedPropertyValues()
        {
            SettingsAttributeDictionary dict = new SettingsAttributeDictionary();
            UserScopedSettingAttribute  attr = new UserScopedSettingAttribute();

            dict.Add(attr.GetType(), attr);

            LocalFileSettingsProvider prov = new LocalFileSettingsProvider();
            SettingsContext           ctx  = new SettingsContext();
            SettingsProperty          p    = new SettingsProperty("property",
                                                                  typeof(int),
                                                                  prov,
                                                                  false,
                                                                  10,
                                                                  SettingsSerializeAs.Binary,
                                                                  dict,
                                                                  false,
                                                                  false);
            SettingsPropertyCollection      col = new SettingsPropertyCollection();
            SettingsPropertyValueCollection vals;

            col.Add(p);

            prov.Initialize(null, null);

            vals = prov.GetPropertyValues(ctx, col);
            Assert.IsNotNull(vals, "A1");
            Assert.AreEqual(1, vals.Count, "A2");
        }
コード例 #8
0
        public void GetAllProfiles()
        {
            ProfileBase profile = ProfileBase.Create("foo", true);

            ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider);
            profile["Name"] = "Fred Flintstone";
            profile.Save();

            SettingsPropertyCollection getProps = new SettingsPropertyCollection();
            SettingsProperty           getProp1 = new SettingsProperty("Name");

            getProp1.PropertyType = typeof(String);
            getProps.Add(getProp1);

            MySQLProfileProvider provider = InitProfileProvider();
            SettingsContext      ctx      = new SettingsContext();

            ctx.Add("IsAuthenticated", true);
            ctx.Add("UserName", "foo");

            int total;
            ProfileInfoCollection profiles = provider.GetAllProfiles(
                ProfileAuthenticationOption.All, 0, 10, out total);

            Assert.AreEqual(1, total);
        }
コード例 #9
0
        public void ReadOnly_Add()
        {
            SettingsPropertyCollection col = new SettingsPropertyCollection();

            col.SetReadOnly();

            SettingsProperty test_prop = new SettingsProperty("test_prop");

            col.Add(test_prop);
        }
コード例 #10
0
        public static SettingsPropertyCollection ToSettingsPropertyCollection(this IEnumerable <SettingsProperty> settingsProperties)
        {
            var c = new SettingsPropertyCollection();

            foreach (var property in settingsProperties)
            {
                c.Add(property);
            }
            return(c);
        }
コード例 #11
0
        public static SettingsPropertyCollection DeserializeSettingsPropertyCollection(List <ProfilePropertyContract> oSettingsPropertyList)
        {
            #region VARIABLES

            System.Configuration.SettingsPropertyCollection oSettingsPropertyCollection;
            string sCurrentPropertyName;

            SettingsProperty oCurrentSettingsProperty;

            #endregion

            oSettingsPropertyCollection = null;

            if (oSettingsPropertyList != null)
            {
                oSettingsPropertyCollection = new SettingsPropertyCollection();

                foreach (var oGenProperty in oSettingsPropertyList)
                {
                    if (oGenProperty != null)
                    {
                        sCurrentPropertyName = oGenProperty.Name;

                        if (!string.IsNullOrEmpty(sCurrentPropertyName))
                        {
                            oCurrentSettingsProperty = new SettingsProperty(sCurrentPropertyName);

                            if (!string.IsNullOrEmpty(oGenProperty.Type))
                            {
                                oCurrentSettingsProperty.PropertyType = Type.GetType(oGenProperty.Type);
                            }

                            oCurrentSettingsProperty.IsReadOnly = oGenProperty.IsReadOnly;

                            if (!string.IsNullOrEmpty(oGenProperty.DefaultValue))
                            {
                                oCurrentSettingsProperty.DefaultValue = oGenProperty.DefaultValue;
                            }


                            if (oGenProperty.Attributes != null)
                            {
                                foreach (var oGenAttribute in oGenProperty.Attributes)
                                {
                                    oCurrentSettingsProperty.Attributes.Add(oGenAttribute.Key, oGenAttribute.Value);
                                }
                            }
                            oSettingsPropertyCollection.Add(oCurrentSettingsProperty);
                        }
                    }
                }
            }

            return(oSettingsPropertyCollection);
        }
コード例 #12
0
        public void GivenConfirmedUsersWhenGetPropertyValuesWithValidColumnsThenPropertyReturnedSuccessfully(
            string providerName, string membershipProviderName)
        {
            // arrange
            var testClass   = this.WithProvider(providerName);
            var memProvider = this.WithMembershipProvider(membershipProviderName);
            var user        = memProvider.WithConfirmedUser().Value;
            var context     = new SettingsContext();

            context["UserName"] = user.UserName;
            var properties = new SettingsPropertyCollection();

            if (memProvider.AsBetter().HasEmailColumnDefined)
            {
                properties.Add(
                    new SettingsProperty(memProvider.AsBetter().UserEmailColumn)
                {
                    PropertyType = typeof(string)
                });
            }

            properties.Add(new SettingsProperty(memProvider.AsBetter().UserIdColumn)
            {
                PropertyType = typeof(int)
            });

            // act
            var profile = testClass.GetPropertyValues(context, properties);

            // assert
            Assert.That(profile, Is.Not.Null);
            Assert.That(profile[memProvider.AsBetter().UserIdColumn], Is.Not.Null);
            Assert.That(profile[memProvider.AsBetter().UserIdColumn].PropertyValue, Is.GreaterThan(0));
            Assert.That(profile[memProvider.AsBetter().UserIdColumn].IsDirty, Is.False);
            if (memProvider.AsBetter().HasEmailColumnDefined)
            {
                Assert.That(profile[memProvider.AsBetter().UserEmailColumn].PropertyValue, Is.EqualTo(user.Email));
                Assert.That(profile[memProvider.AsBetter().UserEmailColumn].IsDirty, Is.False);
            }
        }
コード例 #13
0
 public SettingsPropertyValue GetPreviousVersion(SettingsContext context, SettingsProperty property)
 {
     if (_Properties == null)
     {
         _Properties = new SettingsPropertyCollection();
     }
     if (_Properties[property.Name] == null)
     {
         _Properties.Add(property);
     }
     GetPropertyValuesCore();
     return(_PropertyValues[property.Name]);
 }
コード例 #14
0
        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");
        }
コード例 #15
0
        private static SettingsPropertyCollection GetPropertiesForProvider(ApplicationSettingsBase settings, SettingsProvider provider)
        {
            SettingsPropertyCollection properties = new SettingsPropertyCollection();

            foreach (SettingsProperty property in settings.Properties)
            {
                if (property.Provider == provider)
                {
                    properties.Add(property);
                }
            }

            return(properties);
        }
コード例 #16
0
        public void GetPropertyValues_NonExistantUserIsCreated_CreateUserInstanceIsCalled()
        {
            var userRepository   = A.Fake <IUserRepository>();
            var profileProvider  = GetProfileProvider(userRepository);
            var context          = new SettingsContext();
            var settings         = new SettingsPropertyCollection();
            var settingsProperty = GetSettingsProperty <string>("name");

            settings.Add(settingsProperty);
            context.Add("UserName", "njupiter\\username");
            A.CallTo(() => userRepository.GetUserByUserName("username", "njupiter")).Returns(null);
            profileProvider.GetPropertyValues(context, settings);
            A.CallTo(() => userRepository.CreateUserInstance("username", "njupiter")).MustHaveHappened(Repeated.Exactly.Once);
        }
コード例 #17
0
        public void PropertyValuesInstance()
        {
            SettingsPropertyCollection props = new SettingsPropertyCollection();
            SettingsProviderCollection provs = new SettingsProviderCollection();

            MyProvider p = new MyProvider();
            MySettings s = new MySettings();

            props.Add(new SettingsProperty("Foo", typeof(string), p, false, 10, SettingsSerializeAs.String, null, true, true));
            provs.Add(p);

            s.Initialize(new SettingsContext(), props, provs);
            Assert.AreEqual(s.PropertyValues, s.PropertyValues);
        }
コード例 #18
0
        public void AddPropertyNoProviderButInProviders()
        {
            SettingsPropertyCollection props = new SettingsPropertyCollection();
            SettingsProviderCollection provs = new SettingsProviderCollection();

            MyProvider p = new MyProvider();
            MySettings s = new MySettings();

            props.Add(new SettingsProperty("Foo", typeof(string), null, false, 10, SettingsSerializeAs.String, null, true, true));
            provs.Add(p);

            s.Initialize(new SettingsContext(), props, provs);
            Assert.AreEqual(100, s.Foo);
        }
コード例 #19
0
        public void AddPropertyTypeMismatch()
        {
            SettingsPropertyCollection props = new SettingsPropertyCollection();
            SettingsProviderCollection provs = new SettingsProviderCollection();

            MyProvider p = new MyProvider();
            MySettings s = new MySettings();

            props.Add(new SettingsProperty("Foo", typeof(string), p, false, 10, SettingsSerializeAs.String, null, true, true));
            provs.Add(p);

            s.Initialize(new SettingsContext(), props, provs);
            int i = s.Foo;             // it still works as int, regardless of the settings property type...
        }
コード例 #20
0
        /// <summary>
        /// Gets the relevant properties.
        /// </summary>
        /// <param name="allProperties">All properties.</param>
        /// <returns>
        /// The relevant properties.
        /// </returns>
        protected virtual SettingsPropertyCollection GetRelevantProperties(SettingsPropertyCollection allProperties)
        {
            var relevantProperties = new SettingsPropertyCollection();

            foreach (SettingsProperty property in allProperties)
            {
                CrmSettingsProperty crmProperty;
                if (this.GetIfRelevant(property, out crmProperty))
                {
                    relevantProperties.Add(crmProperty);
                }
            }

            return(relevantProperties);
        }
コード例 #21
0
        public void GetPropertyValues_NotStoredProperty_ValueEqualsNull()
        {
            var property = new SettingsProperty("PropertyName");

            property.Attributes.Add(typeof(UserScopedSettingAttribute), new UserScopedSettingAttribute());
            var properties = new SettingsPropertyCollection();

            properties.Add(property);
            var localFileSettingsProvider = new LocalFileSettingsProvider();

            SettingsPropertyValueCollection propertyValues = localFileSettingsProvider.GetPropertyValues(_testContext, properties);

            Assert.Equal(1, propertyValues.Count);
            Assert.Null(propertyValues["PropertyName"].PropertyValue);
        }
コード例 #22
0
        public void GetPropertyValues_NotStoredConnectionStringProperty_ValueEqualsEmptyString()
        {
            var property = new SettingsProperty("PropertyName");

            property.PropertyType = typeof(string);
            property.Attributes.Add(typeof(ApplicationScopedSettingAttribute), new ApplicationScopedSettingAttribute());
            property.Attributes.Add(typeof(SpecialSettingAttribute), new SpecialSettingAttribute(SpecialSetting.ConnectionString));
            var properties = new SettingsPropertyCollection();

            properties.Add(property);
            var localFileSettingsProvider = new LocalFileSettingsProvider();

            SettingsPropertyValueCollection propertyValues = localFileSettingsProvider.GetPropertyValues(_testContext, properties);

            Assert.Equal(1, propertyValues.Count);
            Assert.Equal(string.Empty, propertyValues["PropertyName"].PropertyValue);
        }
コード例 #23
0
 private static void AddPropertySettingsFromConfig(Type baseType, bool fAnonEnabled, bool hasLowTrust, ProfilePropertySettingsCollection settingsCollection, string groupName)
 {
     foreach (ProfilePropertySettings settings in settingsCollection)
     {
         string name = (groupName != null) ? (groupName + "." + settings.Name) : settings.Name;
         if ((baseType != typeof(ProfileBase)) && (s_Properties[name] != null))
         {
             throw new ConfigurationErrorsException(System.Web.SR.GetString("Profile_property_already_added"), null, settings.ElementInformation.Properties["name"].Source, settings.ElementInformation.Properties["name"].LineNumber);
         }
         try
         {
             if (settings.TypeInternal == null)
             {
                 settings.TypeInternal = ResolvePropertyType(settings.Type);
             }
         }
         catch (Exception exception)
         {
             throw new ConfigurationErrorsException(System.Web.SR.GetString("Profile_could_not_create_type", new object[] { exception.Message }), exception, settings.ElementInformation.Properties["type"].Source, settings.ElementInformation.Properties["type"].LineNumber);
         }
         if (!fAnonEnabled && settings.AllowAnonymous)
         {
             throw new ConfigurationErrorsException(System.Web.SR.GetString("Annoymous_id_module_not_enabled", new object[] { settings.Name }), settings.ElementInformation.Properties["allowAnonymous"].Source, settings.ElementInformation.Properties["allowAnonymous"].LineNumber);
         }
         if ((settings.SerializeAs == SerializationMode.Binary) && !settings.TypeInternal.IsSerializable)
         {
             throw new ConfigurationErrorsException(System.Web.SR.GetString("Property_not_serializable", new object[] { settings.Name }), settings.ElementInformation.Properties["serializeAs"].Source, settings.ElementInformation.Properties["serializeAs"].LineNumber);
         }
         if (hasLowTrust)
         {
             SetProviderForProperty(settings);
         }
         else
         {
             settings.ProviderInternal = null;
         }
         SettingsAttributeDictionary attributes = new SettingsAttributeDictionary();
         attributes.Add("AllowAnonymous", settings.AllowAnonymous);
         if (!string.IsNullOrEmpty(settings.CustomProviderData))
         {
             attributes.Add("CustomProviderData", settings.CustomProviderData);
         }
         SettingsProperty property = new SettingsProperty(name, settings.TypeInternal, settings.ProviderInternal, settings.ReadOnly, settings.DefaultValue, (SettingsSerializeAs)settings.SerializeAs, attributes, false, true);
         s_Properties.Add(property);
     }
 }
コード例 #24
0
        public void StringCollectionAsProperty()
        {
            ProfileBase profile = ProfileBase.Create("foo", true);

            ResetAppId(profile.Providers["MySqlProfileProvider"] as MySQLProfileProvider);
            StringCollection colors = new StringCollection();

            colors.Add("red");
            colors.Add("green");
            colors.Add("blue");
            profile["FavoriteColors"] = colors;
            profile.Save();

            DataTable dt = FillTable("SELECT * FROM my_aspnet_Applications");

            Assert.AreEqual(1, dt.Rows.Count);
            dt = FillTable("SELECT * FROM my_aspnet_Users");
            Assert.AreEqual(1, dt.Rows.Count);
            dt = FillTable("SELECT * FROM my_aspnet_Profiles");
            Assert.AreEqual(1, dt.Rows.Count);

            // now retrieve them
            SettingsPropertyCollection getProps = new SettingsPropertyCollection();
            SettingsProperty           getProp1 = new SettingsProperty("FavoriteColors");

            getProp1.PropertyType = typeof(StringCollection);
            getProp1.SerializeAs  = SettingsSerializeAs.Xml;
            getProps.Add(getProp1);

            MySQLProfileProvider provider = InitProfileProvider();
            SettingsContext      ctx      = new SettingsContext();

            ctx.Add("IsAuthenticated", true);
            ctx.Add("UserName", "foo");
            SettingsPropertyValueCollection getValues = provider.GetPropertyValues(ctx, getProps);

            Assert.AreEqual(1, getValues.Count);
            SettingsPropertyValue getValue1 = getValues["FavoriteColors"];
            StringCollection      outValue  = (StringCollection)getValue1.PropertyValue;

            Assert.AreEqual(3, outValue.Count);
            Assert.AreEqual("red", outValue[0]);
            Assert.AreEqual("green", outValue[1]);
            Assert.AreEqual("blue", outValue[2]);
        }
コード例 #25
0
        public List <SettingsPropertyValueSerializable> GetPropertyValues(List <object> keys, List <object> values, List <SettingsPropertyValueSerializable> properties)
        {
            SettingsContext sc = new SettingsContext();

            for (int i = 0; i < keys.Count; i++)
            {
                sc.Add(keys[i], values[i]);
            }

            SettingsPropertyCollection properties2 = new SettingsPropertyCollection();

            foreach (SettingsPropertyValue settingsPropertyValue in properties)
            {
                properties2.Add(new SettingsProperty(settingsPropertyValue.Name, settingsPropertyValue.Property.PropertyType, settingsPropertyValue.Property.Provider, settingsPropertyValue.Property.IsReadOnly, settingsPropertyValue.Property.DefaultValue, settingsPropertyValue.Property.SerializeAs, settingsPropertyValue.Property.Attributes, settingsPropertyValue.Property.ThrowOnErrorDeserializing, settingsPropertyValue.Property.ThrowOnErrorSerializing));
            }

            return(SqlProfileProvider.GetPropertyValues(sc, properties2).Cast <SettingsPropertyValueSerializable>().ToList());;
        }
コード例 #26
0
        private static void AddToColl(ProfilePropertyMetadata p, SettingsPropertyCollection retColl, bool isAuthenticated)
        {
            string propName  = p.PropertyName;
            Type   propType  = Type.GetType(p.TypeName, false, true);
            bool   allowAnon = p.AllowAnonymousAccess;
            bool   readOnly  = p.IsReadOnly;

            if (!allowAnon && !isAuthenticated)
            {
                return;
            }

            SettingsSerializeAs         serializeAs = (SettingsSerializeAs)p.SerializeAs;
            SettingsAttributeDictionary dict        = new SettingsAttributeDictionary();

            dict.Add("AllowAnonymous", allowAnon);
            retColl.Add(new SettingsProperty(propName, propType, null, readOnly, p.DefaultValue, serializeAs, dict, true, true));
        }
コード例 #27
0
        protected virtual SettingsPropertyCollection GetRelevantProperties(SettingsPropertyCollection properties)
        {
            var result = new SettingsPropertyCollection();

            if (this.ProfileConfiguration.Properties.Count == 0)
            {
                return(result);
            }

            foreach (SettingsProperty property in properties)
            {
                var entry = this.ProfileConfiguration.Properties.FirstOrDefault(i => i.Name == property.Name);
                if (entry != null)
                {
                    result.Add(new SalesforceProfileProperty(property, entry.SalesforceName));
                }
            }

            return(result);
        }
コード例 #28
0
            public void NoConfig_ReturnsDefaultValues()
            {
                // Arrange
                provider.GetSettingsReader = () => new StringReader("");
                var property1 = SettingsUtil.CreateProperty("myProp1", "myDefaultValue1");

                properties.Add(property1);
                var property2 = SettingsUtil.CreateProperty("myProp2", "myDefaultValue2");

                properties.Add(property2);

                // Act
                var values = provider.GetPropertyValues(context, properties);

                // Assert
                Assert.Equal(2, values.Count);
                Assert.Equal("myDefaultValue1", values["myProp1"].PropertyValue);
                Assert.Equal("myDefaultValue2", values["myProp2"].PropertyValue);
            }
コード例 #29
0
        /// <summary>
        /// Adds default properties to the settings storage of <paramref name="settingsStorageType"/> type.
        /// Properties are taken from the type definition. Only those are taken which are decorated with
        /// <see cref="DefaultSettingValueAttribute"/> attribute (i.e. have default values)
        /// </summary>
        /// <param name="settingsStorageType">Type of the settings storage to take properties from</param>
        /// <param name="propertyCollection">Collection to add instances of <see cref="SettingsProperty"/> to</param>
        /// <param name="propertyValueCollection">Collection to add corresponding instances of <see cref="SettingsPropertyValue"/> to</param>
        public static void AddDefaultProperties(
            Type settingsStorageType,
            SettingsPropertyCollection propertyCollection,
            SettingsPropertyValueCollection propertyValueCollection)
        {
            IEnumerable <PropertyInfo> settingProperties = GetPropertiesWithAttribute(settingsStorageType, typeof(DefaultSettingValueAttribute));

            foreach (PropertyInfo settingProperty in settingProperties)
            {
                DefaultSettingValueAttribute defaultValueAttribute = settingProperty.GetCustomAttributes(typeof(DefaultSettingValueAttribute), false)[0]
                                                                     as DefaultSettingValueAttribute;
                if (defaultValueAttribute != null)
                {
                    SettingsProperty setting = BuildSettingsProperty(
                        settingProperty.Name, defaultValueAttribute.Value, settingProperty.PropertyType, settingProperty.GetCustomAttributes(true));
                    SettingsPropertyValue settingValue = BuildSettingsPropertyValue(setting);

                    propertyCollection.Add(setting);
                    propertyValueCollection.Add(settingValue);
                }
            }
        }
コード例 #30
0
            public void SerializesAndDeserializes()
            {
                // Arrange
                var provider = new ServiceSettingsProvider();

                provider.GetSettingsWriter = () => sw;
                var context = new SettingsContext();
                var values  = new SettingsPropertyValueCollection();

                var property = SettingsUtil.CreateProperty <EncryptedSecret>("myProp");

                property.SerializeAs = SettingsSerializeAs.Xml;
                var value           = new SettingsPropertyValue(property);
                var encryptedSecret = new EncryptedSecret("mySecret", 1000);

                value.PropertyValue = encryptedSecret;
                values.Add(value);

                // Act
                provider.SetPropertyValues(context, values);

                // Arrange
                provider.GetSettingsReader = () => new StringReader(sw.ToString());
                var properties = new SettingsPropertyCollection();

                properties.Add(property);

                // Act
                var values2 = provider.GetPropertyValues(context, properties);
                var myProp  = values2["myProp"].PropertyValue;

                // Assert
                Assert.IsAssignableFrom <EncryptedSecret>(myProp);
                var encryptedSecret2 = (EncryptedSecret)myProp;

                Assert.Equal("mySecret", encryptedSecret2.Decrypt());
            }