public void GetConfig_CanLoadConfigsFromMultipleThreads() { const string configKey = "MyCustomConfig"; var configLoader = new FakeLoader(false, true); var configRepository = new ConfigRepository(configLoader); const int maxThreads = 10; Exception ex = null; IConfig config = null; var getConfigCompletedEvent = new ManualResetEvent(false); for(int i = 0; i < maxThreads; i++) { int remainingThreads = i; ThreadPool.QueueUserWorkItem(s => { try { config = configRepository.GetConfig(configKey, false); if(Interlocked.Decrement(ref remainingThreads) == 0) { getConfigCompletedEvent.Set(); } } catch(Exception innerEx) { getConfigCompletedEvent.Set(); ex = innerEx; throw; } }); } getConfigCompletedEvent.WaitOne(); getConfigCompletedEvent.Close(); Assert.IsNotNull(config); Assert.IsNull(ex); }
public async Task It_logs_error_when_file_access_fails_during_runtime() { var errorCallbackInvoked = false; var timer = new FakeTimer(ex => { errorCallbackInvoked = true; }); var fail = false; var loader = new FakeLoader(() => { if (fail) { throw new Exception("Simulated"); } return(XDocument.Parse(@"<endpoints><endpoint name=""A""><instance/></endpoint></endpoints>")); }); var monitor = new InstanceMappingFileMonitor(TimeSpan.Zero, timer, loader, new EndpointInstances()); await monitor.Start(null); fail = true; await timer.Trigger(); Assert.IsTrue(errorCallbackInvoked); }
public void GetConfig_CanLoadConfigsFromMultipleThreads() { const string configKey = "MyCustomConfig"; var configLoader = new FakeLoader(false, true); var configRepository = new ConfigRepository(configLoader); const int maxThreads = 10; Exception ex = null; IConfig config = null; var getConfigCompletedEvent = new ManualResetEvent(false); for (int i = 0; i < maxThreads; i++) { int remainingThreads = i; ThreadPool.QueueUserWorkItem(s => { try { config = configRepository.GetConfig(configKey, false); if (Interlocked.Decrement(ref remainingThreads) == 0) { getConfigCompletedEvent.Set(); } } catch (Exception innerEx) { getConfigCompletedEvent.Set(); ex = innerEx; throw; } }); } getConfigCompletedEvent.WaitOne(); getConfigCompletedEvent.Close(); Assert.IsNotNull(config); Assert.IsNull(ex); }
public void GetConfig_LoadConfigForCustomAssemblyDoesNotExist_ThrowsConfigurationException() { Assembly assembly = typeof(FakeItEasy.A).Assembly; var configLoader = new FakeLoader(true); var configRepository = new ConfigRepository(configLoader); Assert.Throws<ConfigurationException>(() => configRepository.GetConfig(assembly)); Assert.AreEqual(assembly.GetName().Name, configLoader.ConfigKeysLoaded[0]); }
public void GetConfig_LoadCurrentConfigThatDoesNotExistAndSupressExceptions_ReturnsNull() { var configLoader = new FakeLoader(true); var configRepository = new ConfigRepository(configLoader); IConfig config = configRepository.GetConfig(true); Assert.IsNull(config); Assert.AreEqual("nJupiter.Configuration.Tests.Unit", configLoader.ConfigKeysLoaded[0]); }
public void GetConfig_LoadConfigForCustomAssembly_ReturnsConfigWithCorrectSystemConfigKey() { Assembly assembly = typeof(FakeItEasy.A).Assembly; var configLoader = new FakeLoader(); var configRepository = new ConfigRepository(configLoader); IConfig config = configRepository.GetConfig(assembly); Assert.AreEqual(assembly.GetName().Name, config.ConfigKey); }
public void GetSystemConfig_CreateConfigRepositoryWithDefaultValuesAndLoadSystemConfig_ReturnsConfigWithCorrectSystemConfigKey() { var configLoader = new FakeLoader(); var configRepository = new ConfigRepository(configLoader); IConfig config = configRepository.GetSystemConfig(); Assert.AreEqual("System", config.ConfigKey); }
public void GetAppConfig_CreateConfigRepositoryWithDefaultValuesAndLoadAppConfig_ReturnsConfigWithCorrectAppConfigKey() { var configLoader = new FakeLoader(false); var configRepository = new ConfigRepository(configLoader); IConfig config = configRepository.GetAppConfig(); Assert.AreEqual("nJupiter.Configuration.Tests.Integration.dll", config.ConfigKey); }
public void GetConfig_LoadCurrentConfig_ReturnsConfigWithCorrectSystemConfigKey() { var configLoader = new FakeLoader(); var configRepository = new ConfigRepository(configLoader); IConfig config = configRepository.GetConfig(); Assert.AreEqual("nJupiter.Configuration.Tests.Unit", config.ConfigKey); }
public void GetConfig_LoadCurrentConfigThatDoesNotExist_ThrowsConfigurationException() { var configLoader = new FakeLoader(true); var configRepository = new ConfigRepository(configLoader); Assert.Throws <ConfigurationException>(() => configRepository.GetConfig()); Assert.AreEqual("nJupiter.Configuration.Tests.Unit", configLoader.ConfigKeysLoaded[0]); }
public void GetConfig_LoadConfigForCustomAssemblyDoesNotExistAndSupressExceptions_ReturnsNull() { Assembly assembly = typeof(FakeItEasy.A).Assembly; var configLoader = new FakeLoader(true); var configRepository = new ConfigRepository(configLoader); IConfig config = configRepository.GetConfig(assembly, true); Assert.IsNull(config); Assert.AreEqual(assembly.GetName().Name, configLoader.ConfigKeysLoaded[0]); }
public void GetSystemConfig_CreateConfigRepositoryWithCustomValuesAndLoadSystemConfig_ReturnsConfigWithCorrectSystemConfigKey() { var configLoader = new FakeLoader(); var configRepository = new ConfigRepository(configLoader, "CustomSystemKey", "CustomAppKey"); IConfig config = configRepository.GetSystemConfig(); Assert.AreEqual("CustomSystemKey", config.ConfigKey); }
public void GetConfig_LoadConfigForCustomConfig_ReturnsConfigWithCorrectSystemConfigKey() { const string configKey = "MyCustomConfig"; var configLoader = new FakeLoader(); var configRepository = new ConfigRepository(configLoader); IConfig config = configRepository.GetConfig(configKey); Assert.AreEqual(configKey, config.ConfigKey); }
public void Should_log_added_endpoints() { var loader = new FakeLoader(() => XDocument.Parse(@"<endpoints><endpoint name=""A""><instance discriminator=""1"" /><instance discriminator=""2"" /></endpoint></endpoints>")); var monitor = new InstanceMappingFileMonitor(TimeSpan.Zero, new FakeTimer(), loader, new EndpointInstances()); monitor.ReloadData(); Assert.That(logOutput.ToString(), Does.Contain(@"Added endpoint 'A' with 2 instances")); }
public void GetConfig_LoadConfigForCustomConfigDoesNotExist_ThrowsConfigurationException() { const string configKey = "MyCustomConfig"; var configLoader = new FakeLoader(true); var configRepository = new ConfigRepository(configLoader); Assert.Throws <ConfigurationException>(() => configRepository.GetConfig(configKey)); Assert.AreEqual(configKey, configLoader.ConfigKeysLoaded[0]); }
public void GetConfig_LoadConfigForCustomAssemblyDoesNotExist_ThrowsConfigurationException() { Assembly assembly = typeof(FakeItEasy.A).Assembly; var configLoader = new FakeLoader(true); var configRepository = new ConfigRepository(configLoader); Assert.Throws <ConfigurationException>(() => configRepository.GetConfig(assembly)); Assert.AreEqual(assembly.GetName().Name, configLoader.ConfigKeysLoaded[0]); }
public void GetConfig_LoadConfigForCustomConfigDoesNotExistAndSupressExceptions_ReturnsNull() { const string configKey = "MyCustomConfig"; var configLoader = new FakeLoader(true); var configRepository = new ConfigRepository(configLoader); IConfig config = configRepository.GetConfig(configKey, true); Assert.IsNull(config); Assert.AreEqual(configKey, configLoader.ConfigKeysLoaded[0]); }
public void GetConfig_GetSameConfigTwice_ReturnsSameConfig() { var configLoader = new FakeLoader(); var configRepository = new ConfigRepository(configLoader); IConfig config1 = configRepository.GetConfig("myConfig"); Assert.IsTrue(configRepository.Configurations.Contains("myConfig")); IConfig config2 = configRepository.GetConfig("myConfig"); Assert.AreEqual(config1, config2); }
private void SetupApplication() { IDataLoader dataLoader = new FakeLoader(); //IDataLoader dataLoader = new ObjectLoader($"{ _currentDirectory }\\DelegationData.ddc"); _dataCollection = DataAccess.GetCollection(dataLoader); //DataAccess.SaveCollection(_dataCollection, dataLoader); KilometersCard_ComboBox.ItemsSource = _dataCollection.KilometersCards; KilometersCard_ComboBox.SelectedItem = _dataCollection.KilometersCards.FirstOrDefault(); projects_ComboBox.ItemsSource = _dataCollection.Projects; projects_ComboBox.SelectedItem = _dataCollection.Projects.FirstOrDefault(); }
public void Should_log_removed_endpoints() { var fileData = new Queue <string>(); fileData.Enqueue(@"<endpoints><endpoint name=""A""><instance discriminator=""1"" /><instance discriminator=""2"" /></endpoint></endpoints>"); fileData.Enqueue("<endpoints></endpoints>"); var loader = new FakeLoader(() => XDocument.Parse(fileData.Dequeue())); var monitor = new InstanceMappingFileMonitor(TimeSpan.Zero, new FakeTimer(), loader, new EndpointInstances()); monitor.ReloadData(); logOutput.Clear(); monitor.ReloadData(); Assert.That(logOutput.ToString(), Does.Contain(@"Removed all instances of endpoint 'A'")); }
public void GetConfig_LoadConfigForCustomConfigDoesNotExist_ThrowsConfigurationException() { const string configKey = "MyCustomConfig"; var configLoader = new FakeLoader(true); var configRepository = new ConfigRepository(configLoader); Assert.Throws<ConfigurationException>(() => configRepository.GetConfig(configKey)); Assert.AreEqual(configKey, configLoader.ConfigKeysLoaded[0]); }
public void GetConfig_LoadCurrentConfigThatDoesNotExist_ThrowsConfigurationException() { var configLoader = new FakeLoader(true); var configRepository = new ConfigRepository(configLoader); Assert.Throws<ConfigurationException>(() => configRepository.GetConfig()); Assert.AreEqual("nJupiter.Configuration.Tests.Unit", configLoader.ConfigKeysLoaded[0]); }