/// <summary> /// Writes settings to a disk file. /// </summary> public void Save(string filePath = null) { lock (_lock) { SourceFile = filePath ?? SourceFile; if (SourceFile == null) { throw new InvalidOperationException("Either settings must have been previously loaded from the existing file or a file name must be provided"); } if (Count > 0) { using (var sw = new StreamWriter(SourceFile)) { using (var csw = new ConfigurationSettingsWriter(sw)) { csw.SaveSettings(this); } } } } }
private void LoadAndWrite(string originalContent, string expectedContent) { IReadOnlyList<IConfigurationSetting> settings; var sr = new StreamReader(ToStream(originalContent)); using (var csr = new ConfigurationSettingsReader(sr)) { settings = csr.LoadSettings(); } var stream = new MemoryStream(); using (var csw = new ConfigurationSettingsWriter(new StreamWriter(stream))) { csw.SaveSettings(settings); stream.Seek(0, SeekOrigin.Begin); using (var r = new StreamReader(stream)) { var s = r.ReadToEnd(); s.Should().StartWith(Resources.SettingsFileHeader); s.Should().Contain(expectedContent); } } }