public void NotSavingMakesNoChanges() { EditorConfigFile editorConfigFile = PrepareTest("nochange", out string file, out string workingFile); const int TestSection = 0; const string TestPropertyKey = "testProperty"; const string TestPropertyValue = "testValue"; var iniProperty = new IniPropertyData(TestPropertyKey, TestPropertyValue); var sectionName = editorConfigFile.Sections[TestSection].Name; using (var editContext = editorConfigFile.Edit()) { editContext.Sections[sectionName].Add(iniProperty); } var originalText = File.ReadAllText(file); var copyText = File.ReadAllText(workingFile); originalText.Should().Be(copyText); }
public void AddWorks() { EditorConfigFile editorConfigFile = PrepareTest("add", out var file, out var workingFile); const int TestSection = 0; const string TestPropertyKey = "testProperty"; const string TestPropertyValue = "testValue"; var section = editorConfigFile.Sections[TestSection]; var sectionName = section.Name; // Find aftercomment property line editorConfigFile.TryGetProperty("aftercomment", section, out var prop).Should().BeTrue(); var lineNumber = prop !.LineNumber; var iniProperty = new IniPropertyData(TestPropertyKey, TestPropertyValue); using (var editContext = editorConfigFile.Edit(new EditorConfigFileOptions { EndSectionWithBlankLineOrComment = false })) { editContext.Sections[sectionName].Add(iniProperty); editContext.SaveChanges(); } editorConfigFile.TryGetProperty(TestPropertyKey, editorConfigFile.Sections[TestSection], out var updatedProperty).Should().BeTrue(); updatedProperty !.Data.Value.Should().Be(TestPropertyValue); // Use the original value rather than re-reading the property. This ensures that the file is otherwise unchanged updatedProperty !.LineNumber.Should().Be(lineNumber + 1); // Confirm the file is one line longer var fileLength = File.ReadAllLines(file).Length; var workingFileLength = File.ReadAllLines(workingFile).Length; workingFileLength.Should().Be(fileLength + 1); }