public void LoadAppSettingsFromDisk() { // instantiate default memory model var model = AppSettingsRepository.GetDefaultApplicationSettings(); model.ImageFormatExtension = ".webp"; model.InputDirectory = GlobalUnitTestConfig.TestDataInputPath; model.OutputDirectory = GlobalUnitTestConfig.TempDataPath; Assert.IsNotNull(model.FormStateModels, "AppSettingsRepository failed to create valied default config", nameof(model.FormStateModels)); Assert.IsTrue(_repository.SaveSettings(model), "Failed to Save default Settings"); var loadedSettings = _repository.LoadSettings(); Assert.IsNotNull(loadedSettings, "Loaded Settings where null."); // Do not compare form state dictionaries. model.FormStateModels = loadedSettings.FormStateModels; // Test each property bool modelEquals = model.Equals(loadedSettings); Assert.IsTrue(modelEquals, "model.Equals(loadedSettings) The loaded model where not identical to the saved model"); }
public void SaveAppSettingsToDisk() { var model = AppSettingsRepository.GetDefaultApplicationSettings(); model.InputDirectory = GlobalUnitTestConfig.TestDataInputPath; model.OutputDirectory = GlobalUnitTestConfig.TempDataPath; var result = _repository.SaveSettings(model); Assert.IsTrue(result, "Save AppSettingsFailed"); var fi = new FileInfo(Path.Combine(model.OutputDirectory, GlobalUnitTestConfig.AppSettingsFilename)); Log.Information("Saving App settings in: " + Path.GetFullPath(fi.FullName)); Assert.IsTrue(fi.Exists, "Could not find ImageConverterSettings.bin at: " + fi.FullName); }
public ApplicationSettingsService(AppSettingsRepository appSettingsRepository) { _appSettingsRepository = appSettingsRepository; try { _applicationSettings = _appSettingsRepository.LoadSettings(); if (_applicationSettings == null) { _applicationSettings = AppSettingsRepository.GetDefaultApplicationSettings(); _appSettingsRepository.SaveSettings(_applicationSettings); } } catch (Exception ex) { Log.Error(ex, "Fatal error encountered when accessing the registry settings"); throw new IOException("Application Settings could not be loaded and could not be set to default and saved"); } _appSettingsRepository.LoadSettingsCompleted += _appSettingsFileRepository_LoadSettingsCompleted; }