diff --git a/README.md b/README.md index aefd98d2e..4af936510 100644 --- a/README.md +++ b/README.md @@ -35,17 +35,20 @@ For more info, see also this WIKI page: [What is WireMock.Net](https://github.co ### :package: NuGet packages -| | Official | Preview [:information_source:](https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions) | +| | Info | Official | Preview [:information_source:](https://github.com/WireMock-Net/WireMock.Net/wiki/MyGet-preview-versions) | | - | - | - | -|   **WireMock.Net** | [![NuGet Badge WireMock.Net](https://buildstats.info/nuget/WireMock.Net)](https://www.nuget.org/packages/WireMock.Net) | [![MyGet Badge WireMock.Net](https://buildstats.info/myget/wiremock-net/WireMock.Net?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net) -|   **WireMock.Net.StandAlone** | [![NuGet Badge WireMock.Net](https://buildstats.info/nuget/WireMock.Net.StandAlone)](https://www.nuget.org/packages/WireMock.Net.StandAlone) | [![MyGet Badge WireMock.Net.StandAlone](https://buildstats.info/myget/wiremock-net/WireMock.Net.StandAlone?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.StandAlone) -|   **WireMock.Net.FluentAssertions** | [![NuGet Badge WireMock.Net.FluentAssertions](https://buildstats.info/nuget/WireMock.Net.FluentAssertions)](https://www.nuget.org/packages/WireMock.Net.FluentAssertions) | [![MyGet Badge WireMock.Net.FluentAssertions](https://buildstats.info/myget/wiremock-net/WireMock.Net.FluentAssertions?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.FluentAssertions) -|   **WireMock.Net.Matchers.CSharpCode** | [![NuGet Badge WireMock.Net.Matchers.CSharpCode](https://buildstats.info/nuget/WireMock.Net.Matchers.CSharpCode)](https://www.nuget.org/packages/WireMock.Net.Matchers.CSharpCode) | [![MyGet Badge WireMock.Net.Matchers.CSharpCode](https://buildstats.info/myget/wiremock-net/WireMock.Net.Matchers.CSharpCode?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.Matchers.CSharpCode) -|   **WireMock.Net.OpenApiParser** | [![NuGet Badge WireMock.Net.OpenApiParser](https://buildstats.info/nuget/WireMock.Net.OpenApiParser)](https://www.nuget.org/packages/WireMock.Net.OpenApiParser) | [![MyGet Badge WireMock.Net.OpenApiParser](https://buildstats.info/myget/wiremock-net/WireMock.Net.OpenApiParser?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.OpenApiParser) -|   **WireMock.Net.RestClient** | [![NuGet Badge WireMock.Net.RestClient](https://buildstats.info/nuget/WireMock.Net.RestClient)](https://www.nuget.org/packages/WireMock.Net.RestClient) | [![MyGet Badge WireMock.Net.RestClient](https://buildstats.info/myget/wiremock-net/WireMock.Net.RestClient?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.RestClient) -|   **WireMock.Net.xUnit** | [![NuGet Badge WireMock.Net.xUnit](https://buildstats.info/nuget/WireMock.Net.xUnit)](https://www.nuget.org/packages/WireMock.Net.xUnit) | [![MyGet Badge WireMock.Net.xUnit](https://buildstats.info/myget/wiremock-net/WireMock.Net.xUnit?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.xUnit) -|   **WireMock.Net.Testcontainers** | [![NuGet Badge WireMock.Net.Testcontainers](https://buildstats.info/nuget/WireMock.Net.Testcontainers)](https://www.nuget.org/packages/WireMock.Net.Testcontainers) | [![MyGet Badge WireMock.Net.Testcontainers](https://buildstats.info/myget/wiremock-net/WireMock.Net.Testcontainers?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.Testcontainers) -|   **WireMock.Org.RestClient** | [![NuGet Badge WireMock.Org.RestClient](https://buildstats.info/nuget/WireMock.Org.RestClient)](https://www.nuget.org/packages/WireMock.Org.RestClient) | [![MyGet Badge WireMock.Org.RestClient](https://buildstats.info/myget/wiremock-net/WireMock.Org.RestClient?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Org.RestClient) +|   **WireMock.Net** | Main project | [![NuGet Badge WireMock.Net](https://buildstats.info/nuget/WireMock.Net)](https://www.nuget.org/packages/WireMock.Net) | [![MyGet Badge WireMock.Net](https://buildstats.info/myget/wiremock-net/WireMock.Net?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net) +|   **WireMock.Net.StandAlone** | StandAlone | [![NuGet Badge WireMock.Net](https://buildstats.info/nuget/WireMock.Net.StandAlone)](https://www.nuget.org/packages/WireMock.Net.StandAlone) | [![MyGet Badge WireMock.Net.StandAlone](https://buildstats.info/myget/wiremock-net/WireMock.Net.StandAlone?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.StandAlone) +|   **WireMock.Net.GraphQL** | [GraphQL Support](https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching-GraphQLMatcher) | [![NuGet Badge WireMock.Net.GraphQL](https://buildstats.info/nuget/WireMock.Net.GraphQL)](https://www.nuget.org/packages/WireMock.Net.GraphQL) | [![MyGet Badge WireMock.Net.GraphQL](https://buildstats.info/myget/wiremock-net/WireMock.Net.GraphQL?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.GraphQL) +|   **WireMock.Net.MimeKitLite** | [MimePart Support](https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching-MimePartMatcher) | [![NuGet Badge WireMock.Net.MimeKitLite](https://buildstats.info/nuget/WireMock.Net.MimeKitLite)](https://www.nuget.org/packages/WireMock.Net.MimeKitLite) | [![MyGet Badge WireMock.Net.MimeKitLite](https://buildstats.info/myget/wiremock-net/WireMock.Net.MimeKitLite?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.MimeKitLite) +|   **WireMock.Net.ProtoBuf** | [ProtoBuf gRPC Support](https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching-ProtoBuf) | [![NuGet Badge WireMock.Net.ProtoBuf](https://buildstats.info/nuget/WireMock.Net.ProtoBuf)](https://www.nuget.org/packages/WireMock.Net.ProtoBuf) | [![MyGet Badge WireMock.Net.ProtoBuf](https://buildstats.info/myget/wiremock-net/WireMock.Net.ProtoBuf?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.ProtoBuf) +|   **WireMock.Net.Matchers.CSharpCode** | [C# Code Matcher](https://github.com/WireMock-Net/WireMock.Net/wiki/Request-Matching-CSharpCode) | [![NuGet Badge WireMock.Net.Matchers.CSharpCode](https://buildstats.info/nuget/WireMock.Net.Matchers.CSharpCode)](https://www.nuget.org/packages/WireMock.Net.Matchers.CSharpCode) | [![MyGet Badge WireMock.Net.Matchers.CSharpCode](https://buildstats.info/myget/wiremock-net/WireMock.Net.Matchers.CSharpCode?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.Matchers.CSharpCode) +|   **WireMock.Net.OpenApiParser** | OpenApiParser | [![NuGet Badge WireMock.Net.OpenApiParser](https://buildstats.info/nuget/WireMock.Net.OpenApiParser)](https://www.nuget.org/packages/WireMock.Net.OpenApiParser) | [![MyGet Badge WireMock.Net.OpenApiParser](https://buildstats.info/myget/wiremock-net/WireMock.Net.OpenApiParser?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.OpenApiParser) +|   **WireMock.Net.FluentAssertions** | FluentAssertions Extensions | [![NuGet Badge WireMock.Net.FluentAssertions](https://buildstats.info/nuget/WireMock.Net.FluentAssertions)](https://www.nuget.org/packages/WireMock.Net.FluentAssertions) | [![MyGet Badge WireMock.Net.FluentAssertions](https://buildstats.info/myget/wiremock-net/WireMock.Net.FluentAssertions?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.FluentAssertions) +|   **WireMock.Net.xUnit** | xUnit logging support | [![NuGet Badge WireMock.Net.xUnit](https://buildstats.info/nuget/WireMock.Net.xUnit)](https://www.nuget.org/packages/WireMock.Net.xUnit) | [![MyGet Badge WireMock.Net.xUnit](https://buildstats.info/myget/wiremock-net/WireMock.Net.xUnit?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.xUnit) +|   **WireMock.Net.Testcontainers** | [Testcontainers Support](https://github.com/WireMock-Net/WireMock.Net/wiki/Using-WireMock.Net.Testcontainers) | [![NuGet Badge WireMock.Net.Testcontainers](https://buildstats.info/nuget/WireMock.Net.Testcontainers)](https://www.nuget.org/packages/WireMock.Net.Testcontainers) | [![MyGet Badge WireMock.Net.Testcontainers](https://buildstats.info/myget/wiremock-net/WireMock.Net.Testcontainers?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.Testcontainers) +|   **WireMock.Net.RestClient** | RestClient for WireMock.Net| [![NuGet Badge WireMock.Net.RestClient](https://buildstats.info/nuget/WireMock.Net.RestClient)](https://www.nuget.org/packages/WireMock.Net.RestClient) | [![MyGet Badge WireMock.Net.RestClient](https://buildstats.info/myget/wiremock-net/WireMock.Net.RestClient?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Net.RestClient) +|   **WireMock.Org.RestClient** | RestClient for WireMock.Org| [![NuGet Badge WireMock.Org.RestClient](https://buildstats.info/nuget/WireMock.Org.RestClient)](https://www.nuget.org/packages/WireMock.Org.RestClient) | [![MyGet Badge WireMock.Org.RestClient](https://buildstats.info/myget/wiremock-net/WireMock.Org.RestClient?includePreReleases=true)](https://www.myget.org/feed/wiremock-net/package/nuget/WireMock.Org.RestClient) ## :memo: Development diff --git a/WireMock.Net Solution.sln b/WireMock.Net Solution.sln index 67ec72741..4736f80ea 100644 --- a/WireMock.Net Solution.sln +++ b/WireMock.Net Solution.sln @@ -114,6 +114,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMockAzureQueueProxy", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Console.GrpcClient", "examples\WireMock.Net.Console.GrpcClient\WireMock.Net.Console.GrpcClient.csproj", "{B1580A38-84E7-44BE-8FE7-3EE5031D74A1}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.GraphQL", "src\WireMock.Net.GraphQL\WireMock.Net.GraphQL.csproj", "{B6269AAC-170A-4346-8B9A-444DED3D9A45}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.MimeKitLite", "src\WireMock.Net.MimeKitLite\WireMock.Net.MimeKitLite.csproj", "{F8B4A93E-46EF-4237-88FE-15FDAB7635D4}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.ProtoBuf", "src\WireMock.Net.ProtoBuf\WireMock.Net.ProtoBuf.csproj", "{B47413AA-55D3-49A7-896A-17ADBFF72407}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WireMock.Net.Minimal", "src\WireMock.Net.Minimal\WireMock.Net.Minimal.csproj", "{A39C689E-B94B-4BBB-A270-B5A4C2B6D179}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -268,6 +276,22 @@ Global {B1580A38-84E7-44BE-8FE7-3EE5031D74A1}.Debug|Any CPU.Build.0 = Debug|Any CPU {B1580A38-84E7-44BE-8FE7-3EE5031D74A1}.Release|Any CPU.ActiveCfg = Release|Any CPU {B1580A38-84E7-44BE-8FE7-3EE5031D74A1}.Release|Any CPU.Build.0 = Release|Any CPU + {B6269AAC-170A-4346-8B9A-444DED3D9A45}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B6269AAC-170A-4346-8B9A-444DED3D9A45}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B6269AAC-170A-4346-8B9A-444DED3D9A45}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B6269AAC-170A-4346-8B9A-444DED3D9A45}.Release|Any CPU.Build.0 = Release|Any CPU + {F8B4A93E-46EF-4237-88FE-15FDAB7635D4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F8B4A93E-46EF-4237-88FE-15FDAB7635D4}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F8B4A93E-46EF-4237-88FE-15FDAB7635D4}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F8B4A93E-46EF-4237-88FE-15FDAB7635D4}.Release|Any CPU.Build.0 = Release|Any CPU + {B47413AA-55D3-49A7-896A-17ADBFF72407}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B47413AA-55D3-49A7-896A-17ADBFF72407}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B47413AA-55D3-49A7-896A-17ADBFF72407}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B47413AA-55D3-49A7-896A-17ADBFF72407}.Release|Any CPU.Build.0 = Release|Any CPU + {A39C689E-B94B-4BBB-A270-B5A4C2B6D179}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A39C689E-B94B-4BBB-A270-B5A4C2B6D179}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A39C689E-B94B-4BBB-A270-B5A4C2B6D179}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A39C689E-B94B-4BBB-A270-B5A4C2B6D179}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -312,6 +336,10 @@ Global {1EA72C0F-92E9-486B-8FFE-53F992BFC4AA} = {985E0ADB-D4B4-473A-AA40-567E279B7946} {7FC0B409-2682-40EE-B3B9-3930D6769D01} = {985E0ADB-D4B4-473A-AA40-567E279B7946} {B1580A38-84E7-44BE-8FE7-3EE5031D74A1} = {985E0ADB-D4B4-473A-AA40-567E279B7946} + {B6269AAC-170A-4346-8B9A-444DED3D9A45} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2} + {F8B4A93E-46EF-4237-88FE-15FDAB7635D4} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2} + {B47413AA-55D3-49A7-896A-17ADBFF72407} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2} + {A39C689E-B94B-4BBB-A270-B5A4C2B6D179} = {8F890C6F-9ACC-438D-928A-AD61CDA862F2} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {DC539027-9852-430C-B19F-FD035D018458} diff --git a/examples/WireMock.Net.Console.NET8/WireMock.Net.Console.NET8.csproj b/examples/WireMock.Net.Console.NET8/WireMock.Net.Console.NET8.csproj index ff5b2a2fa..536d7f183 100644 --- a/examples/WireMock.Net.Console.NET8/WireMock.Net.Console.NET8.csproj +++ b/examples/WireMock.Net.Console.NET8/WireMock.Net.Console.NET8.csproj @@ -1,40 +1,46 @@ - - Exe - net8.0 - $(DefineConstants);GRAPHQL;MIMEKIT;PROTOBUF - - - - - - - - - - - PreserveNewest - - - - - - - - - - - - - - - - PreserveNewest - - - PreserveNewest - - + + Exe + net8.0 + $(DefineConstants);GRAPHQL;MIMEKIT;PROTOBUF + + + + + + + + + + + PreserveNewest + + + + + + + + + + + + + + + + + + + + PreserveNewest + + + PreserveNewest + + \ No newline at end of file diff --git a/src/WireMock.Net.Abstractions/IRequestMessage.cs b/src/WireMock.Net.Abstractions/IRequestMessage.cs index 42d9c99fd..fe3e44303 100644 --- a/src/WireMock.Net.Abstractions/IRequestMessage.cs +++ b/src/WireMock.Net.Abstractions/IRequestMessage.cs @@ -116,13 +116,11 @@ public interface IRequestMessage /// byte[]? BodyAsBytes { get; } -#if MIMEKIT /// /// The original body as MimeMessage. /// Convenience getter for Handlebars and WireMockAssertions. /// object? BodyAsMimeMessage { get; } -#endif /// /// The detected body type. Convenience getter for Handlebars. diff --git a/src/WireMock.Net.Abstractions/WireMock.Net.Abstractions.csproj b/src/WireMock.Net.Abstractions/WireMock.Net.Abstractions.csproj index 32fa99b03..a12b51e57 100644 --- a/src/WireMock.Net.Abstractions/WireMock.Net.Abstractions.csproj +++ b/src/WireMock.Net.Abstractions/WireMock.Net.Abstractions.csproj @@ -30,10 +30,6 @@ true - - $(DefineConstants);GRAPHQL;MIMEKIT;PROTOBUF - - diff --git a/src/WireMock.Net/Matchers/GraphQLMatcher.cs b/src/WireMock.Net.GraphQL/Matchers/GraphQLMatcher.cs similarity index 95% rename from src/WireMock.Net/Matchers/GraphQLMatcher.cs rename to src/WireMock.Net.GraphQL/Matchers/GraphQLMatcher.cs index fb3b1567e..2bdd28481 100644 --- a/src/WireMock.Net/Matchers/GraphQLMatcher.cs +++ b/src/WireMock.Net.GraphQL/Matchers/GraphQLMatcher.cs @@ -21,8 +21,8 @@ namespace WireMock.Matchers; /// /// GrapQLMatcher Schema Matcher /// -/// -public class GraphQLMatcher : IStringMatcher +/// +public class GraphQLMatcher : IGraphQLMatcher { private sealed class GraphQLRequest { @@ -40,9 +40,7 @@ private sealed class GraphQLRequest /// public MatchBehaviour MatchBehaviour { get; } - /// - /// An optional dictionary defining the custom Scalar and the type. - /// + /// public IDictionary? CustomScalars { get; } /// @@ -52,7 +50,7 @@ private sealed class GraphQLRequest /// The match behaviour. (default = "AcceptOnMatch") /// The to use. (default = "Or") public GraphQLMatcher( - AnyOf schema, + AnyOf schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch, MatchOperator matchOperator = MatchOperator.Or ) : this(schema, null, matchBehaviour, matchOperator) @@ -67,7 +65,7 @@ private sealed class GraphQLRequest /// The match behaviour. (default = "AcceptOnMatch") /// The to use. (default = "Or") public GraphQLMatcher( - AnyOf schema, + AnyOf schema, IDictionary? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch, MatchOperator matchOperator = MatchOperator.Or @@ -92,7 +90,7 @@ private sealed class GraphQLRequest break; case AnyOfType.Third: - _schema = schema.Third; + _schema = schema.Third as ISchema ?? throw new NotSupportedException(); break; default: diff --git a/src/WireMock.Net/Matchers/Models/WireMockCustomScalarGraphType.cs b/src/WireMock.Net.GraphQL/Matchers/Models/WireMockCustomScalarGraphType.cs similarity index 100% rename from src/WireMock.Net/Matchers/Models/WireMockCustomScalarGraphType.cs rename to src/WireMock.Net.GraphQL/Matchers/Models/WireMockCustomScalarGraphType.cs diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageGraphQLMatcher.cs b/src/WireMock.Net.GraphQL/Matchers/Request/RequestMessageGraphQLMatcher.cs similarity index 79% rename from src/WireMock.Net/Matchers/Request/RequestMessageGraphQLMatcher.cs rename to src/WireMock.Net.GraphQL/Matchers/Request/RequestMessageGraphQLMatcher.cs index c8211963b..b4dd7154e 100644 --- a/src/WireMock.Net/Matchers/Request/RequestMessageGraphQLMatcher.cs +++ b/src/WireMock.Net.GraphQL/Matchers/Request/RequestMessageGraphQLMatcher.cs @@ -1,24 +1,22 @@ +#if GRAPHQL using System; using System.Collections.Generic; using System.Linq; using Stef.Validation; using WireMock.Types; +using WireMock.Util; namespace WireMock.Matchers.Request; /// /// The request body GraphQL matcher. /// -public class RequestMessageGraphQLMatcher : IRequestMatcher +public class RequestMessageGraphQLMatcher : IRequestMessageGraphQLMatcher { - /// - /// The matchers. - /// + /// public IMatcher[]? Matchers { get; } - /// - /// The - /// + /// public MatchOperator MatchOperator { get; } = MatchOperator.Or; /// @@ -32,7 +30,6 @@ public class RequestMessageGraphQLMatcher : IRequestMatcher { } -#if GRAPHQL /// /// Initializes a new instance of the class. /// @@ -40,10 +37,9 @@ public class RequestMessageGraphQLMatcher : IRequestMatcher /// The schema. /// A dictionary defining the custom scalars used in this schema. [optional] public RequestMessageGraphQLMatcher(MatchBehaviour matchBehaviour, GraphQL.Types.ISchema schema, IDictionary? customScalars = null) : - this(CreateMatcherArray(matchBehaviour, new AnyOfTypes.AnyOf(schema), customScalars)) + this(CreateMatcherArray(matchBehaviour, new AnyOfTypes.AnyOf(schema), customScalars)) { } -#endif /// /// Initializes a new instance of the class. @@ -91,19 +87,9 @@ private IReadOnlyList CalculateMatchResults(IRequestMessage request return Matchers == null ? new[] { new MatchResult() } : Matchers.Select(matcher => CalculateMatchResult(requestMessage, matcher)).ToArray(); } -#if GRAPHQL - private static IMatcher[] CreateMatcherArray( - MatchBehaviour matchBehaviour, - AnyOfTypes.AnyOf schema, - IDictionary? customScalars - ) - { - return new[] { new GraphQLMatcher(schema, customScalars, matchBehaviour) }.Cast().ToArray(); - } -#else - private static IMatcher[] CreateMatcherArray(MatchBehaviour matchBehaviour, object schema, IDictionary? customScalars) + private static IMatcher[] CreateMatcherArray(MatchBehaviour matchBehaviour, AnyOfTypes.AnyOf schema, IDictionary? customScalars) { - throw new System.NotSupportedException("The GrapQLMatcher can not be used for .NETStandard1.3 or .NET Framework 4.6.1 or lower."); + return new[] { TypeLoader.Load(schema, customScalars, matchBehaviour, MatchOperator.Or) }.Cast().ToArray(); } -#endif -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/WireMock.Net.GraphQL/Properties/AssemblyInfo.cs b/src/WireMock.Net.GraphQL/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..a2f9571eb --- /dev/null +++ b/src/WireMock.Net.GraphQL/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Runtime.CompilerServices; + +// [assembly: InternalsVisibleTo("WireMock.Net.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] + +// Needed for Moq in the UnitTest project +// [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] \ No newline at end of file diff --git a/src/WireMock.Net.GraphQL/RequestBuilders/IGraphQLRequestBuilderExtensions.cs b/src/WireMock.Net.GraphQL/RequestBuilders/IGraphQLRequestBuilderExtensions.cs new file mode 100644 index 000000000..d58932110 --- /dev/null +++ b/src/WireMock.Net.GraphQL/RequestBuilders/IGraphQLRequestBuilderExtensions.cs @@ -0,0 +1,128 @@ +#if GRAPHQL +// ReSharper disable InconsistentNaming +using System; +using System.Collections.Generic; +using Stef.Validation; +using WireMock.Matchers; +using WireMock.Matchers.Request; + +namespace WireMock.RequestBuilders; + +/// +/// IRequestBuilderExtensions extensions for GraphQL. +/// +public static class IGraphQLRequestBuilderExtensions +{ + /// + /// WithGraphQLSchema: The GraphQL schema as a string. + /// + /// The . + /// The GraphQL schema. + /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). + /// The . + public static IRequestBuilder WithGraphQLSchema(this IRequestBuilder requestBuilder, string schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) + { + return WithBodyAsGraphQL(requestBuilder, schema, matchBehaviour); + } + + /// + /// WithGraphQLSchema: The GraphQL schema as a string. + /// + /// The . + /// The GraphQL schema. + /// A dictionary defining the custom scalars used in this schema. (optional) + /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). + /// The . + public static IRequestBuilder WithGraphQLSchema(this IRequestBuilder requestBuilder, string schema, IDictionary? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) + { + return WithBodyAsGraphQL(requestBuilder, schema, customScalars, matchBehaviour); + } + + /// + /// WithBodyAsGraphQL: The GraphQL schema as a string. + /// + /// The . + /// The GraphQL schema. + /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). + /// The . + public static IRequestBuilder WithBodyAsGraphQL(this IRequestBuilder requestBuilder, string schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) + { + return Guard.NotNull(requestBuilder).Add(new RequestMessageGraphQLMatcher(matchBehaviour, schema)); + } + + /// + /// WithBodyAsGraphQL: The GraphQL schema as a string. + /// + /// The . + /// The GraphQL schema. + /// A dictionary defining the custom scalars used in this schema. (optional) + /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). + /// The . + public static IRequestBuilder WithBodyAsGraphQL(this IRequestBuilder requestBuilder, string schema, IDictionary? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) + { + return Guard.NotNull(requestBuilder).Add(new RequestMessageGraphQLMatcher(matchBehaviour, schema, customScalars)); + } + + /// + /// WithGraphQLSchema: The GraphQL schema as a ISchema. + /// + /// The . + /// The GraphQL schema. + /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). + /// The . + public static IRequestBuilder WithGraphQLSchema(this IRequestBuilder requestBuilder, GraphQL.Types.ISchema schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) + { + return WithBodyAsGraphQL(requestBuilder, schema, matchBehaviour); + } + + /// + /// WithGraphQLSchema: The GraphQL schema as a ISchema. + /// + /// The . + /// The GraphQL schema. + /// A dictionary defining the custom scalars used in this schema. (optional) + /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). + /// The . + public static IRequestBuilder WithGraphQLSchema(this IRequestBuilder requestBuilder, GraphQL.Types.ISchema schema, IDictionary? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) + { + return WithBodyAsGraphQL(requestBuilder, schema, customScalars, matchBehaviour); + } + + /// + /// WithBodyAsGraphQL: The GraphQL schema as a ISchema. + /// + /// The . + /// The GraphQL schema. + /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). + /// The . + public static IRequestBuilder WithBodyAsGraphQL(this IRequestBuilder requestBuilder, GraphQL.Types.ISchema schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) + { + return requestBuilder.Add(new RequestMessageGraphQLMatcher(matchBehaviour, schema)); + } + + /// + /// WithBodyAsGraphQL: The GraphQL schema as a ISchema. + /// + /// The . + /// The GraphQL schema. + /// A dictionary defining the custom scalars used in this schema. (optional) + /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). + /// The . + public static IRequestBuilder WithBodyAsGraphQL(this IRequestBuilder requestBuilder, GraphQL.Types.ISchema schema, IDictionary? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) + { + return Guard.NotNull(requestBuilder).Add(new RequestMessageGraphQLMatcher(matchBehaviour, schema, customScalars)); + } + + /// + /// WithBodyAsGraphQLSchema: Body as GraphQL schema as a string. + /// + /// The . + /// The GraphQL schema. + /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). + /// The . + public static IRequestBuilder WithBodyAsGraphQLSchema(this IRequestBuilder requestBuilder, string body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) + { + return WithGraphQLSchema(requestBuilder, body, matchBehaviour); + } +} +#endif \ No newline at end of file diff --git a/src/WireMock.Net.GraphQL/WireMock.Net.GraphQL.csproj b/src/WireMock.Net.GraphQL/WireMock.Net.GraphQL.csproj new file mode 100644 index 000000000..5a52a1d79 --- /dev/null +++ b/src/WireMock.Net.GraphQL/WireMock.Net.GraphQL.csproj @@ -0,0 +1,37 @@ + + + + GraphQL support for WireMock.Net + WireMock.Net.Matchers.GraphQL + Stef Heyenrath + netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0;net8.0 + true + wiremock;matchers;matcher;graphql + WireMock + {B6269AAC-170A-4346-8B9A-444DED3D9A45} + true + true + true + true + ../WireMock.Net/WireMock.Net.ruleset + true + ../WireMock.Net/WireMock.Net.snk + + true + MIT + + + + true + + + + + + + + + + + + \ No newline at end of file diff --git a/src/WireMock.Net.Matchers.CSharpCode/Matchers/CSharpCodeMatcher.cs b/src/WireMock.Net.Matchers.CSharpCode/Matchers/CSharpCodeMatcher.cs index 90dcd3bc7..4fa6ec044 100644 --- a/src/WireMock.Net.Matchers.CSharpCode/Matchers/CSharpCodeMatcher.cs +++ b/src/WireMock.Net.Matchers.CSharpCode/Matchers/CSharpCodeMatcher.cs @@ -1,3 +1,4 @@ +//#if CSHARPMATCHER using System; using System.Linq; using System.Reflection; @@ -231,4 +232,5 @@ private string GetSourceForIsMatchWithString(string pattern, bool isMatchWithStr /// public string Name => nameof(CSharpCodeMatcher); -} \ No newline at end of file +} +//#endif \ No newline at end of file diff --git a/src/WireMock.Net.Matchers.CSharpCode/Properties/AssemblyInfo.cs b/src/WireMock.Net.Matchers.CSharpCode/Properties/AssemblyInfo.cs index 4f81246fa..fd930200f 100644 --- a/src/WireMock.Net.Matchers.CSharpCode/Properties/AssemblyInfo.cs +++ b/src/WireMock.Net.Matchers.CSharpCode/Properties/AssemblyInfo.cs @@ -1,6 +1,6 @@ -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("WireMock.Net.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] +// [assembly: InternalsVisibleTo("WireMock.Net.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] // Needed for Moq in the UnitTest project -[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] \ No newline at end of file +// [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] \ No newline at end of file diff --git a/src/WireMock.Net.Matchers.CSharpCode/WireMock.Net.Matchers.CSharpCode.csproj b/src/WireMock.Net.Matchers.CSharpCode/WireMock.Net.Matchers.CSharpCode.csproj index 97440b252..c516d0d8d 100644 --- a/src/WireMock.Net.Matchers.CSharpCode/WireMock.Net.Matchers.CSharpCode.csproj +++ b/src/WireMock.Net.Matchers.CSharpCode/WireMock.Net.Matchers.CSharpCode.csproj @@ -1,52 +1,52 @@ - - A CSharpCodeMatcher which can be used to match WireMock.Net Requests using C# code. - WireMock.Net.Matchers.CSharpCode - Stef Heyenrath - net451;net452;net46;net461;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 - true - wiremock;matchers;matcher;csharp;csharpcode - WireMock - {B6269AAC-170A-4346-8B9A-444DED3D9A44} - true - $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - true - true - true - ../WireMock.Net/WireMock.Net.ruleset - true - ../WireMock.Net/WireMock.Net.snk - - true - MIT - - - - true - - - - - - - - - - - - - - - - - - - - - - - - + + A CSharpCodeMatcher which can be used to match WireMock.Net Requests using C# code. + WireMock.Net.Matchers.CSharpCode + Stef Heyenrath + net451;net452;net46;net461;net462;net47;net48;netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0;net8.0 + true + wiremock;matchers;matcher;csharp;csharpcode + WireMock + {B6269AAC-170A-4346-8B9A-444DED3D9A44} + true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + true + true + true + ../WireMock.Net/WireMock.Net.ruleset + true + ../WireMock.Net/WireMock.Net.snk + + true + MIT + + + + true + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/WireMock.Net/Matchers/MimePartMatcher.cs b/src/WireMock.Net.MimeKitLite/Matchers/MimePartMatcher.cs similarity index 88% rename from src/WireMock.Net/Matchers/MimePartMatcher.cs rename to src/WireMock.Net.MimeKitLite/Matchers/MimePartMatcher.cs index 145052826..a60331671 100644 --- a/src/WireMock.Net/Matchers/MimePartMatcher.cs +++ b/src/WireMock.Net.MimeKitLite/Matchers/MimePartMatcher.cs @@ -1,9 +1,7 @@ #if MIMEKIT using System; using MimeKit; -using WireMock.Matchers; using WireMock.Matchers.Helpers; -using WireMock.Models; using WireMock.Util; namespace WireMock.Matchers; @@ -11,31 +9,23 @@ namespace WireMock.Matchers; /// /// MimePartMatcher /// -public class MimePartMatcher : IMatcher +public class MimePartMatcher : IMimePartMatcher { private readonly Func[] _funcs; /// public string Name => nameof(MimePartMatcher); - /// - /// ContentType Matcher (image/png; name=image.png.) - /// + /// public IStringMatcher? ContentTypeMatcher { get; } - /// - /// ContentDisposition Matcher (attachment; filename=image.png) - /// + /// public IStringMatcher? ContentDispositionMatcher { get; } - /// - /// ContentTransferEncoding Matcher (base64) - /// + /// public IStringMatcher? ContentTransferEncodingMatcher { get; } - /// - /// Content Matcher - /// + /// public IMatcher? ContentMatcher { get; } /// diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageMultiPartMatcher.cs b/src/WireMock.Net.MimeKitLite/Matchers/Request/RequestMessageMultiPartMatcher.cs similarity index 85% rename from src/WireMock.Net/Matchers/Request/RequestMessageMultiPartMatcher.cs rename to src/WireMock.Net.MimeKitLite/Matchers/Request/RequestMessageMultiPartMatcher.cs index 4695cb71b..a516afbfa 100644 --- a/src/WireMock.Net/Matchers/Request/RequestMessageMultiPartMatcher.cs +++ b/src/WireMock.Net.MimeKitLite/Matchers/Request/RequestMessageMultiPartMatcher.cs @@ -1,6 +1,8 @@ +#if MIMEKIT using System; using System.Collections.Generic; using System.Linq; +using MimeKit; using Stef.Validation; using WireMock.Util; @@ -9,16 +11,12 @@ namespace WireMock.Matchers.Request; /// /// The request body MultiPart matcher. /// -public class RequestMessageMultiPartMatcher : IRequestMatcher +public class RequestMessageMultiPartMatcher : IRequestMessageMultiPartMatcher { - /// - /// The matchers. - /// + /// public IMatcher[]? Matchers { get; } - /// - /// The - /// + /// public MatchOperator MatchOperator { get; } = MatchOperator.Or; /// @@ -26,6 +24,8 @@ public class RequestMessageMultiPartMatcher : IRequestMatcher /// public MatchBehaviour MatchBehaviour { get; } + private readonly MimeKitUtils _mimeKitUtils = new(); + /// /// Initializes a new instance of the class. /// @@ -51,9 +51,6 @@ public RequestMessageMultiPartMatcher(MatchBehaviour matchBehaviour, MatchOperat /// public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResult requestMatchResult) { -#if !MIMEKIT - throw new System.NotSupportedException("The MultiPartMatcher can not be used for .NETStandard1.3 or .NET Framework 4.6.1 or lower."); -#else var score = MatchScores.Mismatch; Exception? exception = null; @@ -62,7 +59,7 @@ public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResu return requestMatchResult.AddScore(GetType(), score, null); } - if (!MimeKitUtils.TryGetMimeMessage(requestMessage, out var message)) + if (!_mimeKitUtils.TryGetMimeMessage(requestMessage, out MimeMessage? message)) { return requestMatchResult.AddScore(GetType(), score, null); } @@ -71,7 +68,7 @@ public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResu { var mimePartMatchers = Matchers.OfType().ToArray(); - foreach (var mimePart in message.BodyParts.OfType()) + foreach (var mimePart in message.BodyParts.OfType()) { var matchesForMimePart = new List { default }; matchesForMimePart.AddRange(mimePartMatchers.Select(matcher => matcher.IsMatch(mimePart))); @@ -98,6 +95,6 @@ public double GetMatchingScore(IRequestMessage requestMessage, IRequestMatchResu } return requestMatchResult.AddScore(GetType(), score, exception); -#endif } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/WireMock.Net.MimeKitLite/Properties/AssemblyInfo.cs b/src/WireMock.Net.MimeKitLite/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..a2f9571eb --- /dev/null +++ b/src/WireMock.Net.MimeKitLite/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Runtime.CompilerServices; + +// [assembly: InternalsVisibleTo("WireMock.Net.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] + +// Needed for Moq in the UnitTest project +// [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] \ No newline at end of file diff --git a/src/WireMock.Net.MimeKitLite/RequestBuilders/IMultiPartRequestBuilderExtensions.cs b/src/WireMock.Net.MimeKitLite/RequestBuilders/IMultiPartRequestBuilderExtensions.cs new file mode 100644 index 000000000..3bfc372aa --- /dev/null +++ b/src/WireMock.Net.MimeKitLite/RequestBuilders/IMultiPartRequestBuilderExtensions.cs @@ -0,0 +1,49 @@ +#if MIMEKIT +// ReSharper disable InconsistentNaming +using WireMock.Matchers; +using WireMock.Matchers.Request; + +namespace WireMock.RequestBuilders; + +/// +/// IRequestBuilderExtensions extensions for MultiPart Mime using MimeKitLite. +/// +public static class IMultiPartRequestBuilderExtensions +{ + /// + /// WithMultiPart: IMatcher + /// + /// The . + /// The matcher. + /// The . + public static IRequestBuilder WithMultiPart(this IRequestBuilder requestBuilder, IMatcher matcher) + { + return requestBuilder.Add(new RequestMessageMultiPartMatcher(matcher)); + } + + /// + /// WithMultiPart: IMatcher[], MatchBehaviour and MatchOperator + /// + /// The . + /// The matchers. + /// The to use. + /// The to use. + /// The . + public static IRequestBuilder WithMultiPart(this IRequestBuilder requestBuilder, IMatcher[] matchers, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch, MatchOperator matchOperator = MatchOperator.Or) + { + return requestBuilder.Add(new RequestMessageMultiPartMatcher(matchBehaviour, matchOperator, matchers)); + } + + /// + /// WithMultiPart: MatchBehaviour and IMatcher[] + /// + /// The . + /// The to use. + /// The matchers. + /// The . + public static IRequestBuilder WithMultiPart(this IRequestBuilder requestBuilder, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch, params IMatcher[] matchers) + { + return requestBuilder.Add(new RequestMessageMultiPartMatcher(matchBehaviour, MatchOperator.Or, matchers)); + } +} +#endif \ No newline at end of file diff --git a/src/WireMock.Net/Util/MimeKitUtils.cs b/src/WireMock.Net.MimeKitLite/Util/MimeKitUtils.cs similarity index 82% rename from src/WireMock.Net/Util/MimeKitUtils.cs rename to src/WireMock.Net.MimeKitLite/Util/MimeKitUtils.cs index 9bb5126e4..1c5fb1181 100644 --- a/src/WireMock.Net/Util/MimeKitUtils.cs +++ b/src/WireMock.Net.MimeKitLite/Util/MimeKitUtils.cs @@ -11,9 +11,16 @@ namespace WireMock.Util; -internal static class MimeKitUtils +internal class MimeKitUtils : IMimeKitUtils { - public static bool TryGetMimeMessage(IRequestMessage requestMessage, [NotNullWhen(true)] out MimeMessage? mimeMessage) + public bool TryGetMimeMessage(IRequestMessage requestMessage, [NotNullWhen(true)] out object? mimeMessage) + { + var result = TryGetMimeMessage(requestMessage, out MimeMessage? value); + mimeMessage = value; + return result; + } + + public bool TryGetMimeMessage(IRequestMessage requestMessage, [NotNullWhen(true)] out MimeMessage? mimeMessage) { Guard.NotNull(requestMessage); diff --git a/src/WireMock.Net.MimeKitLite/WireMock.Net.MimeKitLite.csproj b/src/WireMock.Net.MimeKitLite/WireMock.Net.MimeKitLite.csproj new file mode 100644 index 000000000..9f6c9be9a --- /dev/null +++ b/src/WireMock.Net.MimeKitLite/WireMock.Net.MimeKitLite.csproj @@ -0,0 +1,36 @@ + + + + MultiPart Mime support for WireMock.Net + WireMock.Net.MimeKitLite + Stef Heyenrath + netstandard2.0;netstandard2.1;net462;net47;net48;net6.0;net8.0 + true + wiremock;matchers;matcher;mime;multipart;mimekit + WireMock + {F8B4A93E-46EF-4237-88FE-15FDAB7635D4} + true + true + true + true + ../WireMock.Net/WireMock.Net.ruleset + true + ../WireMock.Net/WireMock.Net.snk + + true + MIT + + + + true + + + + + + + + + + + \ No newline at end of file diff --git a/src/WireMock.Net.Minimal/Properties/AssemblyInfo.cs b/src/WireMock.Net.Minimal/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..1d42700e7 --- /dev/null +++ b/src/WireMock.Net.Minimal/Properties/AssemblyInfo.cs @@ -0,0 +1,7 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("WireMock.Net.ProtoBuf, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] +[assembly: InternalsVisibleTo("WireMock.Net.MimeKitLite, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] +[assembly: InternalsVisibleTo("WireMock.Net.GraphQL, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] +[assembly: InternalsVisibleTo("WireMock.Net.Matchers.CSharpCode, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] +//[assembly: InternalsVisibleTo("WireMock.Net.StandAlone, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] diff --git a/src/WireMock.Net.Minimal/WireMock.Net.Minimal.csproj b/src/WireMock.Net.Minimal/WireMock.Net.Minimal.csproj new file mode 100644 index 000000000..a5286e6ea --- /dev/null +++ b/src/WireMock.Net.Minimal/WireMock.Net.Minimal.csproj @@ -0,0 +1,204 @@ + + + Minimal version for WireMock.Net + WireMock.Net.Minimal + Stef Heyenrath + net451;net452;net46;net461;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0;net8.0 + true + WireMock.Net.Minimal + WireMock.Net.Minimal + tdd;mock;http;wiremock;test;server;unittest;minimal + WireMock + {A39C689E-B94B-4BBB-A270-B5A4C2B6D179} + true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + true + + true + ../WireMock.Net/WireMock.Net.snk + + true + + + + + + + + + true + + + + WireMock.Net.ruleset + + + + $(DefineConstants);NETSTANDARD;USE_ASPNETCORE + + + + $(DefineConstants);USE_ASPNETCORE + + + + $(DefineConstants);USE_ASPNETCORE;NET46 + + + + $(DefineConstants);OPENAPIPARSER + + + + $(DefineConstants);TRAILINGHEADERS + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/WireMock.Net/Matchers/ProtoBufMatcher.cs b/src/WireMock.Net.ProtoBuf/Matchers/ProtoBufMatcher.cs similarity index 90% rename from src/WireMock.Net/Matchers/ProtoBufMatcher.cs rename to src/WireMock.Net.ProtoBuf/Matchers/ProtoBufMatcher.cs index 45a221844..844a52d36 100644 --- a/src/WireMock.Net/Matchers/ProtoBufMatcher.cs +++ b/src/WireMock.Net.ProtoBuf/Matchers/ProtoBufMatcher.cs @@ -22,19 +22,13 @@ public class ProtoBufMatcher : IProtoBufMatcher /// public MatchBehaviour MatchBehaviour { get; } - /// - /// The Func to define The proto definition as text. - /// + /// public Func ProtoDefinition { get; } - /// - /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}". - /// + /// public string MessageType { get; } - /// - /// The Matcher to use (optional). - /// + /// public IObjectMatcher? Matcher { get; } private static readonly Converter ProtoBufToJsonConverter = SingletonFactory.GetInstance(); diff --git a/src/WireMock.Net/Matchers/Request/RequestMessageProtoBufMatcher.cs b/src/WireMock.Net.ProtoBuf/Matchers/Request/RequestMessageProtoBufMatcher.cs similarity index 88% rename from src/WireMock.Net/Matchers/Request/RequestMessageProtoBufMatcher.cs rename to src/WireMock.Net.ProtoBuf/Matchers/Request/RequestMessageProtoBufMatcher.cs index 004d1b70d..57db5ac0a 100644 --- a/src/WireMock.Net/Matchers/Request/RequestMessageProtoBufMatcher.cs +++ b/src/WireMock.Net.ProtoBuf/Matchers/Request/RequestMessageProtoBufMatcher.cs @@ -1,3 +1,4 @@ +#if PROTOBUF using System; using WireMock.Models; @@ -6,7 +7,7 @@ namespace WireMock.Matchers.Request; /// /// The request body Grpc ProtoBuf matcher. /// -public class RequestMessageProtoBufMatcher : IRequestMatcher +public class RequestMessageProtoBufMatcher : IRequestMessageProtoBufMatcher { /// /// The ProtoBufMatcher. @@ -22,11 +23,7 @@ public class RequestMessageProtoBufMatcher : IRequestMatcher /// The optional matcher to use to match the ProtoBuf as (json) object. public RequestMessageProtoBufMatcher(MatchBehaviour matchBehaviour, Func protoDefinition, string messageType, IObjectMatcher? matcher = null) { -#if PROTOBUF Matcher = new ProtoBufMatcher(protoDefinition, messageType, matchBehaviour, matcher); -#else - throw new System.NotSupportedException("The ProtoBufMatcher can not be used for .NETStandard1.3 or .NET Framework 4.6.1 or lower."); -#endif } /// @@ -40,4 +37,5 @@ private MatchResult GetMatchResult(IRequestMessage requestMessage) { return Matcher?.IsMatchAsync(requestMessage.BodyAsBytes).GetAwaiter().GetResult() ?? default; } -} \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/src/WireMock.Net.ProtoBuf/Properties/AssemblyInfo.cs b/src/WireMock.Net.ProtoBuf/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..a2f9571eb --- /dev/null +++ b/src/WireMock.Net.ProtoBuf/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +using System.Runtime.CompilerServices; + +// [assembly: InternalsVisibleTo("WireMock.Net.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] + +// Needed for Moq in the UnitTest project +// [assembly: InternalsVisibleTo("DynamicProxyGenAssembly2, PublicKey=0024000004800000940000000602000000240000525341310004000001000100c547cac37abd99c8db225ef2f6c8a3602f3b3606cc9891605d02baa56104f4cfc0734aa39b93bf7852f7d9266654753cc297e7d2edfe0bac1cdcf9f717241550e0a7b191195b7667bb4f64bcb8e2121380fd1d9d46ad2d92d2d15605093924cceaf74c4861eff62abf69b9291ed0a340e113be11e6a7d3113e92484cf7045cc7")] \ No newline at end of file diff --git a/src/WireMock.Net.ProtoBuf/RequestBuilders/IProtoBufRequestBuilderExtensions.cs b/src/WireMock.Net.ProtoBuf/RequestBuilders/IProtoBufRequestBuilderExtensions.cs new file mode 100644 index 000000000..66e769395 --- /dev/null +++ b/src/WireMock.Net.ProtoBuf/RequestBuilders/IProtoBufRequestBuilderExtensions.cs @@ -0,0 +1,66 @@ +#if PROTOBUF +// ReSharper disable InconsistentNaming +using Stef.Validation; +using WireMock.Matchers; +using WireMock.Matchers.Request; + +namespace WireMock.RequestBuilders; + +/// +/// IRequestBuilderExtensions extensions for ProtoBuf. +/// +public static class IProtoBufRequestBuilderExtensions +{ + /// + /// WithGrpcProto + /// + /// The . + /// The proto definition as text. + /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}". + /// The match behaviour. (default = "AcceptOnMatch") + /// The . + public static IRequestBuilder WithBodyAsProtoBuf(this IRequestBuilder requestBuilder, string protoDefinition, string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) + { + return Guard.NotNull(requestBuilder).Add(new RequestMessageProtoBufMatcher(matchBehaviour, () => new(null, protoDefinition), messageType)); + } + + /// + /// WithGrpcProto + /// + /// The . + /// The proto definition as text. + /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}". + /// The matcher to use to match the ProtoBuf as (json) object. + /// The match behaviour. (default = "AcceptOnMatch") + /// The . + public static IRequestBuilder WithBodyAsProtoBuf(this IRequestBuilder requestBuilder, string protoDefinition, string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) + { + return Guard.NotNull(requestBuilder).Add(new RequestMessageProtoBufMatcher(matchBehaviour, () => new(null, protoDefinition), messageType, matcher)); + } + + /// + /// WithGrpcProto + /// + /// The . + /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}". + /// The match behaviour. (default = "AcceptOnMatch") + /// The . + public static IRequestBuilder WithBodyAsProtoBuf(this IRequestBuilder requestBuilder, string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) + { + return Guard.NotNull(requestBuilder).Add(new RequestMessageProtoBufMatcher(matchBehaviour, () => requestBuilder.Mapping.ProtoDefinition!.Value, messageType)); + } + + /// + /// WithGrpcProto + /// + /// The . + /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}". + /// The matcher to use to match the ProtoBuf as (json) object. + /// The match behaviour. (default = "AcceptOnMatch") + /// The . + public static IRequestBuilder WithBodyAsProtoBuf(this IRequestBuilder requestBuilder, string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) + { + return Guard.NotNull(requestBuilder).Add(new RequestMessageProtoBufMatcher(matchBehaviour, () => requestBuilder.Mapping.ProtoDefinition!.Value, messageType, matcher)); + } +} +#endif \ No newline at end of file diff --git a/src/WireMock.Net/Util/ProtoBufUtils.cs b/src/WireMock.Net.ProtoBuf/Util/ProtoBufUtils.cs similarity index 90% rename from src/WireMock.Net/Util/ProtoBufUtils.cs rename to src/WireMock.Net.ProtoBuf/Util/ProtoBufUtils.cs index 44a5d07ce..958ff9c42 100644 --- a/src/WireMock.Net/Util/ProtoBufUtils.cs +++ b/src/WireMock.Net.ProtoBuf/Util/ProtoBufUtils.cs @@ -8,9 +8,9 @@ namespace WireMock.Util; -internal static class ProtoBufUtils +internal class ProtoBufUtils : IProtoBufUtils { - internal static async Task GetProtoBufMessageWithHeaderAsync( + public async Task GetProtoBufMessageWithHeaderAsync( string? protoDefinition, string? messageType, object? value, diff --git a/src/WireMock.Net.ProtoBuf/WireMock.Net.ProtoBuf.csproj b/src/WireMock.Net.ProtoBuf/WireMock.Net.ProtoBuf.csproj new file mode 100644 index 000000000..79e9a84ba --- /dev/null +++ b/src/WireMock.Net.ProtoBuf/WireMock.Net.ProtoBuf.csproj @@ -0,0 +1,36 @@ + + + + ProtoBuf and gRPC support for WireMock.Net + WireMock.Net.ProtoBuf + Stef Heyenrath + netstandard2.0;netstandard2.1;net462;net6.0;net8.0 + true + wiremock;matchers;matcher;protobuf;grpc + WireMock + {B47413AA-55D3-49A7-896A-17ADBFF72407} + true + true + true + true + ../WireMock.Net/WireMock.Net.ruleset + true + ../WireMock.Net/WireMock.Net.snk + + true + MIT + + + + true + + + + + + + + + + + \ No newline at end of file diff --git a/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj b/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj index 82e6a675d..901e34a29 100644 --- a/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj +++ b/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.csproj @@ -1,46 +1,46 @@ - - Lightweight StandAlone Http Mocking Server for .Net. - WireMock.Net.StandAlone - Stef Heyenrath - net451;net452;net46;net461;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 - true - WireMock.Net.StandAlone - WireMock.Net.StandAlone - tdd;mock;http;wiremock;test;server;unittest - WireMock.Net.StandAlone - {B6269AAC-170A-43D5-8B9A-579DED3D9A95} - true - $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - true - true - true - WireMock.Net.StandAlone.ruleset - true - ../WireMock.Net/WireMock.Net.snk - - true - + + Lightweight StandAlone Http Mocking Server for .NET which includes GraphQL-support, ProtoBuf-support, MimePartMatcher and CSharpCodeMatcher. + WireMock.Net.StandAlone + Stef Heyenrath + net451;net452;net46;net461;net462;net47;net48;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0;net8.0 + true + WireMock.Net.StandAlone + WireMock.Net.StandAlone + tdd;mock;http;wiremock;test;server;unittest + WireMock.Net.StandAlone + {B6269AAC-170A-43D5-8B9A-579DED3D9A95} + true + $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb + true + true + true + ../WireMock.Net/WireMock.Net.ruleset + true + ../WireMock.Net/WireMock.Net.snk + + true + - - - true - + + + true + - - NETSTANDARD;USE_ASPNETCORE - + + NETSTANDARD;USE_ASPNETCORE + - - USE_ASPNETCORE;NET46 - + + USE_ASPNETCORE;NET46 + - - - - + + + + - - - + + + \ No newline at end of file diff --git a/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.ruleset b/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.ruleset deleted file mode 100644 index 978d27ca3..000000000 --- a/src/WireMock.Net.StandAlone/WireMock.Net.StandAlone.ruleset +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/src/WireMock.Net/Matchers/IGraphQLMatcher.cs b/src/WireMock.Net/Matchers/IGraphQLMatcher.cs new file mode 100644 index 000000000..b7a824143 --- /dev/null +++ b/src/WireMock.Net/Matchers/IGraphQLMatcher.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; + +namespace WireMock.Matchers; + +/// +/// GraphQLMatcher +/// +/// +public interface IGraphQLMatcher : IStringMatcher +{ + /// + /// An optional dictionary defining the custom Scalar and the type. + /// + public IDictionary? CustomScalars { get; } +} \ No newline at end of file diff --git a/src/WireMock.Net/Matchers/IMimePartMatcher.cs b/src/WireMock.Net/Matchers/IMimePartMatcher.cs new file mode 100644 index 000000000..d2fda6732 --- /dev/null +++ b/src/WireMock.Net/Matchers/IMimePartMatcher.cs @@ -0,0 +1,28 @@ +namespace WireMock.Matchers; + +/// +/// MimePartMatcher +/// +/// +public interface IMimePartMatcher : IMatcher +{ + /// + /// ContentType Matcher (image/png; name=image.png.) + /// + IStringMatcher? ContentTypeMatcher { get; } + + /// + /// ContentDisposition Matcher (attachment; filename=image.png) + /// + IStringMatcher? ContentDispositionMatcher { get; } + + /// + /// ContentTransferEncoding Matcher (base64) + /// + IStringMatcher? ContentTransferEncodingMatcher { get; } + + /// + /// Content Matcher + /// + IMatcher? ContentMatcher { get; } +} \ No newline at end of file diff --git a/src/WireMock.Net/Matchers/IProtoBufMatcher.cs b/src/WireMock.Net/Matchers/IProtoBufMatcher.cs index 576ee9c15..5d21f6872 100644 --- a/src/WireMock.Net/Matchers/IProtoBufMatcher.cs +++ b/src/WireMock.Net/Matchers/IProtoBufMatcher.cs @@ -1,3 +1,6 @@ +using System; +using WireMock.Models; + namespace WireMock.Matchers; /// @@ -5,4 +8,18 @@ namespace WireMock.Matchers; /// public interface IProtoBufMatcher : IDecodeBytesMatcher, IBytesMatcher { + /// + /// The Func to define the proto definition as text or id. + /// + public Func ProtoDefinition { get; } + + /// + /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}". + /// + public string MessageType { get; } + + /// + /// The Matcher to use (optional). + /// + public IObjectMatcher? Matcher { get; } } \ No newline at end of file diff --git a/src/WireMock.Net/Matchers/Request/IRequestMessageGraphQLMatcher.cs b/src/WireMock.Net/Matchers/Request/IRequestMessageGraphQLMatcher.cs new file mode 100644 index 000000000..37d355eb7 --- /dev/null +++ b/src/WireMock.Net/Matchers/Request/IRequestMessageGraphQLMatcher.cs @@ -0,0 +1,17 @@ +namespace WireMock.Matchers.Request; + +/// +/// The request body GraphQL matcher. +/// +public interface IRequestMessageGraphQLMatcher : IRequestMatcher +{ + /// + /// The matchers. + /// + IMatcher[]? Matchers { get; } + + /// + /// The + /// + MatchOperator MatchOperator { get; } +} \ No newline at end of file diff --git a/src/WireMock.Net/Matchers/Request/IRequestMessageMultiPartMatcher.cs b/src/WireMock.Net/Matchers/Request/IRequestMessageMultiPartMatcher.cs new file mode 100644 index 000000000..269f989f8 --- /dev/null +++ b/src/WireMock.Net/Matchers/Request/IRequestMessageMultiPartMatcher.cs @@ -0,0 +1,17 @@ +namespace WireMock.Matchers.Request; + +/// +/// The request body MultiPart matcher. +/// +public interface IRequestMessageMultiPartMatcher : IRequestMatcher +{ + /// + /// The matchers. + /// + IMatcher[]? Matchers { get; } + + /// + /// The + /// + MatchOperator MatchOperator { get; } +} \ No newline at end of file diff --git a/src/WireMock.Net/Matchers/Request/IRequestMessageProtoBufMatcher.cs b/src/WireMock.Net/Matchers/Request/IRequestMessageProtoBufMatcher.cs new file mode 100644 index 000000000..ca4bc2915 --- /dev/null +++ b/src/WireMock.Net/Matchers/Request/IRequestMessageProtoBufMatcher.cs @@ -0,0 +1,12 @@ +namespace WireMock.Matchers.Request; + +/// +/// The request body ProtoBuf matcher. +/// +public interface IRequestMessageProtoBufMatcher : IRequestMatcher +{ + /// + /// The ProtoBufMatcher. + /// + IProtoBufMatcher? Matcher { get; } +} \ No newline at end of file diff --git a/src/WireMock.Net/Models/GraphQLSchemaDetails.cs b/src/WireMock.Net/Models/GraphQLSchemaDetails.cs index 8188dcf93..f138102d2 100644 --- a/src/WireMock.Net/Models/GraphQLSchemaDetails.cs +++ b/src/WireMock.Net/Models/GraphQLSchemaDetails.cs @@ -20,17 +20,16 @@ public class GraphQLSchemaDetails /// public StringPattern? SchemaAsStringPattern { get; set; } -#if GRAPHQL /// - /// The GraphQL schema as a . + /// The GraphQL schema as a "GraphQL.Types.ISchema". /// - public GraphQL.Types.ISchema? SchemaAsISchema { get; set; } + public object? SchemaAsISchema { get; set; } /// /// The GraphQL Schema. /// [JsonIgnore] - public AnyOf? Schema + public AnyOf? Schema { get { @@ -46,13 +45,12 @@ public class GraphQLSchemaDetails if (SchemaAsISchema != null) { - return new AnyOf(SchemaAsISchema); + return new AnyOf(SchemaAsISchema); } return null; } } -#endif /// /// The custom Scalars to define for this schema. diff --git a/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs b/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs index 7ffae3501..66127243a 100644 --- a/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs +++ b/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs @@ -144,8 +144,6 @@ private Task RunHost(CancellationToken token) _logger.Info("Server using .NET 5.0"); #elif NET6_0 _logger.Info("Server using .NET 6.0"); -#elif NET7_0 - _logger.Info("Server using .NET 7.0"); #elif NET8_0 _logger.Info("Server using .NET 8.0"); #elif NET46 diff --git a/src/WireMock.Net/Owin/Mappers/OwinResponseMapper.cs b/src/WireMock.Net/Owin/Mappers/OwinResponseMapper.cs index c1ceb39f4..8e179c643 100644 --- a/src/WireMock.Net/Owin/Mappers/OwinResponseMapper.cs +++ b/src/WireMock.Net/Owin/Mappers/OwinResponseMapper.cs @@ -142,11 +142,9 @@ private bool IsFault(IResponseMessage responseMessage) var jsonBody = JsonConvert.SerializeObject(responseMessage.BodyData.BodyAsJson, new JsonSerializerSettings { Formatting = formatting, NullValueHandling = NullValueHandling.Ignore }); return (responseMessage.BodyData.Encoding ?? _utf8NoBom).GetBytes(jsonBody); -#if PROTOBUF case BodyType.ProtoBuf: var protoDefinition = responseMessage.BodyData.ProtoDefinition?.Invoke().Text; - return await ProtoBufUtils.GetProtoBufMessageWithHeaderAsync(protoDefinition, responseMessage.BodyData.ProtoBufMessageType, responseMessage.BodyData.BodyAsJson).ConfigureAwait(false); -#endif + return await TypeLoader.Load().GetProtoBufMessageWithHeaderAsync(protoDefinition, responseMessage.BodyData.ProtoBufMessageType, responseMessage.BodyData.BodyAsJson).ConfigureAwait(false); case BodyType.Bytes: return responseMessage.BodyData.BodyAsBytes; diff --git a/src/WireMock.Net/Properties/AssemblyInfo.cs b/src/WireMock.Net/Properties/AssemblyInfo.cs index 5aa4c57c5..cd3be9eb8 100644 --- a/src/WireMock.Net/Properties/AssemblyInfo.cs +++ b/src/WireMock.Net/Properties/AssemblyInfo.cs @@ -1,6 +1,9 @@ using System.Runtime.CompilerServices; -[assembly: InternalsVisibleTo("WireMock.Net.Matchers.CSharpCode, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] +// [assembly: InternalsVisibleTo("WireMock.Net.ProtoBuf, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] +// [assembly: InternalsVisibleTo("WireMock.Net.MimeKitLite, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] +// [assembly: InternalsVisibleTo("WireMock.Net.GraphQL, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] +// [assembly: InternalsVisibleTo("WireMock.Net.Matchers.CSharpCode, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] [assembly: InternalsVisibleTo("WireMock.Net.StandAlone, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] [assembly: InternalsVisibleTo("WireMock.Net.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100e138ec44d93acac565953052636eb8d5e7e9f27ddb030590055cd1a0ab2069a5623f1f77ca907d78e0b37066ca0f6d63da7eecc3fcb65b76aa8ebeccf7ebe1d11264b8404cd9b1cbbf2c83f566e033b3e54129f6ef28daffff776ba7aebbc53c0d635ebad8f45f78eb3f7e0459023c218f003416e080f96a1a3c5ffeb56bee9e")] diff --git a/src/WireMock.Net/RequestBuilders/IBodyRequestBuilder.cs b/src/WireMock.Net/RequestBuilders/IBodyRequestBuilder.cs index c07022474..93fbff95f 100644 --- a/src/WireMock.Net/RequestBuilders/IBodyRequestBuilder.cs +++ b/src/WireMock.Net/RequestBuilders/IBodyRequestBuilder.cs @@ -9,7 +9,7 @@ namespace WireMock.RequestBuilders; /// /// The BodyRequestBuilder interface. /// -public interface IBodyRequestBuilder : IProtoBufRequestBuilder +public interface IBodyRequestBuilder : IHttpVersionBuilder { /// /// WithBody: IMatcher @@ -92,12 +92,4 @@ public interface IBodyRequestBuilder : IProtoBufRequestBuilder /// The form-urlencoded values. /// The . IRequestBuilder WithBody(Func?, bool> func); - - /// - /// WithBodyAsGraphQLSchema: Body as GraphQL schema as a string. - /// - /// The GraphQL schema. - /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). - /// The . - IRequestBuilder WithBodyAsGraphQLSchema(string body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch); } \ No newline at end of file diff --git a/src/WireMock.Net/RequestBuilders/IGraphQLRequestBuilder.cs b/src/WireMock.Net/RequestBuilders/IGraphQLRequestBuilder.cs deleted file mode 100644 index 7dc3cac28..000000000 --- a/src/WireMock.Net/RequestBuilders/IGraphQLRequestBuilder.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using WireMock.Matchers; - -namespace WireMock.RequestBuilders; - -/// -/// The GraphQLRequestBuilder interface. -/// -public interface IGraphQLRequestBuilder : IMultiPartRequestBuilder -{ - /// - /// WithGraphQLSchema: The GraphQL schema as a string. - /// - /// The GraphQL schema. - /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). - /// The . - IRequestBuilder WithGraphQLSchema(string schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch); - - /// - /// WithGraphQLSchema: The GraphQL schema as a string. - /// - /// The GraphQL schema. - /// A dictionary defining the custom scalars used in this schema. (optional) - /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). - /// The . - IRequestBuilder WithGraphQLSchema(string schema, IDictionary? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch); - - /// - /// WithBodyAsGraphQL: The GraphQL schema as a string. - /// - /// The GraphQL schema. - /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). - /// The . - IRequestBuilder WithBodyAsGraphQL(string schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch); - - /// - /// WithBodyAsGraphQL: The GraphQL schema as a string. - /// - /// The GraphQL schema. - /// A dictionary defining the custom scalars used in this schema. (optional) - /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). - /// The . - IRequestBuilder WithBodyAsGraphQL(string schema, IDictionary? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch); - -#if GRAPHQL - /// - /// WithGraphQLSchema: The GraphQL schema as a ISchema. - /// - /// The GraphQL schema. - /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). - /// The . - IRequestBuilder WithGraphQLSchema(GraphQL.Types.ISchema schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch); - - /// - /// WithGraphQLSchema: The GraphQL schema as a ISchema. - /// - /// The GraphQL schema. - /// A dictionary defining the custom scalars used in this schema. (optional) - /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). - /// The . - IRequestBuilder WithGraphQLSchema(GraphQL.Types.ISchema schema, IDictionary? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch); - - /// - /// WithBodyAsGraphQL: The GraphQL schema as a ISchema. - /// - /// The GraphQL schema. - /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). - /// The . - IRequestBuilder WithBodyAsGraphQL(GraphQL.Types.ISchema schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch); - - /// - /// WithBodyAsGraphQL: The GraphQL schema as a ISchema. - /// - /// The GraphQL schema. - /// A dictionary defining the custom scalars used in this schema. (optional) - /// The match behaviour. (Default is MatchBehaviour.AcceptOnMatch). - /// The . - IRequestBuilder WithBodyAsGraphQL(GraphQL.Types.ISchema schema, IDictionary? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch); -#endif -} \ No newline at end of file diff --git a/src/WireMock.Net/RequestBuilders/IMultiPartRequestBuilder.cs b/src/WireMock.Net/RequestBuilders/IMultiPartRequestBuilder.cs deleted file mode 100644 index 4db8bc175..000000000 --- a/src/WireMock.Net/RequestBuilders/IMultiPartRequestBuilder.cs +++ /dev/null @@ -1,34 +0,0 @@ -using WireMock.Matchers; -using WireMock.Matchers.Request; - -namespace WireMock.RequestBuilders; - -/// -/// The MultiPartRequestBuilder interface. -/// -public interface IMultiPartRequestBuilder : IHttpVersionBuilder -{ - /// - /// WithMultiPart: IMatcher - /// - /// The matcher. - /// The . - IRequestBuilder WithMultiPart(IMatcher matcher); - - /// - /// WithMultiPart: IMatcher[], MatchBehaviour and MatchOperator - /// - /// The matchers. - /// The to use. - /// The to use. - /// The . - IRequestBuilder WithMultiPart(IMatcher[] matchers, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch, MatchOperator matchOperator = MatchOperator.Or); - - /// - /// WithMultiPart: MatchBehaviour and IMatcher[] - /// - /// The to use. - /// The matchers. - /// The . - IRequestBuilder WithMultiPart(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch, params IMatcher[] matchers); -} \ No newline at end of file diff --git a/src/WireMock.Net/RequestBuilders/IProtoBufRequestBuilder.cs b/src/WireMock.Net/RequestBuilders/IProtoBufRequestBuilder.cs deleted file mode 100644 index e13ec1e5d..000000000 --- a/src/WireMock.Net/RequestBuilders/IProtoBufRequestBuilder.cs +++ /dev/null @@ -1,45 +0,0 @@ -using WireMock.Matchers; - -namespace WireMock.RequestBuilders; - -/// -/// The ProtoBufRequestBuilder interface. -/// -public interface IProtoBufRequestBuilder : IGraphQLRequestBuilder -{ - /// - /// WithGrpcProto - /// - /// The proto definition as text. - /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}". - /// The match behaviour. (default = "AcceptOnMatch") - /// The . - IRequestBuilder WithBodyAsProtoBuf(string protoDefinition, string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch); - - /// - /// WithGrpcProto - /// - /// The proto definition as text. - /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}". - /// The matcher to use to match the ProtoBuf as (json) object. - /// The match behaviour. (default = "AcceptOnMatch") - /// The . - IRequestBuilder WithBodyAsProtoBuf(string protoDefinition, string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch); - - /// - /// WithGrpcProto - /// - /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}". - /// The match behaviour. (default = "AcceptOnMatch") - /// The . - IRequestBuilder WithBodyAsProtoBuf(string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch); - - /// - /// WithGrpcProto - /// - /// The full type of the protobuf (request/response) message object. Format is "{package-name}.{type-name}". - /// The matcher to use to match the ProtoBuf as (json) object. - /// The match behaviour. (default = "AcceptOnMatch") - /// The . - IRequestBuilder WithBodyAsProtoBuf(string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch); -} \ No newline at end of file diff --git a/src/WireMock.Net/RequestBuilders/IRequestBuilder.cs b/src/WireMock.Net/RequestBuilders/IRequestBuilder.cs index 753039058..8e0e923f5 100644 --- a/src/WireMock.Net/RequestBuilders/IRequestBuilder.cs +++ b/src/WireMock.Net/RequestBuilders/IRequestBuilder.cs @@ -1,3 +1,5 @@ +using WireMock.Matchers.Request; + namespace WireMock.RequestBuilders; /// @@ -5,4 +7,10 @@ namespace WireMock.RequestBuilders; /// public interface IRequestBuilder : IClientIPRequestBuilder { + /// + /// The link back to the Mapping. + /// + internal IMapping Mapping { get; set; } + + internal IRequestBuilder Add(T requestMatcher) where T : IRequestMatcher; } \ No newline at end of file diff --git a/src/WireMock.Net/RequestBuilders/Request.WithBody.cs b/src/WireMock.Net/RequestBuilders/Request.WithBody.cs index a64efb02d..60a0614a3 100644 --- a/src/WireMock.Net/RequestBuilders/Request.WithBody.cs +++ b/src/WireMock.Net/RequestBuilders/Request.WithBody.cs @@ -95,10 +95,4 @@ public IRequestBuilder WithBody(Func?, bool> func) _requestMatchers.Add(new RequestMessageBodyMatcher(Guard.NotNull(func))); return this; } - - /// - public IRequestBuilder WithBodyAsGraphQLSchema(string body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) - { - return WithGraphQLSchema(body, matchBehaviour); - } } \ No newline at end of file diff --git a/src/WireMock.Net/RequestBuilders/Request.WithBodyAsProtoBuf.cs b/src/WireMock.Net/RequestBuilders/Request.WithBodyAsProtoBuf.cs deleted file mode 100644 index 2c3eb187b..000000000 --- a/src/WireMock.Net/RequestBuilders/Request.WithBodyAsProtoBuf.cs +++ /dev/null @@ -1,31 +0,0 @@ -using WireMock.Matchers; -using WireMock.Matchers.Request; - -namespace WireMock.RequestBuilders; - -public partial class Request -{ - /// - public IRequestBuilder WithBodyAsProtoBuf(string protoDefinition, string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) - { - return Add(new RequestMessageProtoBufMatcher(matchBehaviour, () => new (null, protoDefinition), messageType)); - } - - /// - public IRequestBuilder WithBodyAsProtoBuf(string protoDefinition, string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) - { - return Add(new RequestMessageProtoBufMatcher(matchBehaviour, () => new(null, protoDefinition), messageType, matcher)); - } - - /// - public IRequestBuilder WithBodyAsProtoBuf(string messageType, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) - { - return Add(new RequestMessageProtoBufMatcher(matchBehaviour, () => Mapping.ProtoDefinition!.Value, messageType)); - } - - /// - public IRequestBuilder WithBodyAsProtoBuf(string messageType, IObjectMatcher matcher, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) - { - return Add(new RequestMessageProtoBufMatcher(matchBehaviour, () => Mapping.ProtoDefinition!.Value, messageType, matcher)); - } -} \ No newline at end of file diff --git a/src/WireMock.Net/RequestBuilders/Request.WithGraphQLSchema.cs b/src/WireMock.Net/RequestBuilders/Request.WithGraphQLSchema.cs deleted file mode 100644 index 43113c5b1..000000000 --- a/src/WireMock.Net/RequestBuilders/Request.WithGraphQLSchema.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.Collections.Generic; -using System; -using WireMock.Matchers; -using WireMock.Matchers.Request; - -namespace WireMock.RequestBuilders; - -public partial class Request -{ - /// - public IRequestBuilder WithGraphQLSchema(string schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) - { - return WithBodyAsGraphQL(schema, matchBehaviour); - } - - /// - public IRequestBuilder WithGraphQLSchema(string schema, IDictionary? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) - { - return WithBodyAsGraphQL(schema, customScalars, matchBehaviour); - } - - /// - public IRequestBuilder WithBodyAsGraphQL(string schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) - { - return Add(new RequestMessageGraphQLMatcher(matchBehaviour, schema)); - } - - /// - public IRequestBuilder WithBodyAsGraphQL(string schema, IDictionary? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) - { - return Add(new RequestMessageGraphQLMatcher(matchBehaviour, schema, customScalars)); - } - -#if GRAPHQL - /// - public IRequestBuilder WithGraphQLSchema(GraphQL.Types.ISchema schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) - { - return WithBodyAsGraphQL(schema, matchBehaviour); - } - - /// - public IRequestBuilder WithGraphQLSchema(GraphQL.Types.ISchema schema, IDictionary? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) - { - return WithBodyAsGraphQL(schema, customScalars, matchBehaviour); - } - - /// - public IRequestBuilder WithBodyAsGraphQL(GraphQL.Types.ISchema schema, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) - { - return Add(new RequestMessageGraphQLMatcher(matchBehaviour, schema)); - } - - /// - public IRequestBuilder WithBodyAsGraphQL(GraphQL.Types.ISchema schema, IDictionary? customScalars, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) - { - return Add(new RequestMessageGraphQLMatcher(matchBehaviour, schema, customScalars)); - } -#endif -} \ No newline at end of file diff --git a/src/WireMock.Net/RequestBuilders/Request.WithMultiPart.cs b/src/WireMock.Net/RequestBuilders/Request.WithMultiPart.cs deleted file mode 100644 index 64011c307..000000000 --- a/src/WireMock.Net/RequestBuilders/Request.WithMultiPart.cs +++ /dev/null @@ -1,28 +0,0 @@ -using WireMock.Matchers; -using WireMock.Matchers.Request; - -namespace WireMock.RequestBuilders; - -public partial class Request -{ - /// - public IRequestBuilder WithMultiPart(IMatcher matcher) - { - _requestMatchers.Add(new RequestMessageMultiPartMatcher(matcher)); - return this; - } - - /// - public IRequestBuilder WithMultiPart(IMatcher[] matchers, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch, MatchOperator matchOperator = MatchOperator.Or) - { - _requestMatchers.Add(new RequestMessageMultiPartMatcher(matchBehaviour, matchOperator, matchers)); - return this; - } - - /// - public IRequestBuilder WithMultiPart(MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch, params IMatcher[] matchers) - { - _requestMatchers.Add(new RequestMessageMultiPartMatcher(matchBehaviour, MatchOperator.Or, matchers)); - return this; - } -} \ No newline at end of file diff --git a/src/WireMock.Net/RequestBuilders/Request.cs b/src/WireMock.Net/RequestBuilders/Request.cs index f375b6987..c27b6c13c 100644 --- a/src/WireMock.Net/RequestBuilders/Request.cs +++ b/src/WireMock.Net/RequestBuilders/Request.cs @@ -16,9 +16,7 @@ public partial class Request : RequestMessageCompositeMatcher, IRequestBuilder { private readonly IList _requestMatchers; - /// - /// The link back to the Mapping. - /// + /// public IMapping Mapping { get; set; } = null!; /// @@ -69,7 +67,8 @@ private Request(IList requestMatchers) : base(requestMatchers) return _requestMatchers.OfType().FirstOrDefault(func); } - private IRequestBuilder Add(T requestMatcher) where T : IRequestMatcher + /// + public IRequestBuilder Add(T requestMatcher) where T : IRequestMatcher { foreach (var existing in _requestMatchers.OfType().ToArray()) { diff --git a/src/WireMock.Net/RequestMessage.cs b/src/WireMock.Net/RequestMessage.cs index 20b4518e9..50a86e37f 100644 --- a/src/WireMock.Net/RequestMessage.cs +++ b/src/WireMock.Net/RequestMessage.cs @@ -80,11 +80,9 @@ public class RequestMessage : IRequestMessage /// public byte[]? BodyAsBytes { get; } -#if MIMEKIT /// [Newtonsoft.Json.JsonIgnore] // Issue 1001 public object? BodyAsMimeMessage { get; } -#endif /// public string? DetectedBodyType { get; } @@ -180,19 +178,17 @@ public class RequestMessage : IRequestMessage ClientCertificate = clientCertificate; #endif -#if MIMEKIT try { - if (MimeKitUtils.TryGetMimeMessage(this, out var mimeMessage)) + if (TypeLoader.TryFindType(out _) && TypeLoader.Load().TryGetMimeMessage(this, out var mimeMessage)) { BodyAsMimeMessage = mimeMessage; } } catch { - // Ignore exception from MimeMessage.Load + // Ignore exception from IMimeKitUtils.TryGetMimeMessage } -#endif } /// diff --git a/src/WireMock.Net/ResponseBuilders/Response.WithBody.cs b/src/WireMock.Net/ResponseBuilders/Response.WithBody.cs index 1fd6c451e..daf7add8c 100644 --- a/src/WireMock.Net/ResponseBuilders/Response.WithBody.cs +++ b/src/WireMock.Net/ResponseBuilders/Response.WithBody.cs @@ -221,18 +221,15 @@ public IResponseBuilder WithBody(object body, Encoding? encoding, IJsonConverter Guard.NotNullOrWhiteSpace(messageType); Guard.NotNull(value); -#if !PROTOBUF - throw new System.NotSupportedException("The WithBodyAsProtoBuf method can not be used for .NETStandard1.3 or .NET Framework 4.6.1 or lower."); -#else ResponseMessage.BodyDestination = null; ResponseMessage.BodyData = new BodyData { DetectedBodyType = BodyType.ProtoBuf, BodyAsJson = value, - ProtoDefinition = () => new (null, protoDefinition), + ProtoDefinition = () => new(null, protoDefinition), ProtoBufMessageType = messageType }; -#endif + return this; } @@ -247,9 +244,6 @@ public IResponseBuilder WithBody(object body, Encoding? encoding, IJsonConverter Guard.NotNullOrWhiteSpace(messageType); Guard.NotNull(value); -#if !PROTOBUF - throw new System.NotSupportedException("The WithBodyAsProtoBuf method can not be used for .NETStandard1.3 or .NET Framework 4.6.1 or lower."); -#else ResponseMessage.BodyDestination = null; ResponseMessage.BodyData = new BodyData { @@ -258,7 +252,7 @@ public IResponseBuilder WithBody(object body, Encoding? encoding, IJsonConverter ProtoDefinition = () => Mapping.ProtoDefinition ?? throw new WireMockException("ProtoDefinition cannot be resolved. You probably forgot to call .WithProtoDefinition(...) on the mapping."), ProtoBufMessageType = messageType }; -#endif + return this; } } \ No newline at end of file diff --git a/src/WireMock.Net/ResponseBuilders/Response.cs b/src/WireMock.Net/ResponseBuilders/Response.cs index 7932dcfde..1d13b886f 100644 --- a/src/WireMock.Net/ResponseBuilders/Response.cs +++ b/src/WireMock.Net/ResponseBuilders/Response.cs @@ -287,7 +287,7 @@ string RemoveFirstOccurrence(string source, string find) // Check if the body matcher is a RequestMessageProtoBufMatcher and try to to decode the byte-array to a BodyAsJson. if (mapping.RequestMatcher is Request requestMatcher && requestMessage is RequestMessage request) { - var protoBufMatcher = requestMatcher.GetRequestMessageMatcher()?.Matcher; + var protoBufMatcher = requestMatcher.GetRequestMessageMatcher()?.Matcher; if (protoBufMatcher != null) { var decoded = await protoBufMatcher.DecodeAsync(request.BodyData?.BodyAsBytes).ConfigureAwait(false); diff --git a/src/WireMock.Net/Serialization/MappingConverter.cs b/src/WireMock.Net/Serialization/MappingConverter.cs index 27676b249..49b5e40f2 100644 --- a/src/WireMock.Net/Serialization/MappingConverter.cs +++ b/src/WireMock.Net/Serialization/MappingConverter.cs @@ -48,9 +48,9 @@ public string ToCSharpCode(IMapping mapping, MappingConverterSettings? settings var methodMatcher = request.GetRequestMessageMatcher(); var requestMessageBodyMatcher = request.GetRequestMessageMatcher(); var requestMessageHttpVersionMatcher = request.GetRequestMessageMatcher(); - var requestMessageGraphQLMatcher = request.GetRequestMessageMatcher(); - var requestMessageMultiPartMatcher = request.GetRequestMessageMatcher(); - var requestMessageProtoBufMatcher = request.GetRequestMessageMatcher(); + var requestMessageGraphQLMatcher = request.GetRequestMessageMatcher(); + var requestMessageMultiPartMatcher = request.GetRequestMessageMatcher(); + var requestMessageProtoBufMatcher = request.GetRequestMessageMatcher(); var sb = new StringBuilder(); @@ -114,32 +114,26 @@ public string ToCSharpCode(IMapping mapping, MappingConverterSettings? settings sb.AppendLine($" .WithHttpVersion({requestMessageHttpVersionMatcher.HttpVersion})"); } -#if GRAPHQL if (requestMessageGraphQLMatcher is { Matchers: { } }) { - if (requestMessageGraphQLMatcher.Matchers.OfType().FirstOrDefault() is { } graphQLMatcher && graphQLMatcher.GetPatterns().Any()) + if (requestMessageGraphQLMatcher.Matchers.OfType().FirstOrDefault() is { } graphQLMatcher && graphQLMatcher.GetPatterns().Any()) { sb.AppendLine($" .WithGraphQLSchema({GetString(graphQLMatcher)})"); } } -#endif -#if MIMEKIT if (requestMessageMultiPartMatcher is { Matchers: { } }) { - if (requestMessageMultiPartMatcher.Matchers.OfType().Any()) + if (requestMessageMultiPartMatcher.Matchers.OfType().Any()) { sb.AppendLine(" // .WithMultiPart() is not yet supported"); } } -#endif -#if PROTOBUF if (requestMessageProtoBufMatcher is { Matcher: { } }) { sb.AppendLine(" // .WithBodyAsProtoBuf() is not yet supported"); } -#endif if (requestMessageBodyMatcher is { Matchers: { } }) { @@ -254,11 +248,11 @@ public MappingModel ToMappingModel(IMapping mapping) var cookieMatchers = request.GetRequestMessageMatchers(); var paramsMatchers = request.GetRequestMessageMatchers(); var methodMatcher = request.GetRequestMessageMatcher(); - var bodyMatcher = request.GetRequestMessageMatcher(); - var graphQLMatcher = request.GetRequestMessageMatcher(); - var multiPartMatcher = request.GetRequestMessageMatcher(); - var protoBufMatcher = request.GetRequestMessageMatcher(); var httpVersionMatcher = request.GetRequestMessageMatcher(); + var bodyMatcher = request.GetRequestMessageMatcher(); + var graphQLMatcher = request.GetRequestMessageMatcher(); + var multiPartMatcher = request.GetRequestMessageMatcher(); + var protoBufMatcher = request.GetRequestMessageMatcher(); var mappingModel = new MappingModel { @@ -381,13 +375,11 @@ public MappingModel ToMappingModel(IMapping mapping) { void AfterMap(MatcherModel matcherModel) { -#if PROTOBUF // In case the ProtoDefinition is defined at the Mapping level, clear the Pattern at the Matcher level - if (bodyMatchers?.OfType().Any() == true && mappingModel.ProtoDefinition != null) + if (bodyMatchers?.OfType().Any() == true && mappingModel.ProtoDefinition != null) { matcherModel.Pattern = null; } -#endif } mappingModel.Request.Body = new BodyModel(); diff --git a/src/WireMock.Net/Serialization/MatcherMapper.cs b/src/WireMock.Net/Serialization/MatcherMapper.cs index 0041e20d6..4d8b2135d 100644 --- a/src/WireMock.Net/Serialization/MatcherMapper.cs +++ b/src/WireMock.Net/Serialization/MatcherMapper.cs @@ -65,20 +65,17 @@ public MatcherMapper(WireMockServerSettings settings) case nameof(ExactObjectMatcher): return CreateExactObjectMatcher(matchBehaviour, stringPatterns[0]); -#if GRAPHQL - case nameof(GraphQLMatcher): - return new GraphQLMatcher(stringPatterns[0].GetPattern(), matcherModel.CustomScalars, matchBehaviour, matchOperator); -#endif -#if MIMEKIT - case nameof(MimePartMatcher): + case "GraphQLMatcher": + var schema = new AnyOf(stringPatterns[0].GetPattern()); + return TypeLoader.Load(schema, matcherModel.CustomScalars, matchBehaviour, matchOperator); + + case "MimePartMatcher": return CreateMimePartMatcher(matchBehaviour, matcherModel); -#endif -#if PROTOBUF - case nameof(ProtoBufMatcher): + case "ProtoBufMatcher": return CreateProtoBufMatcher(matchBehaviour, stringPatterns[0].GetPattern(), matcherModel); -#endif + case nameof(RegexMatcher): return new RegexMatcher(matchBehaviour, stringPatterns, ignoreCase, useRegexExtended, matchOperator); @@ -159,11 +156,10 @@ public MatcherMapper(WireMockServerSettings settings) case XPathMatcher xpathMatcher: model.XmlNamespaceMap = xpathMatcher.XmlNamespaceMap; break; -#if GRAPHQL - case GraphQLMatcher graphQLMatcher: + + case IGraphQLMatcher graphQLMatcher: model.CustomScalars = graphQLMatcher.CustomScalars; break; -#endif } switch (matcher) @@ -195,22 +191,18 @@ public MatcherMapper(WireMockServerSettings settings) model.Pattern = objectMatcher.Value; break; -#if MIMEKIT - case MimePartMatcher mimePartMatcher: + case IMimePartMatcher mimePartMatcher: model.ContentDispositionMatcher = Map(mimePartMatcher.ContentDispositionMatcher); model.ContentMatcher = Map(mimePartMatcher.ContentMatcher); model.ContentTransferEncodingMatcher = Map(mimePartMatcher.ContentTransferEncodingMatcher); model.ContentTypeMatcher = Map(mimePartMatcher.ContentTypeMatcher); break; -#endif -#if PROTOBUF - case ProtoBufMatcher protoBufMatcher: + case IProtoBufMatcher protoBufMatcher: model.Pattern = protoBufMatcher.ProtoDefinition().Value; model.ProtoBufMessageType = protoBufMatcher.MessageType; model.ContentMatcher = Map(protoBufMatcher.Matcher); break; -#endif } afterMap?.Invoke(model); @@ -260,20 +252,17 @@ private static ExactObjectMatcher CreateExactObjectMatcher(MatchBehaviour matchB return new ExactObjectMatcher(matchBehaviour, bytePattern); } -#if MIMEKIT - private MimePartMatcher CreateMimePartMatcher(MatchBehaviour matchBehaviour, MatcherModel matcher) + private IMimePartMatcher CreateMimePartMatcher(MatchBehaviour matchBehaviour, MatcherModel matcher) { - var contentTypeMatcher = Map(matcher?.ContentTypeMatcher) as IStringMatcher; - var contentDispositionMatcher = Map(matcher?.ContentDispositionMatcher) as IStringMatcher; - var contentTransferEncodingMatcher = Map(matcher?.ContentTransferEncodingMatcher) as IStringMatcher; - var contentMatcher = Map(matcher?.ContentMatcher); + var contentTypeMatcher = Map(matcher.ContentTypeMatcher) as IStringMatcher; + var contentDispositionMatcher = Map(matcher.ContentDispositionMatcher) as IStringMatcher; + var contentTransferEncodingMatcher = Map(matcher.ContentTransferEncodingMatcher) as IStringMatcher; + var contentMatcher = Map(matcher.ContentMatcher); - return new MimePartMatcher(matchBehaviour, contentTypeMatcher, contentDispositionMatcher, contentTransferEncodingMatcher, contentMatcher); + return TypeLoader.Load(matchBehaviour, contentTypeMatcher, contentDispositionMatcher, contentTransferEncodingMatcher, contentMatcher); } -#endif -#if PROTOBUF - private ProtoBufMatcher CreateProtoBufMatcher(MatchBehaviour? matchBehaviour, string protoDefinitionOrId, MatcherModel matcher) + private IProtoBufMatcher CreateProtoBufMatcher(MatchBehaviour? matchBehaviour, string protoDefinitionOrId, MatcherModel matcher) { var objectMatcher = Map(matcher.ContentMatcher) as IObjectMatcher; @@ -287,12 +276,11 @@ private ProtoBufMatcher CreateProtoBufMatcher(MatchBehaviour? matchBehaviour, st protoDefinition = new(null, protoDefinitionOrId); } - return new ProtoBufMatcher( + return TypeLoader.Load( () => protoDefinition, - matcher!.ProtoBufMessageType!, + matcher.ProtoBufMessageType!, matchBehaviour ?? MatchBehaviour.AcceptOnMatch, objectMatcher ); } -#endif } \ No newline at end of file diff --git a/src/WireMock.Net/Util/IMimeKitUtils.cs b/src/WireMock.Net/Util/IMimeKitUtils.cs new file mode 100644 index 000000000..614e542a5 --- /dev/null +++ b/src/WireMock.Net/Util/IMimeKitUtils.cs @@ -0,0 +1,8 @@ +using System.Diagnostics.CodeAnalysis; + +namespace WireMock.Util; + +internal interface IMimeKitUtils +{ + bool TryGetMimeMessage(IRequestMessage requestMessage, [NotNullWhen(true)] out object? mimeMessage); +} \ No newline at end of file diff --git a/src/WireMock.Net/Util/IProtoBufUtils.cs b/src/WireMock.Net/Util/IProtoBufUtils.cs new file mode 100644 index 000000000..48ffdb605 --- /dev/null +++ b/src/WireMock.Net/Util/IProtoBufUtils.cs @@ -0,0 +1,17 @@ +using System.Threading; +using System.Threading.Tasks; +using JsonConverter.Abstractions; + +namespace WireMock.Util; + +internal interface IProtoBufUtils +{ + Task GetProtoBufMessageWithHeaderAsync( + string? protoDefinition, + string? messageType, + object? value, + IJsonConverter? jsonConverter = null, + JsonConverterOptions? options = null, + CancellationToken cancellationToken = default + ); +} \ No newline at end of file diff --git a/src/WireMock.Net/Util/TypeLoader.cs b/src/WireMock.Net/Util/TypeLoader.cs index fcd27e779..d52262480 100644 --- a/src/WireMock.Net/Util/TypeLoader.cs +++ b/src/WireMock.Net/Util/TypeLoader.cs @@ -10,43 +10,47 @@ namespace WireMock.Util; internal static class TypeLoader { - private static readonly ConcurrentDictionary Assemblies = new(); + private static readonly ConcurrentDictionary FoundTypes = new(); - public static TInterface Load(params object[] args) where TInterface : class + public static bool TryFindType([NotNullWhen(true)] out Type? pluginType) where TInterface : class { var key = typeof(TInterface).FullName!; - var pluginType = Assemblies.GetOrAdd(key, _ => - { - if (TryFindTypeInDlls(null, out var foundType)) - { - return foundType; - } + pluginType = FoundTypes.GetOrAdd(key, _ => TryFindTypeInDlls(null, out var foundType) ? foundType : null); - throw new DllNotFoundException($"No dll found which implements Interface '{key}'."); - }); - - return (TInterface)Activator.CreateInstance(pluginType, args)!; + return pluginType != null; } - public static TInterface LoadByFullName(string implementationTypeFullName, params object[] args) where TInterface : class + public static bool TryFindType(string implementationTypeFullName, [NotNullWhen(true)] out Type? pluginType) where TInterface : class { - Guard.NotNullOrEmpty(implementationTypeFullName); - var @interface = typeof(TInterface).FullName; var key = $"{@interface}_{implementationTypeFullName}"; - var pluginType = Assemblies.GetOrAdd(key, _ => + pluginType = FoundTypes.GetOrAdd(key, _ => TryFindTypeInDlls(implementationTypeFullName, out var foundType) ? foundType : null); + + return pluginType != null; + } + + public static TInterface Load(params object?[] args) where TInterface : class + { + if (TryFindType(out var pluginType)) { - if (TryFindTypeInDlls(implementationTypeFullName, out var foundType)) - { - return foundType; - } + return (TInterface)Activator.CreateInstance(pluginType, args)!; + } + + throw new DllNotFoundException($"No dll found which implements Interface '{typeof(TInterface).FullName}'."); + } - throw new DllNotFoundException($"No dll found which implements Interface '{@interface}' and has FullName '{implementationTypeFullName}'."); - }); + public static TInterface LoadByFullName(string implementationTypeFullName, params object?[] args) where TInterface : class + { + Guard.NotNullOrEmpty(implementationTypeFullName); + + if (TryFindType(implementationTypeFullName, out var pluginType)) + { + return (TInterface)Activator.CreateInstance(pluginType, args)!; + } - return (TInterface)Activator.CreateInstance(pluginType, args)!; + throw new DllNotFoundException($"No dll found which implements Interface '{typeof(TInterface).FullName}' and has FullName '{implementationTypeFullName}'."); } private static bool TryFindTypeInDlls(string? implementationTypeFullName, [NotNullWhen(true)] out Type? pluginType) where TInterface : class diff --git a/src/WireMock.Net/WireMock.Net.csproj b/src/WireMock.Net/WireMock.Net.csproj index 4973e072f..55a19e74c 100644 --- a/src/WireMock.Net/WireMock.Net.csproj +++ b/src/WireMock.Net/WireMock.Net.csproj @@ -3,7 +3,7 @@ Lightweight Http Mocking Server for .Net, inspired by WireMock from the Java landscape. WireMock.Net Stef Heyenrath - net451;net452;net46;net461;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 + net451;net452;net46;net461;netstandard1.3;netstandard2.0;netstandard2.1;netcoreapp3.1;net5.0;net6.0;net8.0 true WireMock.Net WireMock.Net @@ -38,7 +38,7 @@ $(DefineConstants);NETSTANDARD;USE_ASPNETCORE - + $(DefineConstants);USE_ASPNETCORE @@ -50,14 +50,30 @@ $(DefineConstants);OPENAPIPARSER - - $(DefineConstants);GRAPHQL;MIMEKIT;PROTOBUF - - $(DefineConstants);TRAILINGHEADERS + + $(DefineConstants);GRAPHQL + true + + + + $(DefineConstants);MIMEKIT + true + + + + $(DefineConstants);PROTOBUF + true + + + + $(DefineConstants);CSHARPMATCHER + true + + @@ -143,18 +159,11 @@ - + - - - - - - - all @@ -198,4 +207,44 @@ + + + + %(RecursiveDir)/%(FileName)%(Extension) + + + %(RecursiveDir)/%(FileName)%(Extension) + + + %(RecursiveDir)/%(FileName)%(Extension) + + + %(RecursiveDir)/%(FileName)%(Extension) + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/dotnet-WireMock.Net/dotnet-WireMock.csproj b/src/dotnet-WireMock.Net/dotnet-WireMock.csproj index 97a7089c4..884eeb396 100644 --- a/src/dotnet-WireMock.Net/dotnet-WireMock.csproj +++ b/src/dotnet-WireMock.Net/dotnet-WireMock.csproj @@ -1,27 +1,27 @@ - - Exe - net8.0 - true - dotnet-wiremock - A dotnet commandline tool for WireMock.Net (A Lightweight Http Mocking Server for .NET) - tdd;mock;http;wiremock;test;server;unittest;dotnet;tool;dotnet-tool - MIT - Stef Heyenrath - + + Exe + net8.0 + true + dotnet-wiremock + A dotnet commandline tool for WireMock.Net (A Lightweight Http Mocking Server for .NET) which includes GraphQL-support, ProtoBuf-support, MimePartMatcher and CSharpCodeMatcher. + tdd;mock;http;wiremock;test;server;unittest;dotnet;tool;dotnet-tool + MIT + Stef Heyenrath + - - true - + + true + - - - - + + + + - - - + + + \ No newline at end of file diff --git a/test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.GetMappingsAsync.cs b/test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.GetMappingsAsync.cs index 637db397b..de26bccba 100644 --- a/test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.GetMappingsAsync.cs +++ b/test/WireMock.Net.Tests/AdminApi/WireMockAdminApiTests.GetMappingsAsync.cs @@ -1,4 +1,4 @@ -#if !(NET452 || NET461 || NETCOREAPP3_1) +#if PROTOBUF using System.Threading.Tasks; using RestEase; using VerifyXunit; diff --git a/test/WireMock.Net.Tests/Util/JsonUtilsTests.cs b/test/WireMock.Net.Tests/Util/JsonUtilsTests.cs index 600d80d07..dc240bfc8 100644 --- a/test/WireMock.Net.Tests/Util/JsonUtilsTests.cs +++ b/test/WireMock.Net.Tests/Util/JsonUtilsTests.cs @@ -1,10 +1,5 @@ using System; -using System.Linq; -using System.Linq.Dynamic.Core; -using System.Reflection; using FluentAssertions; -using Newtonsoft.Json.Linq; -using NFluent; using WireMock.Util; using Xunit; @@ -50,144 +45,4 @@ public void JsonUtils_ParseJTokenToObject_For_Invalid_Throws() // Assert action.Should().Throw(); } - - [Fact] - public void JsonUtils_GenerateDynamicLinqStatement_JToken() - { - // Assign - JToken instance = "Test"; - - // Act - string line = JsonUtils.GenerateDynamicLinqStatement(instance); - - // Assert - var queryable = new[] { instance }.AsQueryable().Select(line); - bool result = queryable.Any("it == \"Test\""); - Check.That(result).IsTrue(); - - Check.That(line).IsEqualTo("string(it)"); - } - - [Fact] - public void JsonUtils_GenerateDynamicLinqStatement_JArray_Indexer() - { - // Assign - var instance = new JObject - { - { "Items", new JArray(new JValue(4), new JValue(8)) } - }; - - // Act - string line = JsonUtils.GenerateDynamicLinqStatement(instance); - - // Assert 1 - line.Should().Be("new ((new [] { long(Items[0]), long(Items[1])}) as Items)"); - - // Assert 2 - var queryable = new[] { instance }.AsQueryable().Select(line); - bool result = queryable.Any("Items != null"); - result.Should().BeTrue(); - } - - [Fact] - public void JsonUtils_GenerateDynamicLinqStatement_JObject2() - { - // Assign - var instance = new JObject - { - {"U", new JValue(new Uri("http://localhost:80/abc?a=5"))}, - {"N", new JValue((object?) null)}, - {"G", new JValue(Guid.NewGuid())}, - {"Flt", new JValue(10.0f)}, - {"Dbl", new JValue(Math.PI)}, - {"Check", new JValue(true)}, - { - "Child", new JObject - { - {"ChildId", new JValue(4)}, - {"ChildDateTime", new JValue(new DateTime(2018, 2, 17))}, - {"TS", new JValue(TimeSpan.FromMilliseconds(999))} - } - }, - {"I", new JValue(9)}, - {"L", new JValue(long.MaxValue)}, - {"Name", new JValue("Test")} - }; - - // Act - string line = JsonUtils.GenerateDynamicLinqStatement(instance); - - // Assert 1 - line.Should().Be("new (Uri(U) as U, null as N, Guid(G) as G, double(Flt) as Flt, double(Dbl) as Dbl, bool(Check) as Check, new (long(Child.ChildId) as ChildId, DateTime(Child.ChildDateTime) as ChildDateTime, TimeSpan(Child.TS) as TS) as Child, long(I) as I, long(L) as L, string(Name) as Name)"); - - // Assert 2 - var queryable = new[] { instance }.AsQueryable().Select(line); - bool result = queryable.Any("I > 1 && L > 1"); - result.Should().BeTrue(); - } - - [Fact] - public void JsonUtils_GenerateDynamicLinqStatement_Throws() - { - // Assign - var instance = new JObject - { - { "B", new JValue(new byte[] {48, 49}) } - }; - - // Act and Assert - Check.ThatCode(() => JsonUtils.GenerateDynamicLinqStatement(instance)).Throws(); - } - - [Fact] - public void JsonUtils_CreateTypeFromJObject() - { - // Assign - var instance = new JObject - { - {"U", new JValue(new Uri("http://localhost:80/abc?a=5"))}, - {"N", new JValue((object?) null)}, - {"G", new JValue(Guid.NewGuid())}, - {"Flt", new JValue(10.0f)}, - {"Dbl", new JValue(Math.PI)}, - {"Check", new JValue(true)}, - { - "Child", new JObject - { - {"ChildId", new JValue(4)}, - {"ChildDateTime", new JValue(new DateTime(2018, 2, 17))}, - {"ChildTimeSpan", new JValue(TimeSpan.FromMilliseconds(999))} - } - }, - {"I", new JValue(9)}, - {"L", new JValue(long.MaxValue)}, - {"S", new JValue("Test")}, - {"C", new JValue('c')} - }; - - // Act - var type = JsonUtils.CreateTypeFromJObject(instance); - - // Assert - var setProperties = type - .GetProperties(BindingFlags.Public | BindingFlags.Instance) - .Where(pi => pi.GetMethod != null).Select(pi => $"{pi.GetMethod}") - .ToArray(); - - setProperties.Should().HaveCount(11); - setProperties.Should().BeEquivalentTo(new[] - { - "System.String get_U()", - "System.Object get_N()", - "System.Guid get_G()", - "Single get_Flt()", - "Single get_Dbl()", - "Boolean get_Check()", - "Child get_Child()", - "Int64 get_I()", - "Int64 get_L()", - "System.String get_S()", - "System.String get_C()" - }); - } } \ No newline at end of file diff --git a/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj b/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj index d47c90573..2178b0233 100644 --- a/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj +++ b/test/WireMock.Net.Tests/WireMock.Net.Tests.csproj @@ -2,7 +2,7 @@ Stef Heyenrath - net452;net461;netcoreapp3.1;net6.0;net7.0;net8.0 + net452;net461;netcoreapp3.1;net6.0;net8.0 11 enable false @@ -26,34 +26,34 @@ NETFRAMEWORK - - $(DefineConstants);GRAPHQL;MIMEKIT;PROTOBUF + + $(DefineConstants);GRAPHQL + true + + + + $(DefineConstants);MIMEKIT + true + + + + $(DefineConstants);PROTOBUF + true $(DefineConstants);TRAILINGHEADERS - - - - - - + - @@ -107,7 +107,6 @@ - @@ -118,7 +117,7 @@ - +