-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathConfigParserTests.cs
105 lines (90 loc) · 3.26 KB
/
ConfigParserTests.cs
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
using System;
using System.IO;
using System.Threading;
using Xunit;
namespace Salaros.Configuration.Tests
{
public class ConfigParserTests
{
[Fact]
public void ExistingFileIsUpdatedCorrectly()
{
var configFilePathTmp = Path.GetTempFileName();
File.WriteAllLines(configFilePathTmp, new[]
{
"[Settings]",
"Recno = chocolate"
});
var configFile = new ConfigParser(configFilePathTmp);
configFile.SetValue("Settings", "Recno", "123");
configFile.Save(configFilePathTmp);
Assert.Equal("[Settings]\r\nRecno = 123", configFile.ToString());
}
[Fact]
public void FileCanBeSavedToTheSamePath()
{
var configFilePathTmp = Path.GetTempFileName();
File.WriteAllLines(configFilePathTmp, new[]
{
"[Baz]",
"Foo = bar"
});
var dateModifiedOld = File.GetLastWriteTime(configFilePathTmp);
var configFile = new ConfigParser(configFilePathTmp);
configFile.Save();
Assert.True(File.GetLastWriteTime(configFilePathTmp).Ticks >= dateModifiedOld.Ticks);
}
[Fact]
public void FileCanBeSavedToNewPath()
{
var configFilePathTmp = Path.GetTempFileName();
File.WriteAllLines(configFilePathTmp, new[]
{
"[Baz]",
"Foo = bar"
});
var configFile = new ConfigParser(configFilePathTmp);
var configFilePathTmpNew = Path.GetTempFileName();
configFile.Save(configFilePathTmpNew);
Assert.True(File.Exists(configFilePathTmpNew));
}
[Fact]
public void ArrayIsReadCorrectly()
{
// Set up
var settings = new ConfigParserSettings { MultiLineValues = MultiLineValues.Simple | MultiLineValues.QuoteDelimitedValues };
var configFile = new ConfigParser(
@"[Advanced]
Select =
select * from
from table
where ID = '5'
",
settings);
// Act
var arrayValues = configFile.GetArrayValue("Advanced", "Select");
// Assert
Assert.Equal(3, arrayValues?.Length ?? 0);
Assert.Equal("select * from", arrayValues[0]);
Assert.Equal("from table", arrayValues[1]);
Assert.Equal("where ID = '5'", arrayValues[2]);
}
[Fact]
public void JoinMultilineValueWorks()
{
// Set up
var settings = new ConfigParserSettings { MultiLineValues = MultiLineValues.Simple };
var configFile = new ConfigParser(
@"[Advanced]
ExampleValue = Lorem ipsum dolor sit amet
consectetur adipiscing elit
sed do eiusmod tempor incididunt
",
settings);
// Act
var multiLineJoint = configFile.JoinMultilineValue("Advanced", "ExampleValue", " ");
// Assert
Assert.Equal("Lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt", multiLineJoint);
}
}
}