-
Notifications
You must be signed in to change notification settings - Fork 249
Expand file tree
/
Copy pathSectionCollectionTests.cs
More file actions
117 lines (89 loc) · 3.92 KB
/
SectionCollectionTests.cs
File metadata and controls
117 lines (89 loc) · 3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
using System.Collections.Generic;
using IniParser;
using IniParser.Model;
using NUnit.Framework;
namespace IniParser.Tests.Unit.Model
{
[TestFixture, Category("Test of data structures used to hold information retrieved for an INI file")]
public class SectionDataCollectionTests
{
[Test]
public void check_section_data_operations()
{
string strSectionTest = "MySection";
string strComment = "comment";
List<string> commentListTest = new List<string>(new string[] { "testComment 1", "testComment 2" });
//Creation
SectionCollection sdc = new SectionCollection();
Assert.That(sdc, Is.Empty);
//Add section
sdc.Add(strSectionTest);
sdc.Add(strSectionTest);
Assert.That(sdc.Count, Is.EqualTo(1));
//Check access
Assert.That(sdc.FindByName(strSectionTest), Is.Not.Null);
Assert.That(sdc.FindByName(strSectionTest).Comments, Is.Empty);
Assert.That(sdc.FindByName(strSectionTest).Properties.Count, Is.EqualTo(0));
//Check add comments
sdc.FindByName(strSectionTest).Comments.Add(strComment);
Assert.That(sdc.FindByName(strSectionTest).Comments.Count, Is.EqualTo(1));
sdc.FindByName(strSectionTest).Comments.Clear();
sdc.FindByName(strSectionTest).Comments.AddRange(commentListTest);
Assert.That(sdc.FindByName(strSectionTest).Comments.Count, Is.EqualTo(commentListTest.Count));
//Remove section
sdc.Remove("asdf");
Assert.That(sdc.Count, Is.EqualTo(1));
sdc.Remove(strSectionTest);
Assert.That(sdc.Count, Is.EqualTo(0));
//Check access
Assert.That(sdc[strSectionTest], Is.Null);
}
[Test]
public void check_remove_all_keys_in_section_without_deleting_the_section()
{
IniData data = new IniData();
data.Sections.Add("test");
data.Sections.Add("test2");
data["test"].Add("key1", "value1");
data["test"].Add("key2", "value2");
data["test2"].Add("key3", "value3");
data["test2"].Add("key4", "value4");
Assert.That(data["test"].Contains("key1"));
Assert.That(data["test"].Contains("key2"));
Assert.That(data["test2"].Contains("key3"));
Assert.That(data["test2"].Contains("key4"));
data.Sections.FindByName("test").ClearProperties();
Assert.That(data.Sections.Contains("test"));
Assert.That(data["test"].Contains("key1"), Is.False);
Assert.That(data["test"].Contains("key2"), Is.False);
data["test2"].Clear();
Assert.That(data.Sections.Contains("test2"));
Assert.That(data["test2"].Contains("key3"), Is.False);
Assert.That(data["test2"].Contains("key4"), Is.False);
}
[Test]
public void check_adding_sections_to_collection()
{
var col = new SectionCollection();
var exampleSection = new Section("section1");
exampleSection.Properties.Add("examplekey");
exampleSection.Properties["examplekey"] = "examplevalue";
col.Add(exampleSection);
Assert.That(col["section1"], Is.Not.Null);
// Add sections directly to the collection
Assert.That(col.Add("section2"), Is.True);
Assert.That(col.Add("section2"), Is.False);
Assert.That(col["section2"], Is.Not.Null);
}
[Test]
public void check_deep_clone()
{
var ori = new SectionCollection();
ori.Add("section1");
ori["section1"]["key1"] = "value1";
var copy = ori.DeepClone();
copy["section1"]["key1"] = "value2";
Assert.That(ori["section1"]["key1"], Is.EqualTo("value1"));
}
}
}