Пример #1
0
        public void PropertyBag_TypedPropertyBagNoCache()
        {
            var propertyBag = new TestEnumPropertyBag();

            TestEnum testEnum = propertyBag.GetProperty(TestEnumOptionTwo, cacheDefault: false);

            Assert.AreEqual(TestEnumOptionTwo.DefaultValue, testEnum);
            Assert.AreEqual(propertyBag.Count, 0);
        }
Пример #2
0
        public void PropertyBag_HumanReadableSerialization()
        {
            TestData testData    = new TestData();
            var      propertyBag = new PropertyBag();

            testData.InitializePropertyBag(propertyBag);

            propertyBag = PersistAndReloadPropertyBag(propertyBag);
            testData.ValidatePropertyBag(propertyBag);

            string path = Path.GetTempFileName();

            try
            {
                propertyBag.SaveTo(path, "TestId");
                propertyBag = new PropertyBag();
                propertyBag.LoadFrom(path);
                testData.ValidatePropertyBag(propertyBag);
            }
            finally
            {
                if (File.Exists(path))
                {
                    File.Delete(path);
                }
            }

            TestEnumPropertyBag typedPropertyBag = propertyBag.GetProperty(TypedPropertyBagOption);

            typedPropertyBag.SetProperty(TestEnumOptionThree, TestEnum.ValueOne);
            Assert.AreEqual(TestEnum.ValueOne, typedPropertyBag.GetProperty(TestEnumOptionThree));
            Assert.AreNotEqual(TestEnumOptionThree.DefaultValue, typedPropertyBag.GetProperty(TestEnumOptionThree));

            Assert.AreEqual(TestEnumOptionTwo.DefaultValue, typedPropertyBag.GetProperty(TestEnumOptionTwo));

            propertyBag.SetProperty(TypedPropertyBagOption, null);
            typedPropertyBag = propertyBag.GetProperty(TypedPropertyBagOption);

            // The Roslyn options pattern has a design flaw in that it does not provide for handing out new
            // default instances of references type. Instead, the option instance retains a singleton
            // value. In ModernCop, we replaced DefaultValue with a delegate that returns the appropriate type.
            // This allowed for multiple constructions of empty default values.
            //Assert.AreEqual(TestEnumOptionThree.DefaultValue, typedPropertyBag.GetProperty(TestEnumOptionThree));
        }
Пример #3
0
            internal void InitializePropertyBag(PropertyBag propertyBag)
            {
                propertyBag.SetProperty(DoubleOption, DoubleValue);
                propertyBag.SetProperty(BooleanOption, BooleanValue);
                propertyBag.SetProperty(TestEnumOptionThree, TestEnumValue);
                propertyBag.SetProperty(StringSetOption, StringSetValue);

                PropertyBagValue = new PropertyBag();
                PropertyBagValue.SetProperty(DoubleOption, EmbeddedDoubleValue);
                PropertyBagValue.SetProperty(BooleanOption, EmbeddedBooleanValue);
                PropertyBagValue.SetProperty(TestEnumOptionThree, EmbeddedTestEnumValue);
                PropertyBagValue.SetProperty(StringSetOption, EmbeddedStringSetValue);


                propertyBag.SetProperty(PropertyBagOption, PropertyBagValue);

                TypedPropertyBagValue = propertyBag.GetProperty(TypedPropertyBagOption);
                TypedPropertyBagValue.SetProperty(TestEnumOptionThree, EmbeddedTestEnumValue);

                propertyBag.SetProperty(TypedPropertyBagOption, TypedPropertyBagValue);
            }
Пример #4
0
        public void PropertyBag_TypedPropertyBagSetNull()
        {
            var propertyBag = new TestEnumPropertyBag();

            propertyBag.SetProperty(null, 0);
        }