diff --git a/tests/TinyPng.Tests/FakeResponseHandler.cs b/tests/TinyPng.Tests/FakeResponseHandler.cs index dd91fb2..09618ff 100644 --- a/tests/TinyPng.Tests/FakeResponseHandler.cs +++ b/tests/TinyPng.Tests/FakeResponseHandler.cs @@ -8,8 +8,8 @@ namespace TinyPng.Tests; public class FakeResponseHandler : DelegatingHandler { - private readonly Dictionary _fakeGetResponses = new(); - private readonly Dictionary _fakePostResponses = new(); + private readonly Dictionary _fakeGetResponses = []; + private readonly Dictionary _fakePostResponses = []; public void AddFakeGetResponse(Uri uri, HttpResponseMessage responseMessage) @@ -23,12 +23,8 @@ public void AddFakePostResponse(Uri uri, HttpResponseMessage responseMessage) protected override Task SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { - var result = request.Method == HttpMethod.Get && _fakeGetResponses.ContainsKey(request.RequestUri) - ? _fakeGetResponses[request.RequestUri] - : request.Method == HttpMethod.Post && _fakePostResponses.ContainsKey(request.RequestUri) - ? _fakePostResponses[request.RequestUri] - : new HttpResponseMessage(HttpStatusCode.NotFound) { RequestMessage = request }; - - return Task.FromResult(result); + if (request.Method == HttpMethod.Get && _fakeGetResponses.TryGetValue(request.RequestUri, out var getMessage)) { return Task.FromResult(getMessage); } + else if (request.Method == HttpMethod.Post && _fakePostResponses.TryGetValue(request.RequestUri, out var postMessage)) { return Task.FromResult(postMessage); } + else { return Task.FromResult(new HttpResponseMessage(HttpStatusCode.NotFound) { RequestMessage = request }); } } } diff --git a/tests/TinyPng.Tests/TinyPng.Tests.csproj b/tests/TinyPng.Tests/TinyPng.Tests.csproj index 02a37f5..c003e26 100644 --- a/tests/TinyPng.Tests/TinyPng.Tests.csproj +++ b/tests/TinyPng.Tests/TinyPng.Tests.csproj @@ -1,6 +1,6 @@  - net6.0 + net8.0