Skip to content

Commit b56ad61

Browse files
committed
make tests more readable with raw strings
1 parent 644c2b9 commit b56ad61

File tree

1 file changed

+113
-92
lines changed

1 file changed

+113
-92
lines changed

test/libman.Test/LibmanInstallTest.cs

Lines changed: 113 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Licensed to the .NET Foundation under one or more agreements.
22
// The .NET Foundation licenses this file to you under the MIT license.
33

4-
using System;
54
using System.IO;
65
using System.Linq;
76
using Microsoft.VisualStudio.TestTools.UnitTesting;
@@ -35,16 +34,18 @@ public void TestInstall_CleanDirectory()
3534
Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "libman.json")));
3635

3736
string text = File.ReadAllText(Path.Combine(WorkingDir, "libman.json"));
38-
string expectedText = @"{
39-
""version"": ""3.0"",
40-
""defaultProvider"": ""cdnjs"",
41-
""libraries"": [
42-
{
43-
""library"": ""[email protected]"",
44-
""destination"": ""wwwroot""
45-
}
46-
]
47-
}";
37+
string expectedText = """
38+
{
39+
"version": "3.0",
40+
"defaultProvider": "cdnjs",
41+
"libraries": [
42+
{
43+
"library": "[email protected]",
44+
"destination": "wwwroot"
45+
}
46+
]
47+
}
48+
""";
4849
Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(text));
4950
}
5051

@@ -63,16 +64,18 @@ public void TestInstall_CleanDirectory_WithPromptForProvider()
6364
Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "libman.json")));
6465

6566
string text = File.ReadAllText(Path.Combine(WorkingDir, "libman.json"));
66-
string expectedText = @"{
67-
""version"": ""3.0"",
68-
""defaultProvider"": ""cdnjs"",
69-
""libraries"": [
70-
{
71-
""library"": ""[email protected]"",
72-
""destination"": ""wwwroot""
73-
}
74-
]
75-
}";
67+
string expectedText = """
68+
{
69+
"version": "3.0",
70+
"defaultProvider": "cdnjs",
71+
"libraries": [
72+
{
73+
"library": "[email protected]",
74+
"destination": "wwwroot"
75+
}
76+
]
77+
}
78+
""";
7679
Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(text));
7780
}
7881

@@ -83,11 +86,13 @@ public void TestInstall_ExistingLibman_WithPromptForProvider()
8386

8487
testInputReader.Inputs.Add("ProviderId", "cdnjs");
8588

86-
string initialContent = @"{
87-
""version"": ""1.0"",
88-
""libraries"": [
89-
]
90-
}";
89+
string initialContent = """
90+
{
91+
"version": "1.0",
92+
"libraries": [
93+
]
94+
}
95+
""";
9196

9297
File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), initialContent);
9398
var command = new InstallCommand(HostEnvironment);
@@ -98,16 +103,18 @@ public void TestInstall_ExistingLibman_WithPromptForProvider()
98103
Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "libman.json")));
99104

100105
string text = File.ReadAllText(Path.Combine(WorkingDir, "libman.json"));
101-
string expectedText = @"{
102-
""version"": ""1.0"",
103-
""defaultProvider"": ""cdnjs"",
104-
""libraries"": [
105-
{
106-
""library"": ""[email protected]"",
107-
""destination"": ""wwwroot""
108-
}
109-
]
110-
}";
106+
string expectedText = """
107+
{
108+
"version": "1.0",
109+
"defaultProvider": "cdnjs",
110+
"libraries": [
111+
{
112+
"library": "[email protected]",
113+
"destination": "wwwroot"
114+
}
115+
]
116+
}
117+
""";
111118
Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(text));
112119
}
113120

@@ -118,13 +125,15 @@ public void TestInstall_WithExistingLibmanJson()
118125
var command = new InstallCommand(HostEnvironment);
119126
command.Configure(null);
120127

121-
string initialContent = @"{
122-
""version"": ""1.0"",
123-
""defaultProvider"": ""cdnjs"",
124-
""defaultDestination"": ""wwwroot"",
125-
""libraries"": [
126-
]
127-
}";
128+
string initialContent = """
129+
{
130+
"version": "1.0",
131+
"defaultProvider": "cdnjs",
132+
"defaultDestination": "wwwroot",
133+
"libraries": [
134+
]
135+
}
136+
""";
128137

129138
File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), initialContent);
130139

@@ -133,16 +142,18 @@ public void TestInstall_WithExistingLibmanJson()
133142
Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "libman.json")));
134143

135144
string actualText = File.ReadAllText(Path.Combine(WorkingDir, "libman.json"));
136-
string expectedText = @"{
137-
""version"": ""1.0"",
138-
""defaultProvider"": ""cdnjs"",
139-
""defaultDestination"": ""wwwroot"",
140-
""libraries"": [
141-
{
142-
""library"": ""[email protected]""
143-
}
144-
]
145-
}";
145+
string expectedText = """
146+
{
147+
"version": "1.0",
148+
"defaultProvider": "cdnjs",
149+
"defaultDestination": "wwwroot",
150+
"libraries": [
151+
{
152+
"library": "[email protected]"
153+
}
154+
]
155+
}
156+
""";
146157
Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(actualText));
147158
}
148159

@@ -152,16 +163,18 @@ public void TestInstall_Duplicate()
152163
var command = new InstallCommand(HostEnvironment);
153164
command.Configure(null);
154165

155-
string initialContent = @"{
156-
""version"": ""1.0"",
157-
""defaultProvider"": ""cdnjs"",
158-
""defaultDestination"": ""wwwroot"",
159-
""libraries"": [
160-
{
161-
""library"": ""[email protected]""
162-
}
163-
]
164-
}";
166+
string initialContent = """
167+
{
168+
"version": "1.0",
169+
"defaultProvider": "cdnjs",
170+
"defaultDestination": "wwwroot",
171+
"libraries": [
172+
{
173+
"library": "[email protected]"
174+
}
175+
]
176+
}
177+
""";
165178

166179
File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), initialContent);
167180

@@ -177,33 +190,37 @@ public void TestInstall_WithExistingLibmanJson_SpecificFiles()
177190
var command = new InstallCommand(HostEnvironment);
178191
command.Configure(null);
179192

180-
string initialContent = @"{
181-
""version"": ""1.0"",
182-
""defaultProvider"": ""cdnjs"",
183-
""defaultDestination"": ""wwwroot"",
184-
""libraries"": [
185-
]
186-
}";
193+
string initialContent = """
194+
{
195+
"version": "1.0",
196+
"defaultProvider": "cdnjs",
197+
"defaultDestination": "wwwroot",
198+
"libraries": [
199+
]
200+
}
201+
""";
187202

188203
File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), initialContent);
189204
command.Execute("[email protected]", "--files", "jquery.min.js");
190205

191206
Assert.IsTrue(File.Exists(Path.Combine(WorkingDir, "libman.json")));
192207

193208
string actualText = File.ReadAllText(Path.Combine(WorkingDir, "libman.json"));
194-
string expectedText = @"{
195-
""version"": ""1.0"",
196-
""defaultProvider"": ""cdnjs"",
197-
""defaultDestination"": ""wwwroot"",
198-
""libraries"": [
199-
{
200-
""library"": ""[email protected]"",
201-
""files"": [
202-
""jquery.min.js""
203-
]
204-
}
205-
]
206-
}";
209+
string expectedText = """
210+
{
211+
"version": "1.0",
212+
"defaultProvider": "cdnjs",
213+
"defaultDestination": "wwwroot",
214+
"libraries": [
215+
{
216+
"library": "[email protected]",
217+
"files": [
218+
"jquery.min.js"
219+
]
220+
}
221+
]
222+
}
223+
""";
207224
Assert.AreEqual(StringHelper.NormalizeNewLines(expectedText), StringHelper.NormalizeNewLines(actualText));
208225
}
209226

@@ -213,18 +230,22 @@ public void TestInstall_WithInvalidFiles()
213230
var command = new InstallCommand(HostEnvironment);
214231
command.Configure(null);
215232

216-
string initialContent = @"{
217-
""version"": ""1.0"",
218-
""defaultProvider"": ""cdnjs"",
219-
""defaultDestination"": ""wwwroot"",
220-
""libraries"": [
221-
]
222-
}";
233+
string initialContent = """
234+
{
235+
"version": "1.0",
236+
"defaultProvider": "cdnjs",
237+
"defaultDestination": "wwwroot",
238+
"libraries": [
239+
]
240+
}
241+
""";
223242

224243
File.WriteAllText(Path.Combine(WorkingDir, "libman.json"), initialContent);
225244
command.Execute("[email protected]", "--files", "abc.js");
226-
string expectedMessage = @"[LIB018]: ""[email protected]"" does not contain the following: abc.js
227-
Valid files are jquery.js, jquery.min.js, jquery.min.map, jquery.slim.js, jquery.slim.min.js, jquery.slim.min.map";
245+
string expectedMessage = """
246+
[LIB018]: "[email protected]" does not contain the following: abc.js
247+
Valid files are jquery.js, jquery.min.js, jquery.min.map, jquery.slim.js, jquery.slim.min.js, jquery.slim.min.map
248+
""";
228249

229250
var logger = HostEnvironment.Logger as TestLogger;
230251
Assert.AreEqual(expectedMessage, logger.Messages.Last().Value);

0 commit comments

Comments
 (0)