// This source file is based on mock4net by Alexandre Victoor which is licensed under the Apache 2.0 License. // For more details see 'mock4net/LICENSE.txt' and 'mock4net/readme.md' in this project root. using System; using System.Collections.Generic; using JsonConverter.Abstractions; using Newtonsoft.Json; using Stef.Validation; using WireMock.Matchers; using WireMock.Matchers.Request; using WireMock.Util; namespace WireMock.RequestBuilders; public partial class Request { /// public IRequestBuilder WithBody(string body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) { _requestMatchers.Add(new RequestMessageBodyMatcher(matchBehaviour, body)); return this; } /// public IRequestBuilder WithBody(byte[] body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) { _requestMatchers.Add(new RequestMessageBodyMatcher(matchBehaviour, body)); return this; } /// public IRequestBuilder WithBody(object body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) { _requestMatchers.Add(new RequestMessageBodyMatcher(matchBehaviour, body)); return this; } /// public IRequestBuilder WithBodyAsJson(object body, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) { var bodyAsJsonString = JsonConvert.SerializeObject(body); _requestMatchers.Add(new RequestMessageBodyMatcher(matchBehaviour, bodyAsJsonString)); return this; } /// public IRequestBuilder WithBodyAsJson(object body, IJsonConverter converter, JsonConverterOptions? options = null, MatchBehaviour matchBehaviour = MatchBehaviour.AcceptOnMatch) { Guard.NotNull(converter); var bodyAsJsonString = converter.Serialize(body, options); _requestMatchers.Add(new RequestMessageBodyMatcher(matchBehaviour, bodyAsJsonString)); return this; } /// public IRequestBuilder WithBody(IMatcher matcher) { return WithBody(new[] { matcher }); } /// public IRequestBuilder WithBody(IMatcher[] matchers, MatchOperator matchOperator = MatchOperator.Or) { Guard.NotNull(matchers); _requestMatchers.Add(new RequestMessageBodyMatcher(matchOperator, matchers)); return this; } /// public IRequestBuilder WithBody(Func func) { Guard.NotNull(func); _requestMatchers.Add(new RequestMessageBodyMatcher(func)); return this; } /// public IRequestBuilder WithBody(Func func) { Guard.NotNull(func); _requestMatchers.Add(new RequestMessageBodyMatcher(func)); return this; } /// public IRequestBuilder WithBody(Func func) { Guard.NotNull(func); _requestMatchers.Add(new RequestMessageBodyMatcher(func)); return this; } /// public IRequestBuilder WithBody(Func func) { Guard.NotNull(func); _requestMatchers.Add(new RequestMessageBodyMatcher(func)); return this; } /// public IRequestBuilder WithBody(Func?, bool> func) { _requestMatchers.Add(new RequestMessageBodyMatcher(Guard.NotNull(func))); return this; } }