|
@@ -1,4 +1,4 @@
|
|
|
-using System.Configuration;
|
|
|
+using System.Collections.Specialized;
|
|
|
using Abc.Zebus.Directory.Configuration;
|
|
|
using Abc.Zebus.Testing.Extensions;
|
|
|
using Abc.Zebus.Util;
|
|
@@ -9,22 +9,28 @@ namespace Abc.Zebus.Directory.Tests.Configuration
|
|
|
[TestFixture]
|
|
|
public class ConfigurationTests
|
|
|
{
|
|
|
+ private NameValueCollection _appSettings;
|
|
|
+
|
|
|
+ [SetUp]
|
|
|
+ public void SetUp()
|
|
|
+ {
|
|
|
+ _appSettings = new NameValueCollection();
|
|
|
+ }
|
|
|
+
|
|
|
[Test]
|
|
|
public void should_read_registration_timeout()
|
|
|
{
|
|
|
SetAppSettingsKey("Bus.Directory.RegistrationTimeout", "00:00:42");
|
|
|
|
|
|
- var configuration = new AppSettingsBusConfiguration();
|
|
|
- configuration.RegistrationTimeout.ShouldEqual(42.Seconds());
|
|
|
+ var busConfiguration = new AppSettingsBusConfiguration(new AppSettings(_appSettings));
|
|
|
+ busConfiguration.RegistrationTimeout.ShouldEqual(42.Seconds());
|
|
|
}
|
|
|
|
|
|
[Test]
|
|
|
public void should_read_default_registration_timeout()
|
|
|
{
|
|
|
- RemoveAppSettingsKey("Bus.Directory.RegistrationTimeout");
|
|
|
-
|
|
|
- var configuration = new AppSettingsBusConfiguration();
|
|
|
- configuration.RegistrationTimeout.ShouldEqual(30.Seconds());
|
|
|
+ var busConfiguration = new AppSettingsBusConfiguration(new AppSettings(_appSettings));
|
|
|
+ busConfiguration.RegistrationTimeout.ShouldEqual(30.Seconds());
|
|
|
}
|
|
|
|
|
|
[Test]
|
|
@@ -32,40 +38,36 @@ namespace Abc.Zebus.Directory.Tests.Configuration
|
|
|
{
|
|
|
SetAppSettingsKey("Directory.PingPeers.Interval", "00:02");
|
|
|
|
|
|
- var configuration = new AppSettingsDirectoryConfiguration();
|
|
|
- configuration.PeerPingInterval.ShouldEqual(2.Minutes());
|
|
|
+ var directoryConfiguration = new AppSettingsDirectoryConfiguration(new AppSettings(_appSettings));
|
|
|
+ directoryConfiguration.PeerPingInterval.ShouldEqual(2.Minutes());
|
|
|
}
|
|
|
|
|
|
[Test]
|
|
|
- public void should_read_default_peer_ping_interval()
|
|
|
+ public void should_read_default_max_allowed_clock_diff()
|
|
|
{
|
|
|
- RemoveAppSettingsKey("Directory.PingPeers.Interval");
|
|
|
-
|
|
|
- var configuration = new AppSettingsDirectoryConfiguration();
|
|
|
- configuration.PeerPingInterval.ShouldEqual(1.Minute());
|
|
|
+ var directoryConfiguration = new AppSettingsDirectoryConfiguration(new AppSettings(_appSettings));
|
|
|
+ directoryConfiguration.MaxAllowedClockDifferenceWhenRegistering.ShouldEqual(null);
|
|
|
}
|
|
|
|
|
|
- private static void SetAppSettingsKey(string key, string value)
|
|
|
+ [Test]
|
|
|
+ public void should_read_max_allowed_clock_diff()
|
|
|
{
|
|
|
- var appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
|
|
- var element = appConfig.AppSettings.Settings[key];
|
|
|
- if (element == null)
|
|
|
- appConfig.AppSettings.Settings.Add(key, value);
|
|
|
- else
|
|
|
- element.Value = value;
|
|
|
-
|
|
|
- appConfig.Save();
|
|
|
+ SetAppSettingsKey("Directory.MaxAllowedClockDifferenceWhenRegistering", "00:02");
|
|
|
|
|
|
- ConfigurationManager.RefreshSection("appSettings");
|
|
|
+ var directoryConfiguration = new AppSettingsDirectoryConfiguration(new AppSettings(_appSettings));
|
|
|
+ directoryConfiguration.MaxAllowedClockDifferenceWhenRegistering.ShouldEqual(2.Minutes());
|
|
|
}
|
|
|
|
|
|
- private static void RemoveAppSettingsKey(string key)
|
|
|
+ [Test]
|
|
|
+ public void should_read_default_peer_ping_interval()
|
|
|
{
|
|
|
- var appConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
|
|
- appConfig.AppSettings.Settings.Remove(key);
|
|
|
- appConfig.Save();
|
|
|
+ var directoryConfiguration = new AppSettingsDirectoryConfiguration(new AppSettings(_appSettings));
|
|
|
+ directoryConfiguration.PeerPingInterval.ShouldEqual(1.Minute());
|
|
|
+ }
|
|
|
|
|
|
- ConfigurationManager.RefreshSection("appSettings");
|
|
|
+ private void SetAppSettingsKey(string key, string value)
|
|
|
+ {
|
|
|
+ _appSettings[key] = value;
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|