Beispiel #1
0
        public void PostConfigure_DoesNotSetProblemDetailsFactoryWithLegacyCompatBehavior()
        {
            // Arrange
            var optionsSetup = new ApiBehaviorOptionsSetup(
                NullLoggerFactory.Instance,
                Options.Create(new MvcCompatibilityOptions {
                CompatibilityVersion = CompatibilityVersion.Version_2_1
            }));
            var options = new ApiBehaviorOptions();

            // Act
            optionsSetup.Configure(options);
            optionsSetup.PostConfigure(string.Empty, options);

            // Assert
            Assert.Same(ApiBehaviorOptionsSetup.DefaultFactory, options.InvalidModelStateResponseFactory);
        }
Beispiel #2
0
        public void PostConfigure_DoesNotSetProblemDetailsFactory_IfValueWasModified()
        {
            // Arrange
            var optionsSetup = new ApiBehaviorOptionsSetup(
                NullLoggerFactory.Instance,
                Options.Create(new MvcCompatibilityOptions {
                CompatibilityVersion = CompatibilityVersion.Latest
            }));
            var options = new ApiBehaviorOptions();
            Func <ActionContext, IActionResult> expected = _ => null;

            // Act
            optionsSetup.Configure(options);
            // This is equivalent to user code updating the value via ConfigureOptions
            options.InvalidModelStateResponseFactory = expected;
            optionsSetup.PostConfigure(string.Empty, options);

            // Assert
            Assert.Same(expected, options.InvalidModelStateResponseFactory);
        }