// ACT public override void Act(out object[] actual) { // Get 1st line var first_line = new PrivateProfileLine(this.RawLines[0]); // Get Null Section Flag var null_section = (first_line.LineType != PrivateProfileLineType.Section); // NEW Lines var lines = new PrivateProfileLine[this.RawLines.Length + (null_section ? 1 : 0)]; // Add Null Section Line if (null_section) { lines[0] = new PrivateProfileLine(null); } // for Lines for (int i = (null_section ? 1 : 0); i < lines.Length; i++) { // NEW Line lines[i] = new PrivateProfileLine(this.RawLines[i - (null_section ? 1 : 0)]); } // ACT: NEW Section var section = new PrivateProfileSection(lines); // GET Actual actual = SectionTestParameter.ConvertSectionToObjectArray(section); }
public override void Act(out object[] actual) { // New Section (ignoreDuplicatedEntry = true) var section = new PrivateProfileSection(true) { Name = this.Name }; // Append Entries foreach (var entry in this.Entries) { section.Append(new PrivateProfileLine() { Key = entry[0], Value = entry[1] }); } // Get Actual actual = SectionTestParameter.ConvertSectionToObjectArray(section); // Override Expected Length by Reming Entry var list = this.Entries.ToList(); list.RemoveAt(2); (this.Expected as object[])[1] = list.ToArray(); }
public void IgnoreDuplicatedEntryPropertyExceptionTest() { // New Section var section = new PrivateProfileSection { Name = "Test" }; // Append Entry section.Append(new PrivateProfileLine() { Key = "Key", Value = "Value" }); // Append Another Entry section.Append(new PrivateProfileLine() { Key = "Key1", Value = "Value1" }); // Append Same Entry (Exception) section.Append(new PrivateProfileLine() { Key = "Key", Value = "Value2" }); }
// ACT public override void Act(out object[] actual) { // ACT: NEW Section var section = new PrivateProfileSection(this.RawLines); // GET Actual actual = SectionTestParameter.ConvertSectionToObjectArray(section); }
// ARRANGE public override void Arrange(out object[] expected) { // BASE base.Arrange(out expected); // NEW Section this.Section = new PrivateProfileSection(this.BeforeRawLines); // Print Entries before change Console.WriteLine("Before Change:"); PrivateProfileSectionTests.PrintSection(this.Section); Console.WriteLine(); }
// ARRANGE public override void Arrange(out object[] expected) { // BASE base.Arrange(out expected); // NEW Section this.Section = new PrivateProfileSection(this.BeforeRawLines); // Print Section Name Console.WriteLine("Before Change:"); Console.WriteLine($"Section Name = \"{this.Section.Name}\""); Console.WriteLine(); }
// Print Section public static void PrintSection(PrivateProfileSection section) { // Print Section Name Console.WriteLine("Section Name = " + (section.Name is null ? "(null)" : $"\"{section.Name}\"")); // for Entries var i = 0; foreach (var key in section.Entries.Keys) { // Print Entry Console.WriteLine("Entries[{0}] = ({1}, {2})", i++, key, (section.Entries[key] is null ? "null" : $"\"{section.Entries[key]}\"")); } }
// GET Entries private Dictionary <string, string> GetPrivateProfileEntries(PrivateProfileSection section) { // NEW Dictionary (Entries) Dictionary <string, string> entries = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); // for Entries foreach (var key in section.Entries.Keys) { // ADD Entry entries.Add(key, section.Entries[key]); } // RETURN Entries return(entries); }
// Utility to convert Section into Object[] public static object[] ConvertSectionToObjectArray(PrivateProfileSection section) { // GET Entries string[][] entries = new string[section.Entries.Count][]; var i = 0; foreach (var key in section.Entries.Keys) { entries[i++] = new string[] { key, section.Entries[key] }; } // RETURN return(new object[] { section.Name, entries, section.GetRawLines() }); }