dependabot-nuget 0.309.0 → 0.310.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,13 +10,13 @@ namespace NuGetUpdater.Core.Test
10
10
  {
11
11
  public class TestHttpServer : IDisposable
12
12
  {
13
- private readonly Func<string, (int, byte[])> _requestHandler;
13
+ private readonly Func<string, string, (int, byte[])> _requestHandler;
14
14
  private readonly HttpListener _listener;
15
15
  private bool _runServer = true;
16
16
 
17
17
  public string BaseUrl { get; }
18
18
 
19
- private TestHttpServer(string baseurl, Func<string, (int, byte[])> requestHandler)
19
+ private TestHttpServer(string baseurl, Func<string, string, (int, byte[])> requestHandler)
20
20
  {
21
21
  BaseUrl = baseurl;
22
22
  _requestHandler = requestHandler;
@@ -43,7 +43,7 @@ namespace NuGetUpdater.Core.Test
43
43
  while (_runServer)
44
44
  {
45
45
  var context = await _listener.GetContextAsync();
46
- var (statusCode, response) = _requestHandler(context.Request.Url!.AbsoluteUri);
46
+ var (statusCode, response) = _requestHandler(context.Request.HttpMethod, context.Request.Url!.AbsoluteUri);
47
47
  context.Response.StatusCode = statusCode;
48
48
  await context.Response.OutputStream.WriteAsync(response);
49
49
  context.Response.Close();
@@ -53,6 +53,11 @@ namespace NuGetUpdater.Core.Test
53
53
  private static readonly object PortGate = new();
54
54
 
55
55
  public static TestHttpServer CreateTestServer(Func<string, (int, byte[])> requestHandler)
56
+ {
57
+ return CreateTestServer((method, url) => requestHandler(url));
58
+ }
59
+
60
+ public static TestHttpServer CreateTestServer(Func<string, string, (int, byte[])> requestHandler)
56
61
  {
57
62
  // static lock to ensure the port is not recycled after `FindFreePort()` and before we can start the real server
58
63
  lock (PortGate)
@@ -67,9 +72,14 @@ namespace NuGetUpdater.Core.Test
67
72
 
68
73
  public static TestHttpServer CreateTestStringServer(Func<string, (int, string)> requestHandler)
69
74
  {
70
- Func<string, (int, byte[])> bytesRequestHandler = url =>
75
+ return CreateTestStringServer((method, url) => requestHandler(url));
76
+ }
77
+
78
+ public static TestHttpServer CreateTestStringServer(Func<string, string, (int, string)> requestHandler)
79
+ {
80
+ Func<string, string, (int, byte[])> bytesRequestHandler = (method, url) =>
71
81
  {
72
- var (statusCode, response) = requestHandler(url);
82
+ var (statusCode, response) = requestHandler(method, url);
73
83
  return (statusCode, Encoding.UTF8.GetBytes(response));
74
84
  };
75
85
  return CreateTestServer(bytesRequestHandler);
@@ -170,7 +180,7 @@ namespace NuGetUpdater.Core.Test
170
180
  return (404, Encoding.UTF8.GetBytes("{}"));
171
181
  }
172
182
 
173
- var server = TestHttpServer.CreateTestServer(HttpHandler);
183
+ var server = CreateTestServer((method, url) => HttpHandler(url));
174
184
  return server;
175
185
  }
176
186
 
@@ -4,20 +4,234 @@ using Xunit;
4
4
 
5
5
  using static NuGetUpdater.Core.Utilities.EOLHandling;
6
6
 
7
- namespace NuGetUpdater.Core.Test.Utilities
7
+ namespace NuGetUpdater.Core.Test.Utilities;
8
+
9
+ public class EOLHandlingTests
8
10
  {
9
- public class EOLHandlingTests
11
+ [Theory]
12
+ [InlineData(EOLType.LF, "\n")]
13
+ [InlineData(EOLType.CR, "\r")]
14
+ [InlineData(EOLType.CRLF, "\r\n")]
15
+ public void ValidateEOLNormalizesFromLF(EOLType eolType, string literal)
16
+ {
17
+ var teststring = "this\ris\na\r\nstring\rwith\nmixed\r\nline\rendings\n.";
18
+ var changed = teststring.SetEOL(eolType);
19
+ var lineEndings = Regex.Split(changed, "\\S+");
20
+ Assert.All(lineEndings, lineEnding => lineEnding.Equals(literal));
21
+ }
22
+
23
+ [Theory]
24
+ [MemberData(nameof(GetPredominantEOLTestData))]
25
+ public void GetPredominantEOL(string fileContent, EOLType expectedEOL)
26
+ {
27
+ var actualEOL = fileContent.GetPredominantEOL();
28
+ Assert.Equal(expectedEOL, actualEOL);
29
+ }
30
+
31
+ [Theory]
32
+ [MemberData(nameof(SetEOLTestData))]
33
+ public void SetEOL(string currentFileContent, EOLType desiredEOL, string expectedFileContent)
34
+ {
35
+ var actualFileContent = currentFileContent.SetEOL(desiredEOL);
36
+ Assert.Equal(expectedFileContent, actualFileContent);
37
+ }
38
+
39
+ public static IEnumerable<object[]> GetPredominantEOLTestData()
10
40
  {
11
- [Theory]
12
- [InlineData(EOLType.LF, "\n")]
13
- [InlineData(EOLType.CR, "\r")]
14
- [InlineData(EOLType.CRLF, "\r\n")]
15
- public void ValidateEOLNormalizesFromLF(EOLType eolType, string literal)
16
- {
17
- var teststring = "this\ris\na\r\nstring\rwith\nmixed\r\nline\rendings\n.";
18
- var changed = teststring.SetEOL(eolType);
19
- var lineEndings = Regex.Split(changed, "\\S+");
20
- Assert.All(lineEndings, lineEnding => lineEnding.Equals(literal));
21
- }
41
+ // purely CR
42
+ yield return
43
+ [
44
+ // fileContent
45
+ string.Concat(
46
+ "line1\r",
47
+ "line2\r",
48
+ "line3\r"
49
+ ),
50
+ // expectedEOL
51
+ EOLType.CR
52
+ ];
53
+
54
+ // purely LF
55
+ yield return
56
+ [
57
+ // fileContent
58
+ string.Concat(
59
+ "line1\n",
60
+ "line2\n",
61
+ "line3\n"
62
+ ),
63
+ // expectedEOL
64
+ EOLType.LF
65
+ ];
66
+
67
+ // purely CRLF
68
+ yield return
69
+ [
70
+ // fileContent
71
+ string.Concat(
72
+ "line1\r\n",
73
+ "line2\r\n",
74
+ "line3\r\n"
75
+ ),
76
+ // expectedEOL
77
+ EOLType.CRLF
78
+ ];
79
+
80
+ // mostly CR
81
+ yield return
82
+ [
83
+ // fileContent
84
+ string.Concat(
85
+ "line1\r",
86
+ "line2\n",
87
+ "line3\r"
88
+ ),
89
+ // expectedEOL
90
+ EOLType.CR
91
+ ];
92
+
93
+ // mostly LF
94
+ yield return
95
+ [
96
+ // fileContent
97
+ string.Concat(
98
+ "line1\n",
99
+ "line2\r",
100
+ "line3\n"
101
+ ),
102
+ // expectedEOL
103
+ EOLType.LF
104
+ ];
105
+
106
+ // mostly CRLF
107
+ yield return
108
+ [
109
+ // fileContent
110
+ string.Concat(
111
+ "line1\r\n",
112
+ "line2\n",
113
+ "line3\r",
114
+ "line4\r\n"
115
+ ),
116
+ // expectedEOL
117
+ EOLType.CRLF
118
+ ];
119
+ }
120
+
121
+ public static IEnumerable<object[]> SetEOLTestData()
122
+ {
123
+ // CR to CR
124
+ yield return
125
+ [
126
+ // currentFileContent
127
+ string.Concat(
128
+ "line1\r",
129
+ "line2\r",
130
+ "line3\r"
131
+ ),
132
+ // desiredEOL
133
+ EOLType.CR,
134
+ // expectedFileContent
135
+ string.Concat(
136
+ "line1\r",
137
+ "line2\r",
138
+ "line3\r"
139
+ )
140
+ ];
141
+
142
+ // LF to LF
143
+ yield return
144
+ [
145
+ // currentFileContent
146
+ string.Concat(
147
+ "line1\n",
148
+ "line2\n",
149
+ "line3\n"
150
+ ),
151
+ // desiredEOL
152
+ EOLType.LF,
153
+ // expectedFileContent
154
+ string.Concat(
155
+ "line1\n",
156
+ "line2\n",
157
+ "line3\n"
158
+ )
159
+ ];
160
+
161
+ // CRLF to CRLF
162
+ yield return
163
+ [
164
+ // currentFileContent
165
+ string.Concat(
166
+ "line1\r\n",
167
+ "line2\r\n",
168
+ "line3\r\n"
169
+ ),
170
+ // desiredEOL
171
+ EOLType.CRLF,
172
+ // expectedFileContent
173
+ string.Concat(
174
+ "line1\r\n",
175
+ "line2\r\n",
176
+ "line3\r\n"
177
+ )
178
+ ];
179
+
180
+ // mixed to CR
181
+ yield return
182
+ [
183
+ // currentFileContent
184
+ string.Concat(
185
+ "line1\r",
186
+ "line2\n",
187
+ "line3\r\n"
188
+ ),
189
+ // desiredEOL
190
+ EOLType.CR,
191
+ // expectedFileContent
192
+ string.Concat(
193
+ "line1\r",
194
+ "line2\r",
195
+ "line3\r"
196
+ )
197
+ ];
198
+
199
+ // mixed to LF
200
+ yield return
201
+ [
202
+ // currentFileContent
203
+ string.Concat(
204
+ "line1\r",
205
+ "line2\n",
206
+ "line3\r\n"
207
+ ),
208
+ // desiredEOL
209
+ EOLType.LF,
210
+ // expectedFileContent
211
+ string.Concat(
212
+ "line1\n",
213
+ "line2\n",
214
+ "line3\n"
215
+ )
216
+ ];
217
+
218
+ // mixed to CRLF
219
+ yield return
220
+ [
221
+ // currentFileContent
222
+ string.Concat(
223
+ "line1\r",
224
+ "line2\n",
225
+ "line3\r\n"
226
+ ),
227
+ // desiredEOL
228
+ EOLType.CRLF,
229
+ // expectedFileContent
230
+ string.Concat(
231
+ "line1\r\n",
232
+ "line2\r\n",
233
+ "line3\r\n"
234
+ )
235
+ ];
22
236
  }
23
237
  }