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); }
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)); }
public void PropertyBag_TypedPropertyBagGetNull() { var propertyBag = new TestEnumPropertyBag(); propertyBag.GetProperty(null); }