public void PropertyOnChangeEventTest() { string key1 = "key1"; string key2 = "key2"; string key3 = "key3"; string value1 = "Hello World 1"; string value2 = "Hello World 2"; string value3 = "100"; Dictionary <string, string> data = new Dictionary <string, string>(); data[key1] = value1; data[key2] = value2; data[key3] = value3; MemoryConfiguration configuration = new MemoryConfiguration(data); IDynamicConfigurationSource configurationSource = ObjectFactory.CreateDefaultDynamicConfigurationSource(0, "test", configuration); IConfigurationManager manager = ObjectFactory.CreateDefaultConfigurationManager(configurationSource); int managerEventExecuted = 0; manager.OnPropertyChange += (s, e) => managerEventExecuted++; int event1Executed = 0, event2Executed = 0, event3Executed = 0; IProperty property1 = manager.GetProperty(key1); property1.OnChange += (s, e) => event1Executed++; IProperty property2 = manager.GetProperty(key2); property2.OnChange += (s, e) => event2Executed++; IProperty <double> property3 = manager.GetProperty(key3, 0.0); property3.OnChange += (s, e) => event3Executed++; managerEventExecuted = event1Executed = event2Executed = event3Executed = 0; configuration[key1] = "test value"; Assert.AreEqual(1, event1Executed); Assert.AreEqual(0, event2Executed); Assert.AreEqual(0, event3Executed); Assert.AreEqual(1, managerEventExecuted); managerEventExecuted = event1Executed = event2Executed = event3Executed = 0; configuration[key2] = "test value"; Assert.AreEqual(0, event1Executed); Assert.AreEqual(1, event2Executed); Assert.AreEqual(0, event3Executed); Assert.AreEqual(1, managerEventExecuted); managerEventExecuted = event1Executed = event2Executed = event3Executed = 0; configuration[key3] = "100.0"; Assert.AreEqual(0, event1Executed); Assert.AreEqual(0, event2Executed); Assert.AreEqual(0, event3Executed); Assert.AreEqual(1, managerEventExecuted); }
public void CorrectDefaultValue() { string sizeKey = "age"; int sizeMaxValue = 100; int defaultValue = 101; MemoryConfiguration memoryConfiguration = new MemoryConfiguration(); IDynamicConfigurationSource dynamicSource = ObjectFactory.CreateDefaultDynamicConfigurationSource(0, "dynamic", memoryConfiguration); IConfigurationManager manager = ObjectFactory.CreateDefaultConfigurationManager(dynamicSource); IProperty <int> ageProperty = manager.GetProperty <int>(sizeKey, defaultValue, new UpperBoundCorrector <int>(sizeMaxValue)); Assert.AreEqual(sizeMaxValue, ageProperty.Value); }
public void CorrectDefaultNullableValue() { string ageKey = "age"; int? ageMinValue = 0; int? defaultValue = -1; MemoryConfiguration memoryConfiguration = new MemoryConfiguration(); IDynamicConfigurationSource dynamicSource = ObjectFactory.CreateDefaultDynamicConfigurationSource(0, "dynamic", memoryConfiguration); IConfigurationManager manager = ObjectFactory.CreateDefaultConfigurationManager(dynamicSource); IProperty <int?> ageProperty = manager.GetProperty <int?>(ageKey, defaultValue, new NullableLowerBoundCorrector <int>(ageMinValue)); Assert.AreEqual(ageMinValue, ageProperty.Value); }
public void CorrectDefaultNullableValue() { string portKey = "port"; int? portMinValue = 1; int? portMaxValue = 65535; int? defaultValue = 0; MemoryConfiguration memoryConfiguration = new MemoryConfiguration(); IDynamicConfigurationSource dynamicSource = ObjectFactory.CreateDefaultDynamicConfigurationSource(0, "dynamic", memoryConfiguration); IConfigurationManager manager = ObjectFactory.CreateDefaultConfigurationManager(dynamicSource); IProperty <int?> ageProperty = manager.GetProperty <int?>(portKey, defaultValue, new NullableRangeCorrector <int>(portMinValue, portMaxValue)); Assert.AreEqual(portMinValue, ageProperty.Value); }
public void CorrectInvalidNullableValue() { string sizeKey = "age"; int? sizeValue = 101; int? sizeMaxValue = 100; int? defaultValue = 0; MemoryConfiguration memoryConfiguration = new MemoryConfiguration(); memoryConfiguration[sizeKey] = sizeValue.ToString(); IDynamicConfigurationSource dynamicSource = ObjectFactory.CreateDefaultDynamicConfigurationSource(0, "dynamic", memoryConfiguration); IConfigurationManager manager = ObjectFactory.CreateDefaultConfigurationManager(dynamicSource); IProperty <int?> ageProperty = manager.GetProperty <int?>(sizeKey, defaultValue, new NullableUpperBoundCorrector <int>(sizeMaxValue)); Assert.AreEqual(sizeMaxValue, ageProperty.Value); }
public void CorrectInvalidValue() { string ageKey = "age"; int ageValue = -1; int ageMinValue = 0; int defaultValue = 18; MemoryConfiguration memoryConfiguration = new MemoryConfiguration(); memoryConfiguration[ageKey] = ageValue.ToString(); IDynamicConfigurationSource dynamicSource = ObjectFactory.CreateDefaultDynamicConfigurationSource(0, "dynamic", memoryConfiguration); IConfigurationManager manager = ObjectFactory.CreateDefaultConfigurationManager(dynamicSource); IProperty <int> ageProperty = manager.GetProperty <int>(ageKey, defaultValue, new LowerBoundCorrector <int>(ageMinValue)); Assert.AreEqual(ageMinValue, ageProperty.Value); }
public void CorrectInvalidValue_MaxValue() { string portKey = "port"; int portValue = 65536; int portMinValue = 1; int portMaxValue = 65535; int defaultValue = 12345; MemoryConfiguration memoryConfiguration = new MemoryConfiguration(); memoryConfiguration[portKey] = portValue.ToString(); IDynamicConfigurationSource dynamicSource = ObjectFactory.CreateDefaultDynamicConfigurationSource(0, "dynamic", memoryConfiguration); IConfigurationManager manager = ObjectFactory.CreateDefaultConfigurationManager(dynamicSource); IProperty <int> ageProperty = manager.GetProperty <int>(portKey, defaultValue, new RangeCorrector <int>(portMinValue, portMaxValue)); Assert.AreEqual(portMaxValue, ageProperty.Value); }
public void PropertyMultiChangeEventTest() { string birthKey = "BirthYear"; string ageKey = "Age"; MultiChangeTestConfiguration configuration = new MultiChangeTestConfiguration(); IDynamicConfigurationSource configurationSource = ObjectFactory.CreateDefaultDynamicConfigurationSource(0, "MultiChangeTestConfiguration", configuration); IConfigurationManager manager = ObjectFactory.CreateDefaultConfigurationManager(configurationSource); IProperty <int> birthYearProperty = manager.GetProperty <int>(birthKey); IProperty <int> ageProperty = manager.GetProperty <int>(ageKey); int birthYearEventExecuted = 0, ageEventExecuted = 0; birthYearProperty.OnChange += (o, e) => birthYearEventExecuted++; ageProperty.OnChange += (o, e) => ageEventExecuted++; configuration[birthKey] = "1991"; Assert.AreEqual(1, birthYearEventExecuted); Assert.AreEqual(1, ageEventExecuted); }
public void ValueCorrectorChain_MinValue_Test() { string portKey = "port"; int portValue = 0; int portMinValue = 1; int portMaxValue = 65535; int defaultValue = 12345; MemoryConfiguration memoryConfiguration = new MemoryConfiguration(); memoryConfiguration[portKey] = portValue.ToString(); IDynamicConfigurationSource dynamicSource = ObjectFactory.CreateDefaultDynamicConfigurationSource(0, "dynamic", memoryConfiguration); IConfigurationManager manager = ObjectFactory.CreateDefaultConfigurationManager(dynamicSource); IValueCorrector <int> valueCorrector = new UpperBoundCorrector <int>(portMaxValue); valueCorrector = new LowerBoundCorrector <int>(valueCorrector, portMinValue); IProperty <int> ageProperty = manager.GetProperty <int>(portKey, defaultValue, valueCorrector); Assert.AreEqual(portMinValue, ageProperty.Value); }
public void NotCacheValueTest() { string messageKey = "message"; string messageValue = "Hello World 1"; string messageNewValue = "Hello World 2"; Dictionary <string, string> data = new Dictionary <string, string>(); data[messageKey] = messageValue; DynamicConfigurationForCacheValueTest configuration = new DynamicConfigurationForCacheValueTest(data); IDynamicConfigurationSource configurationSource = ObjectFactory.CreateDefaultDynamicConfigurationSource(0, "test", configuration); IConfigurationManager manager = ObjectFactory.CreateDefaultConfigurationManager(configurationSource); IProperty property = manager.GetProperty(messageKey, "", false); Assert.AreEqual(messageValue, property.Value); configuration.SetPropertyValue(messageKey, messageNewValue); Assert.AreEqual(messageNewValue, property.Value); Thread.Sleep(2000); Assert.AreEqual(messageNewValue, property.Value); }