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 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
            }
        }
示例#3
0
        public void PropertyValuesUninitialized()
        {
            MySettings s = new MySettings();

            s.Initialize(new SettingsContext(), new SettingsPropertyCollection(), new SettingsProviderCollection());
            s.Properties.Add(new SettingsProperty("Foo"));
            // values are filled only at initialization phase.
            Assert.AreEqual(0, s.PropertyValues.Count, "#1");
        }
示例#4
0
        public void PropertyDefaults()
        {
            MySettings s = new MySettings();

            Assert.IsNull(s.Properties, "#1");
            Assert.IsNull(s.Providers, "#2");
            Assert.IsNull(s.Context, "#3");
            Assert.AreEqual(0, s.PropertyValues.Count, "#4");
            Assert.IsNull(s.Properties, "#5");
            Assert.IsNull(s.Providers, "#6");
            Assert.IsNull(s.Context, "#7");
            s.Initialize(s.Context, s.Properties, s.Providers);
        }
示例#5
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);
        }
示例#6
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...
        }
示例#7
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);
        }
		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
			}
		}
		public void PropertyDefaults ()
		{
			MySettings s = new MySettings ();
			Assert.IsNull (s.Properties, "#1");
			Assert.IsNull (s.Providers, "#2");
			Assert.IsNull (s.Context, "#3");
			Assert.AreEqual (0, s.PropertyValues.Count, "#4");
			Assert.IsNull (s.Properties, "#5");
			Assert.IsNull (s.Providers, "#6");
			Assert.IsNull (s.Context, "#7");
			s.Initialize (s.Context, s.Properties, s.Providers);
		}
		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);
		}
		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...
		}
		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 PropertyValuesUninitialized ()
		{
			MySettings s = new MySettings ();
			s.Initialize (new SettingsContext (), new SettingsPropertyCollection (), new SettingsProviderCollection ());
			s.Properties.Add (new SettingsProperty ("Foo"));
			// values are filled only at initialization phase.
			Assert.AreEqual (0, s.PropertyValues.Count, "#1");
		}
		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);
		}