Skip to content

Commit 957368f

Browse files
committed
Fix warnings
1 parent f88f14d commit 957368f

File tree

10 files changed

+42
-50
lines changed

10 files changed

+42
-50
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<Copyright>Copyright (c) 2020, nventive</Copyright>
77
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
88
<Product>HttpRecorder</Product>
9-
<LangVersion>8.0</LangVersion>
9+
<LangVersion>10.0</LangVersion>
1010
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
1111
<WarningsAsErrors />
1212
<NoWarn>1701;1702;1998</NoWarn>

HttpRecorder.Tests/Anonymizers/RulesInteractionAnonymizerTests.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Linq;
43
using System.Net.Http;
54
using System.Threading.Tasks;
@@ -34,8 +33,8 @@ public async Task ItShouldAnonymizeRequestQueryStringParameter()
3433
.AnonymizeRequestQueryStringParameter("key");
3534

3635
var result = await anonymizer.Anonymize(interaction);
37-
result.Messages[0].Response.RequestMessage.RequestUri.ToString().Should().Be("http://first/");
38-
result.Messages[1].Response.RequestMessage.RequestUri.ToString().Should().Be($"https://second/?key={RulesInteractionAnonymizer.DefaultAnonymizerReplaceValue}&value=bar");
36+
result.Messages[0].Response.RequestMessage!.RequestUri!.ToString().Should().Be("http://first/");
37+
result.Messages[1].Response.RequestMessage!.RequestUri!.ToString().Should().Be($"https://second/?key={RulesInteractionAnonymizer.DefaultAnonymizerReplaceValue}&value=bar");
3938
}
4039

4140
[Fact]
@@ -51,10 +50,10 @@ public async Task ItShouldAnonymizeRequestHeader()
5150
.AnonymizeRequestHeader("X-RequestHeader");
5251

5352
var result = await anonymizer.Anonymize(interaction);
54-
result.Messages[0].Response.RequestMessage.Headers.GetValues("X-RequestHeader").First().Should().Be(RulesInteractionAnonymizer.DefaultAnonymizerReplaceValue);
53+
result.Messages[0].Response.RequestMessage!.Headers.GetValues("X-RequestHeader").First().Should().Be(RulesInteractionAnonymizer.DefaultAnonymizerReplaceValue);
5554
}
5655

57-
private Interaction BuildInteraction(params HttpRequestMessage[] requests)
56+
private static Interaction BuildInteraction(params HttpRequestMessage[] requests)
5857
{
5958
return new Interaction(
6059
"test",

HttpRecorder.Tests/ContextTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public async Task ItShouldWorkWithHttpRecorderContext()
3232
options.BaseAddress = _fixture.ServerUri;
3333
});
3434

35-
HttpResponseMessage passthroughResponse = null;
36-
using (var context = new HttpRecorderContext((sp, builder) => new HttpRecorderConfiguration
35+
HttpResponseMessage passthroughResponse;
36+
using (new HttpRecorderContext((_, _) => new HttpRecorderConfiguration
3737
{
3838
Mode = HttpRecorderMode.Record,
3939
InteractionName = nameof(ItShouldWorkWithHttpRecorderContext),
@@ -44,7 +44,7 @@ public async Task ItShouldWorkWithHttpRecorderContext()
4444
passthroughResponse.EnsureSuccessStatusCode();
4545
}
4646

47-
using (var context = new HttpRecorderContext((sp, builder) => new HttpRecorderConfiguration
47+
using (new HttpRecorderContext((_, _) => new HttpRecorderConfiguration
4848
{
4949
Mode = HttpRecorderMode.Replay,
5050
InteractionName = nameof(ItShouldWorkWithHttpRecorderContext),
@@ -70,8 +70,8 @@ public async Task ItShouldWorkWithHttpRecorderContextWhenNotRecording()
7070
options.BaseAddress = _fixture.ServerUri;
7171
});
7272

73-
HttpResponseMessage passthroughResponse = null;
74-
using (var context = new HttpRecorderContext((sp, builder) => new HttpRecorderConfiguration
73+
HttpResponseMessage passthroughResponse;
74+
using (new HttpRecorderContext((_, _) => new HttpRecorderConfiguration
7575
{
7676
Enabled = false,
7777
Mode = HttpRecorderMode.Record,
@@ -83,7 +83,7 @@ public async Task ItShouldWorkWithHttpRecorderContextWhenNotRecording()
8383
passthroughResponse.EnsureSuccessStatusCode();
8484
}
8585

86-
using (var context = new HttpRecorderContext((sp, builder) => new HttpRecorderConfiguration
86+
using (new HttpRecorderContext((_, _) => new HttpRecorderConfiguration
8787
{
8888
Mode = HttpRecorderMode.Replay,
8989
InteractionName = nameof(ItShouldWorkWithHttpRecorderContextWhenNotRecording),
@@ -99,7 +99,7 @@ public async Task ItShouldWorkWithHttpRecorderContextWhenNotRecording()
9999
public void ItShouldNotAllowMultipleContexts()
100100
{
101101
using var context = new HttpRecorderContext();
102-
Action act = () => { var ctx2 = new HttpRecorderContext(); };
102+
Action act = () => { _ = new HttpRecorderContext(); };
103103
act.Should().Throw<HttpRecorderException>().WithMessage("*multiple*");
104104
}
105105
}

HttpRecorder.Tests/HttpClientFactoryTests.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
1+
using System.Collections.Generic;
42
using System.Net.Http;
53
using System.Threading.Tasks;
64
using HttpRecorder.Tests.Server;

HttpRecorder.Tests/HttpRecorderIntegrationTests.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ await ExecuteModeIterations(async (client, mode) =>
4646
{
4747
passthroughResponse = response;
4848
var result = await response.Content.ReadFromJsonAsync<SampleModel>();
49-
result.Name.Should().Be(SampleModel.DefaultName);
49+
result!.Name.Should().Be(SampleModel.DefaultName);
5050
}
5151
else
5252
{
@@ -71,7 +71,7 @@ await ExecuteModeIterations(async (client, mode) =>
7171
{
7272
passthroughResponse = response;
7373
var result = await response.Content.ReadFromJsonAsync<SampleModel>();
74-
result.Name.Should().Be(name);
74+
result!.Name.Should().Be(name);
7575
}
7676
else
7777
{
@@ -97,7 +97,7 @@ await ExecuteModeIterations(async (client, mode) =>
9797
{
9898
passthroughResponse = response;
9999
var result = await response.Content.ReadFromJsonAsync<SampleModel>();
100-
result.Name.Should().Be(sampleModel.Name);
100+
result!.Name.Should().Be(sampleModel.Name);
101101
}
102102
else
103103
{
@@ -127,7 +127,7 @@ await ExecuteModeIterations(async (client, mode) =>
127127
{
128128
passthroughResponse = response;
129129
var result = await response.Content.ReadFromJsonAsync<SampleModel>();
130-
result.Name.Should().Be(sampleModel.Name);
130+
result!.Name.Should().Be(sampleModel.Name);
131131
}
132132
else
133133
{
@@ -165,7 +165,7 @@ await ExecuteModeIterations(async (client, mode) =>
165165
var response = responses[i];
166166
response.Should().BeSuccessful();
167167
var result = await response.Content.ReadFromJsonAsync<SampleModel>();
168-
result.Name.Should().Be($"{i}");
168+
result!.Name.Should().Be($"{i}");
169169
}
170170
}
171171
else
@@ -185,21 +185,17 @@ public async Task ItShouldExecuteMultipleRequestsInSequenceWithRecorderModeAuto(
185185
File.Delete(recordedFileName);
186186
}
187187

188-
var client = CreateHttpClient(
189-
HttpRecorderMode.Auto,
190-
nameof(ItShouldExecuteMultipleRequestsInSequenceWithRecorderModeAuto));
188+
var client = CreateHttpClient(HttpRecorderMode.Auto);
191189
var response1 = await client.GetAsync($"{ApiController.JsonUri}?name=1");
192190
var response2 = await client.GetAsync($"{ApiController.JsonUri}?name=2");
193191
var result1 = await response1.Content.ReadFromJsonAsync<SampleModel>();
194-
result1.Name.Should().Be("1");
192+
result1!.Name.Should().Be("1");
195193

196194
var result2 = await response2.Content.ReadFromJsonAsync<SampleModel>();
197-
result2.Name.Should().Be("2");
195+
result2!.Name.Should().Be("2");
198196

199197
// We resolve to replay at this point.
200-
client = CreateHttpClient(
201-
HttpRecorderMode.Auto,
202-
nameof(ItShouldExecuteMultipleRequestsInSequenceWithRecorderModeAuto));
198+
client = CreateHttpClient(HttpRecorderMode.Auto);
203199
var response2_1 = await client.GetAsync($"{ApiController.JsonUri}?name=1");
204200
var response2_2 = await client.GetAsync($"{ApiController.JsonUri}?name=2");
205201

HttpRecorder.Tests/Matchers/RulesMatcherUnitTests.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public void ItShouldMatchOnce()
2222

2323
var result = matcher.Match(request, interaction);
2424

25-
result.Response.RequestMessage.RequestUri.Should().BeEquivalentTo(new Uri("http://first"));
25+
result.Response.RequestMessage!.RequestUri.Should().BeEquivalentTo(new Uri("http://first"));
2626

2727
result = matcher.Match(request, interaction);
2828

2929
result.Should().NotBeNull();
30-
result.Response.RequestMessage.RequestUri.Should().BeEquivalentTo(new Uri("http://second"));
30+
result.Response.RequestMessage!.RequestUri.Should().BeEquivalentTo(new Uri("http://second"));
3131
}
3232

3333
[Fact]
@@ -45,7 +45,7 @@ public void ItShouldMatchOnceByHttpMethod()
4545
var result = matcher.Match(request, interaction);
4646

4747
result.Should().NotBeNull();
48-
result.Response.RequestMessage.Method.Should().BeEquivalentTo(HttpMethod.Head);
48+
result.Response.RequestMessage!.Method.Should().BeEquivalentTo(HttpMethod.Head);
4949
}
5050

5151
[Fact]
@@ -63,7 +63,7 @@ public void ItShouldMatchOnceByCompleteRequestUri()
6363
var result = matcher.Match(request, interaction);
6464

6565
result.Should().NotBeNull();
66-
result.Response.RequestMessage.RequestUri.Should().BeEquivalentTo(new Uri("http://first?name=bar"));
66+
result.Response.RequestMessage!.RequestUri.Should().BeEquivalentTo(new Uri("http://first?name=bar"));
6767
}
6868

6969
[Fact]
@@ -81,7 +81,7 @@ public void ItShouldMatchOnceByPartialRequestUri()
8181
var result = matcher.Match(request, interaction);
8282

8383
result.Should().NotBeNull();
84-
result.Response.RequestMessage.RequestUri.Should().BeEquivalentTo(new Uri("http://first?name=foo"));
84+
result.Response.RequestMessage!.RequestUri.Should().BeEquivalentTo(new Uri("http://first?name=foo"));
8585
}
8686

8787
[Fact]
@@ -102,7 +102,7 @@ public void ItShouldMatchOnceByHeader()
102102
var result = matcher.Match(request, interaction);
103103

104104
result.Should().NotBeNull();
105-
result.Response.RequestMessage.Headers.IfNoneMatch.ToString().Should().Be("second");
105+
result.Response.RequestMessage!.Headers.IfNoneMatch.ToString().Should().Be("second");
106106
}
107107

108108
[Fact]
@@ -122,7 +122,7 @@ public void ItShouldMatchOnceByContentWithSameSize()
122122
var result = matcher.Match(request, interaction);
123123

124124
result.Should().NotBeNull();
125-
result.Response.RequestMessage.Content.Should().BeEquivalentTo(secondContent);
125+
result.Response.RequestMessage!.Content.Should().BeEquivalentTo(secondContent);
126126
}
127127

128128
[Fact]
@@ -142,7 +142,7 @@ public void ItShouldMatchOnceByContentWithDifferentSizes()
142142
var result = matcher.Match(request, interaction);
143143

144144
result.Should().NotBeNull();
145-
result.Response.RequestMessage.Content.Should().BeEquivalentTo(secondContent);
145+
result.Response.RequestMessage!.Content.Should().BeEquivalentTo(secondContent);
146146
}
147147

148148
[Fact]
@@ -165,7 +165,7 @@ public void ItShouldMatchOnceByJsonContent()
165165
var result = matcher.Match(request, interaction);
166166

167167
result.Should().NotBeNull();
168-
result.Response.RequestMessage.Content.Should().BeEquivalentTo(secondContent);
168+
result.Response.RequestMessage!.Content.Should().BeEquivalentTo(secondContent);
169169
}
170170

171171
[Fact]
@@ -210,10 +210,10 @@ public void ItShouldMatchWithCombination()
210210
.ByRequestUri();
211211

212212
var result = matcher.Match(request, interaction);
213-
result.Response.RequestMessage.RequestUri.Should().BeEquivalentTo(new Uri("http://second"));
213+
result.Response.RequestMessage!.RequestUri.Should().BeEquivalentTo(new Uri("http://second"));
214214
}
215215

216-
private Interaction BuildInteraction(params HttpRequestMessage[] requests)
216+
private static Interaction BuildInteraction(params HttpRequestMessage[] requests)
217217
{
218218
return new Interaction(
219219
"test",
@@ -224,7 +224,7 @@ private Interaction BuildInteraction(params HttpRequestMessage[] requests)
224224

225225
private class Model
226226
{
227-
public string Name { get; set; }
227+
public string Name { get; init; }
228228

229229
public override bool Equals(object obj)
230230
{

HttpRecorder.Tests/ServerFixture.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Uri ServerUri
3030
get
3131
{
3232
var serverAddressesFeature = ServerWebHost.ServerFeatures.Get<IServerAddressesFeature>();
33-
return new Uri(serverAddressesFeature.Addresses.First());
33+
return new Uri(serverAddressesFeature!.Addresses.First());
3434
}
3535
}
3636

HttpRecorder/HttpClientBuilderExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static IHttpClientBuilder AddHttpRecorder(
5151
repository: repository,
5252
anonymizer: anonymizer);
5353

54-
return httpClientBuilder.AddHttpMessageHandler((sp) => recorder);
54+
return httpClientBuilder.AddHttpMessageHandler(_ => recorder);
5555
}
5656
}
5757
}

HttpRecorder/Matchers/RulesMatcher.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ public RulesMatcher ByHeader(string headerName, StringComparison stringCompariso
128128
public RulesMatcher ByContent()
129129
=> By((request, message) =>
130130
{
131-
var requestContent = request.Content?.ReadAsByteArrayAsync()?.ConfigureAwait(false).GetAwaiter().GetResult();
132-
var messageContent = message.Response.RequestMessage.Content?.ReadAsByteArrayAsync()?.ConfigureAwait(false).GetAwaiter().GetResult();
131+
var requestContent = request.Content?.ReadAsByteArrayAsync().ConfigureAwait(false).GetAwaiter().GetResult();
132+
var messageContent = message.Response.RequestMessage.Content?.ReadAsByteArrayAsync().ConfigureAwait(false).GetAwaiter().GetResult();
133133

134134
if (requestContent is null)
135135
{
@@ -149,8 +149,8 @@ public RulesMatcher ByContent()
149149
}
150150

151151
return StructuralComparisons.StructuralComparer.Compare(
152-
request.Content?.ReadAsByteArrayAsync()?.Result,
153-
message.Response.RequestMessage.Content?.ReadAsByteArrayAsync()?.Result) == 0;
152+
request.Content?.ReadAsByteArrayAsync().Result,
153+
message.Response.RequestMessage.Content?.ReadAsByteArrayAsync().Result) == 0;
154154
});
155155

156156
/// <summary>
@@ -165,10 +165,10 @@ public RulesMatcher ByJsonContent<T>(
165165
JsonSerializerOptions jsonSerializerOptions = null)
166166
=> By((request, message) =>
167167
{
168-
var requestContent = request.Content?.ReadAsStringAsync()?.Result;
168+
var requestContent = request.Content?.ReadAsStringAsync().Result;
169169
var requestJson = !string.IsNullOrEmpty(requestContent) ? JsonSerializer.Deserialize<T>(requestContent, jsonSerializerOptions) : default(T);
170170

171-
var interactionContent = message.Response.RequestMessage.Content?.ReadAsStringAsync()?.Result;
171+
var interactionContent = message.Response.RequestMessage.Content?.ReadAsStringAsync().Result;
172172
var interactionJson = !string.IsNullOrEmpty(interactionContent) ? JsonSerializer.Deserialize<T>(interactionContent, jsonSerializerOptions) : default(T);
173173

174174
if (equalityComparer == null)

HttpRecorder/Repositories/HAR/Header.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Collections.Generic;
2-
using System.Net.Http.Headers;
32

43
namespace HttpRecorder.Repositories.HAR
54
{

0 commit comments

Comments
 (0)