public void CreateNewSettings_Returns_New_Object() { // Arrange var testBundle = new SettingsRepositoryTestBundle(); var settingsRoot = new SettingsRoot(); testBundle.MockEntityProvider.Setup(x => x.ProvideDefaultSettingsRoot()).Returns(settingsRoot); // Act var settings = testBundle.SettingsManager.CreateNewSettings(); // Assert Assert.AreSame(settingsRoot, settings); testBundle.MockEntityProvider.Verify(x => x.ProvideDefaultSettingsRoot(), Times.Once); }
public SettingsRoot GetSettings() { try { _available.WaitOne(); } catch (AbandonedMutexException e) { _log.Warn("Failed to acquire semaphore lock when loading settings.", e); return(null); } try { // If the settings have already been populated then return them if (_settingsRoot != null) { _available.Release(); return(_settingsRoot); } _settingsRoot = _settingsRepository.Load(); if (_settingsRoot == null) { _settingsRoot = _settingsRepository.CreateNewSettings(); try { _settingsRepository.Save(_settingsRoot); } catch (Exception ex) { _log.Warn("Saving new settings failed.", ex); } } _available.Release(); } catch (Exception) { _available.Release(); throw; } return(_settingsRoot); }
public SettingsRoot GetSettings() { try { _available.WaitOne(); } catch (AbandonedMutexException e) { _log.Warn("Failed to acquire semaphore lock when loading settings.", e); return null; } try { // If the settings have already been populated then return them if (_settingsRoot != null) { _available.Release(); return _settingsRoot; } _settingsRoot = _settingsRepository.Load(); if (_settingsRoot == null) { _settingsRoot = _settingsRepository.CreateNewSettings(); try { _settingsRepository.Save(_settingsRoot); } catch (Exception ex) { _log.Warn("Saving new settings failed.", ex); } } _available.Release(); } catch (Exception) { _available.Release(); throw; } return _settingsRoot; }
public void Save_Writes_To_Serializer() { // Arrange var testBundle = new SettingsRepositoryTestBundle(); var mockLog = new Mock<ILog>(); var settings = new SettingsRoot(); testBundle.MockLogProvider.Setup(x => x.GetLogger(It.IsAny<Type>())).Returns(mockLog.Object); // Act testBundle.SettingsManager.Save(settings); // Assert testBundle.MockXmlSerializer.Verify(x => x.Serialize(It.IsAny<TextWriter>(), It.IsAny<object>()), Times.Once); }
public void Save_Wraps_SerializationException_As_IOException() { // Arrange var testBundle = new SettingsRepositoryTestBundle(); var mockLog = new Mock<ILog>(); var settings = new SettingsRoot(); var testException = new SerializationException("test exception"); IOException thrownException = null; testBundle.MockLogProvider.Setup(x => x.GetLogger(It.IsAny<Type>())).Returns(mockLog.Object); testBundle.MockXmlSerializer.Setup(x => x.Serialize(It.IsAny<TextWriter>(), It.IsAny<object>())).Throws(testException); // Act try { testBundle.SettingsManager.Save(settings); } catch (IOException ex) { thrownException = ex; } // Assert testBundle.MockXmlSerializer.Verify(x => x.Serialize(It.IsAny<TextWriter>(), It.IsAny<object>()), Times.Once); Assert.IsNotNull(thrownException); }
public SettingsRootTestBundle() { MockServiceLocator = new Mock<IEntityProvider>(); SettingsRoot = new SettingsRoot(MockServiceLocator.Object); }
public SettingsRoot ProvideDefaultSettingsRoot() { var settings = new SettingsRoot(this); settings.PopulateWithDefaults(); return settings; }