forked from microsoft/scalar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigVerbTests.cs
More file actions
170 lines (144 loc) · 6.12 KB
/
ConfigVerbTests.cs
File metadata and controls
170 lines (144 loc) · 6.12 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
using NUnit.Framework;
using Scalar.FunctionalTests.Tools;
using Scalar.Tests.Should;
using System;
using System.Collections.Generic;
namespace Scalar.FunctionalTests.Tests.MultiEnlistmentTests
{
[TestFixture]
[Category(Categories.NeedsUpdatesForNonVirtualizedMode)]
public class ConfigVerbTests : TestsWithMultiEnlistment
{
private const string IntegerSettingKey = "functionalTest_Integer";
private const string FloatSettingKey = "functionalTest_Float";
private const string RegularStringSettingKey = "functionalTest_RegularString";
private const string SpacedStringSettingKey = "functionalTest_SpacedString";
private const string SpacesOnlyStringSettingKey = "functionalTest_SpacesOnlyString";
private const string EmptyStringSettingKey = "functionalTest_EmptyString";
private const string NonExistentSettingKey = "functionalTest_NonExistentSetting";
private const int GenericErrorExitCode = 3;
private readonly Dictionary<string, string> initialSettings = new Dictionary<string, string>()
{
{ IntegerSettingKey, "213" },
{ FloatSettingKey, "213.15" },
{ RegularStringSettingKey, "foobar" },
{ SpacedStringSettingKey, "quick brown fox" }
};
private readonly Dictionary<string, string> updateSettings = new Dictionary<string, string>()
{
{ IntegerSettingKey, "32123" },
{ FloatSettingKey, "3.14159" },
{ RegularStringSettingKey, "helloWorld!" },
{ SpacedStringSettingKey, "jumped over lazy dog" }
};
[OneTimeSetUp]
public void ResetTestConfig()
{
this.DeleteSettings(this.initialSettings);
this.DeleteSettings(this.updateSettings);
}
[TestCase, Order(1)]
public void CreateSettings()
{
this.ApplySettings(this.initialSettings);
this.ConfigShouldContainSettings(this.initialSettings);
}
[TestCase, Order(2)]
public void UpdateSettings()
{
this.ApplySettings(this.updateSettings);
this.ConfigShouldContainSettings(this.updateSettings);
}
[TestCase, Order(3)]
public void ListSettings()
{
this.ConfigShouldContainSettings(this.updateSettings);
}
[TestCase, Order(4)]
public void ReadSingleSetting()
{
foreach (KeyValuePair<string, string> setting in this.updateSettings)
{
string value = this.RunConfigCommand($"{setting.Key}");
value.TrimEnd(Environment.NewLine.ToCharArray()).ShouldEqual($"{setting.Value}");
}
}
[TestCase, Order(5)]
public void AddSpaceValueSetting()
{
string writeSpacesValue = " ";
this.WriteSetting(SpacesOnlyStringSettingKey, writeSpacesValue);
string readSpacesValue = this.ReadSetting($"{SpacesOnlyStringSettingKey}");
readSpacesValue.TrimEnd(Environment.NewLine.ToCharArray()).ShouldEqual(writeSpacesValue);
}
[TestCase, Order(6)]
public void AddNullValueSetting()
{
string writeEmptyValue = string.Empty;
this.WriteSetting(EmptyStringSettingKey, writeEmptyValue, GenericErrorExitCode);
string readEmptyValue = this.ReadSetting(EmptyStringSettingKey, GenericErrorExitCode);
readEmptyValue.ShouldBeEmpty();
}
[TestCase, Order(7)]
public void ReadNonExistentSetting()
{
string nonExistentValue = this.ReadSetting(NonExistentSettingKey, GenericErrorExitCode);
nonExistentValue.ShouldBeEmpty();
}
[TestCase, Order(8)]
public void DeleteSettings()
{
this.DeleteSettings(this.updateSettings);
List<string> deletedLines = new List<string>();
foreach (KeyValuePair<string, string> setting in this.updateSettings)
{
deletedLines.Add(this.GetSettingLineInConfigFileFormat(setting));
}
string allSettings = this.RunConfigCommand("--list");
allSettings.ShouldNotContain(ignoreCase: true, unexpectedSubstrings: deletedLines.ToArray());
}
private void DeleteSettings(Dictionary<string, string> settings)
{
List<string> deletedLines = new List<string>();
foreach (KeyValuePair<string, string> setting in settings)
{
this.RunConfigCommand($"--delete {setting.Key}");
}
}
private void ConfigShouldContainSettings(Dictionary<string, string> expectedSettings)
{
List<string> expectedLines = new List<string>();
foreach (KeyValuePair<string, string> setting in expectedSettings)
{
expectedLines.Add(this.GetSettingLineInConfigFileFormat(setting));
}
string allSettings = this.RunConfigCommand("--list");
allSettings.ShouldContain(expectedLines.ToArray());
}
private string GetSettingLineInConfigFileFormat(KeyValuePair<string, string> setting)
{
return $"{setting.Key}={setting.Value}";
}
private void ApplySettings(Dictionary<string, string> settings)
{
foreach (KeyValuePair<string, string> setting in settings)
{
this.WriteSetting(setting.Key, setting.Value);
}
}
private void WriteSetting(string key, string value, int expectedExitCode = 0)
{
this.RunConfigCommand($"{key} \"{value}\"", expectedExitCode);
}
private string ReadSetting(string key, int expectedExitCode = 0)
{
return this.RunConfigCommand($"{key}", expectedExitCode);
}
private string RunConfigCommand(string argument, int expectedExitCode = 0)
{
ProcessResult result = ProcessHelper.Run(ScalarTestConfig.PathToScalar, $"config {argument}");
result.ExitCode.ShouldEqual(expectedExitCode, result.Errors);
return result.Output;
}
}
}