diff --git a/examples/WireMock.Net.Console.NET8.WithCertificate/WireMock.Net.Console.NET8.WithCertificate.csproj b/examples/WireMock.Net.Console.NET8.WithCertificate/WireMock.Net.Console.NET8.WithCertificate.csproj index de4e20c1..9f157822 100644 --- a/examples/WireMock.Net.Console.NET8.WithCertificate/WireMock.Net.Console.NET8.WithCertificate.csproj +++ b/examples/WireMock.Net.Console.NET8.WithCertificate/WireMock.Net.Console.NET8.WithCertificate.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net8.0 diff --git a/examples/WireMock.Net.Service/WireMock.Net.Service.csproj b/examples/WireMock.Net.Service/WireMock.Net.Service.csproj index 3721b4e4..186505a4 100644 --- a/examples/WireMock.Net.Service/WireMock.Net.Service.csproj +++ b/examples/WireMock.Net.Service/WireMock.Net.Service.csproj @@ -33,24 +33,9 @@ 4 - - ..\..\packages\log4net.2.0.15\lib\net45\log4net.dll - - - ..\..\packages\Microsoft.Owin.2.0.2\lib\net45\Microsoft.Owin.dll - - - ..\..\packages\Microsoft.Owin.Host.HttpListener.2.0.2\lib\net45\Microsoft.Owin.Host.HttpListener.dll - - - ..\..\packages\Microsoft.Owin.Hosting.2.0.2\lib\net45\Microsoft.Owin.Hosting.dll - ..\..\packages\Newtonsoft.Json.13.0.3\lib\net45\Newtonsoft.Json.dll - - ..\..\packages\Owin.1.0\lib\net40\Owin.dll - ..\..\packages\SimMetrics.Net.1.0.5\lib\net45\SimMetrics.Net.dll @@ -59,29 +44,17 @@ - - ..\..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll - - - ..\..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll - - - ..\..\packages\Microsoft.AspNet.WebApi.Owin.5.2.3\lib\net45\System.Web.Http.Owin.dll - - - ..\..\packages\XPath2.1.1.4\lib\net452\XPath2.dll - @@ -115,10 +88,13 @@ - 3.2.0 + 3.3.0 + + + 2.3.9 - 1.12.0 + 1.25.0 diff --git a/src/WireMock.Net.Minimal/Http/HttpClientBuilder.cs b/src/WireMock.Net.Minimal/Http/HttpClientBuilder.cs index 01bf5375..cc17df64 100644 --- a/src/WireMock.Net.Minimal/Http/HttpClientBuilder.cs +++ b/src/WireMock.Net.Minimal/Http/HttpClientBuilder.cs @@ -2,6 +2,7 @@ using System.Net; using System.Net.Http; +using System.Security.Authentication; using WireMock.HttpsCertificate; using WireMock.Settings; @@ -12,10 +13,13 @@ internal static class HttpClientBuilder public static HttpClient Build(HttpClientSettings settings) { #if NET8_0_OR_GREATER + var handler = new HttpClientHandler { CheckCertificateRevocationList = false, - SslProtocols = System.Security.Authentication.SslProtocols.Tls13 | System.Security.Authentication.SslProtocols.Tls12 | System.Security.Authentication.SslProtocols.Tls11 | System.Security.Authentication.SslProtocols.Tls, +#pragma warning disable SYSLIB0039 // Type or member is obsolete + SslProtocols = SslProtocols.Tls13 | SslProtocols.Tls12 | SslProtocols.Tls11 | SslProtocols.Tls, +#pragma warning restore SYSLIB0039 // Type or member is obsolete ServerCertificateCustomValidationCallback = (_, _, _, _) => true, AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; diff --git a/src/WireMock.Net.Minimal/HttpsCertificate/CertificateLoader.cs b/src/WireMock.Net.Minimal/HttpsCertificate/CertificateLoader.cs index c533b942..fc15e944 100644 --- a/src/WireMock.Net.Minimal/HttpsCertificate/CertificateLoader.cs +++ b/src/WireMock.Net.Minimal/HttpsCertificate/CertificateLoader.cs @@ -48,7 +48,7 @@ internal static class CertificateLoader if (!string.IsNullOrEmpty(options.X509CertificateFilePath)) { - if (options.X509CertificateFilePath.EndsWith(ExtensionPem, StringComparison.OrdinalIgnoreCase)) + if (options.X509CertificateFilePath!.EndsWith(ExtensionPem, StringComparison.OrdinalIgnoreCase)) { // PEM logic based on: https://www.scottbrady91.com/c-sharp/pem-loading-in-dotnet-core-and-dotnet #if NET8_0_OR_GREATER diff --git a/src/WireMock.Net.Minimal/Owin/WireMockMiddlewareOptions.cs b/src/WireMock.Net.Minimal/Owin/WireMockMiddlewareOptions.cs index 6f6e2c05..653096f9 100644 --- a/src/WireMock.Net.Minimal/Owin/WireMockMiddlewareOptions.cs +++ b/src/WireMock.Net.Minimal/Owin/WireMockMiddlewareOptions.cs @@ -17,7 +17,7 @@ namespace WireMock.Owin; internal class WireMockMiddlewareOptions : IWireMockMiddlewareOptions { - public IWireMockLogger Logger { get; set; } + public IWireMockLogger Logger { get; set; } = new WireMockConsoleLogger(); public TimeSpan? RequestProcessingDelay { get; set; } diff --git a/src/WireMock.Net.Minimal/Server/WireMockServer.Admin.cs b/src/WireMock.Net.Minimal/Server/WireMockServer.Admin.cs index 655f5d3f..12507600 100644 --- a/src/WireMock.Net.Minimal/Server/WireMockServer.Admin.cs +++ b/src/WireMock.Net.Minimal/Server/WireMockServer.Admin.cs @@ -586,7 +586,7 @@ public partial class WireMockServer { if (TryParseGuidFromRequestMessage(requestMessage, out var guid)) { - var entry = LogEntries.SingleOrDefault(r => !r.RequestMessage.Path.StartsWith("/__admin/") && r.Guid == guid); + var entry = LogEntries.SingleOrDefault(r => r.RequestMessage != null && !r.RequestMessage.Path.StartsWith("/__admin/") && r.Guid == guid); if (entry is { }) { var model = new LogEntryMapper(_options).Map(entry); @@ -615,7 +615,7 @@ public partial class WireMockServer { var logEntryMapper = new LogEntryMapper(_options); var result = LogEntries - .Where(r => !r.RequestMessage.Path.StartsWith("/__admin/")) + .Where(r => r.RequestMessage != null && !r.RequestMessage.Path.StartsWith("/__admin/")) .Select(logEntryMapper.Map); return ToJson(result); @@ -637,10 +637,10 @@ public partial class WireMockServer var request = (Request)InitRequestBuilder(requestModel); var dict = new Dictionary(); - foreach (var logEntry in LogEntries.Where(le => !le.RequestMessage.Path.StartsWith("/__admin/"))) + foreach (var logEntry in LogEntries.Where(le => le.RequestMessage != null && !le.RequestMessage.Path.StartsWith("/__admin/"))) { var requestMatchResult = new RequestMatchResult(); - if (request.GetMatchingScore(logEntry.RequestMessage, requestMatchResult) > MatchScores.AlmostPerfect) + if (request.GetMatchingScore(logEntry.RequestMessage!, requestMatchResult) > MatchScores.AlmostPerfect) { dict.Add(logEntry, requestMatchResult); } @@ -659,7 +659,7 @@ public partial class WireMockServer Guid.TryParse(value.ToString(), out var mappingGuid) ) { - var logEntries = LogEntries.Where(le => !le.RequestMessage.Path.StartsWith("/__admin/") && le.MappingGuid == mappingGuid); + var logEntries = LogEntries.Where(le => le.RequestMessage != null && !le.RequestMessage.Path.StartsWith("/__admin/") && le.MappingGuid == mappingGuid); var logEntryMapper = new LogEntryMapper(_options); var result = logEntries.Select(logEntryMapper.Map); return ToJson(result); diff --git a/src/WireMock.Net.Minimal/Transformers/Scriban/WireMockListAccessor.cs b/src/WireMock.Net.Minimal/Transformers/Scriban/WireMockListAccessor.cs index f48c00c1..8fee1b42 100644 --- a/src/WireMock.Net.Minimal/Transformers/Scriban/WireMockListAccessor.cs +++ b/src/WireMock.Net.Minimal/Transformers/Scriban/WireMockListAccessor.cs @@ -4,66 +4,65 @@ using Scriban; using Scriban.Parsing; using Scriban.Runtime; -namespace WireMock.Transformers.Scriban +namespace WireMock.Transformers.Scriban; + +internal class WireMockListAccessor : IListAccessor, IObjectAccessor { - internal class WireMockListAccessor : IListAccessor, IObjectAccessor + #region IListAccessor + public int GetLength(TemplateContext context, SourceSpan span, object target) { - #region IListAccessor - public int GetLength(TemplateContext context, SourceSpan span, object target) - { - throw new NotImplementedException(); - } - - public object GetValue(TemplateContext context, SourceSpan span, object target, int index) - { - return target.ToString(); - } - - public void SetValue(TemplateContext context, SourceSpan span, object target, int index, object value) - { - throw new NotImplementedException(); - } - #endregion - - #region IObjectAccessor - public int GetMemberCount(TemplateContext context, SourceSpan span, object target) - { - throw new NotImplementedException(); - } - - public IEnumerable GetMembers(TemplateContext context, SourceSpan span, object target) - { - throw new NotImplementedException(); - } - - public bool HasMember(TemplateContext context, SourceSpan span, object target, string member) - { - throw new NotImplementedException(); - } - - public bool TryGetValue(TemplateContext context, SourceSpan span, object target, string member, out object value) - { - throw new NotImplementedException(); - } - - public bool TrySetValue(TemplateContext context, SourceSpan span, object target, string member, object value) - { - throw new NotImplementedException(); - } - - public bool TryGetItem(TemplateContext context, SourceSpan span, object target, object index, out object value) - { - throw new NotImplementedException(); - } - - public bool TrySetItem(TemplateContext context, SourceSpan span, object target, object index, object value) - { - throw new NotImplementedException(); - } - - public bool HasIndexer => throw new NotImplementedException(); - - public Type IndexType => throw new NotImplementedException(); - #endregion + throw new NotImplementedException(); } + + public object GetValue(TemplateContext context, SourceSpan span, object target, int index) + { + return target?.ToString() ?? string.Empty; + } + + public void SetValue(TemplateContext context, SourceSpan span, object target, int index, object value) + { + throw new NotImplementedException(); + } + #endregion + + #region IObjectAccessor + public int GetMemberCount(TemplateContext context, SourceSpan span, object target) + { + throw new NotImplementedException(); + } + + public IEnumerable GetMembers(TemplateContext context, SourceSpan span, object target) + { + throw new NotImplementedException(); + } + + public bool HasMember(TemplateContext context, SourceSpan span, object target, string member) + { + throw new NotImplementedException(); + } + + public bool TryGetValue(TemplateContext context, SourceSpan span, object target, string member, out object value) + { + throw new NotImplementedException(); + } + + public bool TrySetValue(TemplateContext context, SourceSpan span, object target, string member, object value) + { + throw new NotImplementedException(); + } + + public bool TryGetItem(TemplateContext context, SourceSpan span, object target, object index, out object value) + { + throw new NotImplementedException(); + } + + public bool TrySetItem(TemplateContext context, SourceSpan span, object target, object index, object value) + { + throw new NotImplementedException(); + } + + public bool HasIndexer => throw new NotImplementedException(); + + public Type IndexType => throw new NotImplementedException(); + #endregion } \ No newline at end of file diff --git a/test/WireMock.Net.Tests/RequestBuilders/RequestBuilderUsingMethodTests.cs b/test/WireMock.Net.Tests/RequestBuilders/RequestBuilderUsingMethodTests.cs index 6eb513c4..c9b8faa7 100644 --- a/test/WireMock.Net.Tests/RequestBuilders/RequestBuilderUsingMethodTests.cs +++ b/test/WireMock.Net.Tests/RequestBuilders/RequestBuilderUsingMethodTests.cs @@ -17,7 +17,7 @@ public class RequestBuilderUsingMethodTests // Assert var matchers = requestBuilder.GetPrivateFieldValue>("_requestMatchers"); matchers.Count.Should().Be(1); - ((matchers[0] as RequestMessageMethodMatcher).Methods).Should().ContainSingle("CONNECT"); + (matchers[0] as RequestMessageMethodMatcher).Methods.Should().ContainSingle("CONNECT"); } [Fact] @@ -29,7 +29,7 @@ public class RequestBuilderUsingMethodTests // Assert var matchers = requestBuilder.GetPrivateFieldValue>("_requestMatchers"); matchers.Count.Should().Be(1); - ((matchers[0] as RequestMessageMethodMatcher).Methods).Should().ContainSingle("OPTIONS"); + (matchers[0] as RequestMessageMethodMatcher).Methods.Should().ContainSingle("OPTIONS"); } [Fact] @@ -41,7 +41,7 @@ public class RequestBuilderUsingMethodTests // Assert var matchers = requestBuilder.GetPrivateFieldValue>("_requestMatchers"); matchers.Count.Should().Be(1); - ((matchers[0] as RequestMessageMethodMatcher).Methods).Should().ContainSingle("PATCH"); + (matchers[0] as RequestMessageMethodMatcher).Methods.Should().ContainSingle("PATCH"); } [Fact] @@ -53,7 +53,7 @@ public class RequestBuilderUsingMethodTests // Assert var matchers = requestBuilder.GetPrivateFieldValue>("_requestMatchers"); matchers.Count.Should().Be(1); - ((matchers[0] as RequestMessageMethodMatcher).Methods).Should().ContainSingle("TRACE"); + (matchers[0] as RequestMessageMethodMatcher).Methods.Should().ContainSingle("TRACE"); } [Fact] diff --git a/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsJsonPathTests.cs b/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsJsonPathTests.cs index 8251e1b7..1d870cf6 100644 --- a/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsJsonPathTests.cs +++ b/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsJsonPathTests.cs @@ -109,8 +109,8 @@ public class ResponseWithHandlebarsJsonPathTests var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of(), request, _settings); // Assert - JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson!); - j["x"].Value().Should().Be(99); + var j = JObject.FromObject(response.Message.BodyData!.BodyAsJson!); + j["x"]?.Value().Should().Be(99); } [Fact] @@ -163,7 +163,7 @@ public class ResponseWithHandlebarsJsonPathTests var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of(), request, _settings); // Assert - response.Message.BodyData.BodyAsString.Should().Be($"{{{Environment.NewLine} \"Name\": \"Acme Co\",{Environment.NewLine} \"Products\": [{Environment.NewLine} {{{Environment.NewLine} \"Name\": \"Anvil\",{Environment.NewLine} \"Price\": 50{Environment.NewLine} }}{Environment.NewLine} ]{Environment.NewLine}}}"); + response.Message.BodyData!.BodyAsString.Should().Be($"{{{Environment.NewLine} \"Name\": \"Acme Co\",{Environment.NewLine} \"Products\": [{Environment.NewLine} {{{Environment.NewLine} \"Name\": \"Anvil\",{Environment.NewLine} \"Price\": 50{Environment.NewLine} }}{Environment.NewLine} ]{Environment.NewLine}}}"); } [Fact] diff --git a/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsLinqTests.cs b/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsLinqTests.cs index e47a9e29..207ae667 100644 --- a/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsLinqTests.cs +++ b/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsLinqTests.cs @@ -46,9 +46,9 @@ public class ResponseWithHandlebarsLinqTests var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of(), request, _settings); // Assert - JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson); + var j = JObject.FromObject(response.Message.BodyData!.BodyAsJson!); j["x"].Should().NotBeNull(); - j["x"].ToString().Should().Be("/pathtest"); + j["x"]?.ToString().Should().Be("/pathtest"); } [Fact(Skip = "DynamicLinq")] @@ -76,9 +76,8 @@ public class ResponseWithHandlebarsLinqTests var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of(), request, _settings); // Assert - JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson); - j["x"].Should().NotBeNull(); - j["x"].ToString().Should().Be("Test_123"); + var j = JObject.FromObject(response.Message.BodyData!.BodyAsJson!); + j["x"].Should().NotBeNull().And.Subject.ToString().Should().Be("Test_123"); } [Fact(Skip = "DynamicLinq")] diff --git a/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsXegerTests.cs b/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsXegerTests.cs index acd527b6..d404d5a3 100644 --- a/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsXegerTests.cs +++ b/test/WireMock.Net.Tests/ResponseBuilders/ResponseWithHandlebarsXegerTests.cs @@ -3,7 +3,6 @@ using Microsoft.AspNetCore.Http; using Moq; using Newtonsoft.Json.Linq; - using WireMock.Handlers; using WireMock.Models; using WireMock.ResponseBuilders; @@ -69,9 +68,8 @@ public class ResponseWithHandlebarsXegerTests var response = await responseBuilder.ProvideResponseAsync(_mappingMock.Object, Mock.Of(), request, _settings); // Assert - JObject j = JObject.FromObject(response.Message.BodyData.BodyAsJson); - j["Number"].Value().Should().BeGreaterThan(1000).And.BeLessThan(9999); - j["Postcode"].Value().Should().NotBeEmpty(); + var j = JObject.FromObject(response.Message.BodyData!.BodyAsJson!); + j["Number"]?.Value().Should().BeGreaterThan(1000).And.BeLessThan(9999); + j["Postcode"]?.Value().Should().NotBeEmpty(); } -} - +} \ No newline at end of file diff --git a/test/WireMock.Net.Tests/Serialization/CustomPathParamMatcherModel.cs b/test/WireMock.Net.Tests/Serialization/CustomPathParamMatcherModel.cs index 69fc94c0..9666ac2b 100644 --- a/test/WireMock.Net.Tests/Serialization/CustomPathParamMatcherModel.cs +++ b/test/WireMock.Net.Tests/Serialization/CustomPathParamMatcherModel.cs @@ -1,20 +1,16 @@ // Copyright © WireMock.Net -namespace WireMock.Net.Tests.Serialization +namespace WireMock.Net.Tests.Serialization; + +public class CustomPathParamMatcherModel { - public class CustomPathParamMatcherModel + public string Path { get; set; } + + public Dictionary PathParams { get; set; } + + public CustomPathParamMatcherModel(string path, Dictionary pathParams) { - public string Path { get; set; } - public Dictionary PathParams { get; set; } - - public CustomPathParamMatcherModel() - { - } - - public CustomPathParamMatcherModel(string path, Dictionary pathParams) - { - Path = path; - PathParams = pathParams; - } + Path = path; + PathParams = pathParams; } } \ No newline at end of file diff --git a/test/WireMock.Net.Tests/TestUtils.cs b/test/WireMock.Net.Tests/TestUtils.cs index 21a335c7..ae727a88 100644 --- a/test/WireMock.Net.Tests/TestUtils.cs +++ b/test/WireMock.Net.Tests/TestUtils.cs @@ -10,7 +10,7 @@ public static class TestUtils { var field = obj.GetType().GetTypeInfo().GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Instance); - return (T)field.GetValue(obj); + return (T)field!.GetValue(obj)!; } /// @@ -27,8 +27,8 @@ public static class TestUtils throw new ArgumentNullException(nameof(obj)); } - Type t = obj.GetType(); - FieldInfo fi = null; + Type? t = obj.GetType(); + FieldInfo? fi = null; while (fi == null && t != null) { fi = t.GetField(propertyName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);