Beispiel #1
0
        public async Task body_binding___returns_413_payloadtoolarge_for_xml_deserialized_exceeding_configured_max()
        {
            base.SetupEnvironment(services =>
            {
                var jsonFormattingConfiguration = new JsonMediaSerializerConfiguration();

                var instanceMock = new Mock <DeepSleepXmlMediaSerializer>(new object[] { null })
                {
                    CallBase = true
                };
                instanceMock
                .Setup(m => m.ReadType(It.IsAny <Stream>(), It.IsAny <Type>(), It.IsAny <IMediaSerializerOptions>()))
                .Throws(new MockBadHttpRequestException());

                services.RemoveAll(typeof(IDeepSleepMediaSerializer));
                services.AddScoped(typeof(IDeepSleepMediaSerializer), (p) => instanceMock.Object);
            });



            var request = @$ "
POST https://{host}/binding/body/max/request/length HTTP/1.1
Host: {host}
Connection: keep-alive
User-Agent: UnitTest/1.0 DEV
Accept: {applicationXml}
Content-Type: {applicationXml}
Content-Length: 1

<MaxRequestLengthModel>
    <Value>This is way too long of a request</Value>
</MaxRequestLengthModel>";

            using var httpContext = new MockHttpContext(this.ServiceProvider, request);
            var apiContext = await Invoke(httpContext).ConfigureAwait(false);

            var response = httpContext.Response;

            base.AssertResponse(
                apiContext: apiContext,
                response: response,
                expectedHttpStatus: 413,
                shouldHaveResponse: false,
                expectedValidationState: ApiValidationState.NotAttempted,
                extendedHeaders: new NameValuePairs <string, string>
            {
            });
        }
Beispiel #2
0
        /// <summary>Uses the deep sleep json negotiation.</summary>
        /// <param name="services">The services.</param>
        /// <param name="configure">The configure.</param>
        /// <returns></returns>
        public static IServiceCollection UseDeepSleepJsonNegotiation(this IServiceCollection services, Action <JsonMediaSerializerConfiguration> configure = null)
        {
            var configuration = new JsonMediaSerializerConfiguration
            {
                SerializerOptions = GetJsonSerializerSettings()
            };

            if (configure != null)
            {
                configure(configuration);
            }

            services.AddScoped <IDeepSleepMediaSerializer, DeepSleepJsonMediaSerializer>();
            services.AddSingleton <JsonMediaSerializerConfiguration>((p) => configuration);

            return(services);
        }
Beispiel #3
0
 /// <summary>Initializes a new instance of the <see cref="CustomObjectEndpoints"/> class.</summary>
 /// <param name="jsonFormattingConfiguration">The json formatting configuration.</param>
 public CustomObjectEndpoints(JsonMediaSerializerConfiguration jsonFormattingConfiguration)
 {
     this.jsonFormattingConfiguration = jsonFormattingConfiguration;
 }
Beispiel #4
0
 /// <summary>Initializes a new instance of the <see cref="DeepSleepJsonMediaSerializer" /> class.</summary>
 /// <param name="jsonFormattingConfiguration">The json formatting configuration.</param>
 public DeepSleepJsonMediaSerializer(JsonMediaSerializerConfiguration jsonFormattingConfiguration)
 {
     this.jsonFormattingConfiguration = jsonFormattingConfiguration;
 }