public void RefreshDoesNotThrowException() { // --- Arrange MsSqlConfigurationHandler.Reset(TimeSpan.FromMilliseconds(100)); var handler = new MsSqlConfigurationHandler(); // --- Act string value1; handler.GetConfigurationValue("Category1", "Key1", out value1); string value2; handler.GetConfigurationValue("Category1", "Key1", out value2); Thread.Sleep(100); ServiceManager.RemoveService(typeof(IConfigurationDataOperations)); string value3; handler.GetConfigurationValue("Category1", "Key1", out value3); Thread.Sleep(100); // --- Assert MsSqlConfigurationHandler.LastRefreshException.ShouldBeOfType(typeof(AggregateException)); }
public void ParallelRefreshWorksAsExpected() { // --- Arrange MsSqlConfigurationHandler.Reset(TimeSpan.FromMilliseconds(100)); var handler = new MsSqlConfigurationHandler(); // --- Act var refreshTime1 = MsSqlConfigurationHandler.LastRefreshTime; string value1; handler.GetConfigurationValue("Category1", "Key1", out value1); string value2; handler.SetConfigurationValue("Category1", "Key1", "New"); handler.GetConfigurationValue("Category1", "Key1", out value2); var refreshTime2 = MsSqlConfigurationHandler.LastRefreshTime; Thread.Sleep(100); string value3; Parallel.Invoke( () => handler.GetConfigurationValue("Category1", "Key1", out value3), () => handler.GetConfigurationValue("Category1", "Key1", out value3)); Thread.Sleep(100); handler.GetConfigurationValue("Category1", "Key1", out value3); var refreshTime3 = MsSqlConfigurationHandler.LastRefreshTime; // --- Assert refreshTime1.ShouldEqual(refreshTime2); value1.ShouldEqual(value2); refreshTime3.ShouldNotEqual(refreshTime2); value3.ShouldNotEqual(value2); }
public void ConfigurationIsNotRefreshedAfterHold() { // --- Arrange MsSqlConfigurationHandler.Reset(TimeSpan.FromMilliseconds(100)); var handler = new MsSqlConfigurationHandler(); // --- Act var refreshTime1 = MsSqlConfigurationHandler.LastRefreshTime; string value1; handler.GetConfigurationValue("Category1", "Key1", out value1); string value2; handler.SetConfigurationValue("Category1", "Key1", "New"); MsSqlConfigurationHandler.Hold(); handler.GetConfigurationValue("Category1", "Key1", out value2); var refreshTime2 = MsSqlConfigurationHandler.LastRefreshTime; Thread.Sleep(100); string value3; handler.GetConfigurationValue("Category1", "Key1", out value3); Thread.Sleep(100); handler.GetConfigurationValue("Category1", "Key1", out value3); var refreshTime3 = MsSqlConfigurationHandler.LastRefreshTime; // --- Assert refreshTime1.ShouldEqual(refreshTime2); value1.ShouldEqual(value2); refreshTime3.ShouldEqual(refreshTime2); value3.ShouldEqual(value2); }
public void TestInitialize() { ServiceManager.SetRegistry(new DefaultServiceRegistry()); ServiceManager.Register <IConfigurationDataOperations, ConfigurationDataOperations>(DB_CONN); DataAccessFactory.SetRegistry(ServiceManager.ServiceRegistry); SqlScriptHelper.RunScript("InitConfigurationValues.sql"); MsSqlConfigurationHandler.Reset(TimeSpan.FromSeconds(10)); }