示例#1
0
 /// <summary>
 /// Initializes a new instance of <see cref="XmlSerializerMvcOptionsSetup"/>.
 /// </summary>
 /// <param name="xmlOptions"><see cref="MvcXmlOptions"/>.</param>
 /// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
 public XmlSerializerMvcOptionsSetup(
     IOptions <MvcXmlOptions> xmlOptions,
     ILoggerFactory loggerFactory)
 {
     _xmlOptions    = xmlOptions?.Value ?? throw new ArgumentNullException(nameof(xmlOptions));
     _loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
 }
示例#2
0
        public void GetProvider_ReturnsNull_IfTypeDoesNotMatch()
        {
            // Arrange
            var xmlOptions      = new MvcXmlOptions();
            var providerFactory = new ProblemDetailsWrapperProviderFactory(xmlOptions);
            var context         = new WrapperProviderContext(typeof(SerializableError), isSerialization: true);

            // Act
            var provider = providerFactory.GetProvider(context);

            // Assert
            Assert.Null(provider);
        }
示例#3
0
        public void GetProvider_ReturnsNull_ForCustomProblemDetails()
        {
            // Arrange
            var xmlOptions      = new MvcXmlOptions();
            var providerFactory = new ProblemDetailsWrapperProviderFactory(xmlOptions);
            var instance        = new CustomProblemDetails();
            var context         = new WrapperProviderContext(instance.GetType(), isSerialization: true);

            // Act
            var provider = providerFactory.GetProvider(context);

            // Assert
            Assert.Null(provider);
        }
示例#4
0
        public void GetProvider_Returns21CompatibleWrapper_ForValidationProblemDetails()
        {
            // Arrange
            var xmlOptions      = new MvcXmlOptions();
            var providerFactory = new ProblemDetailsWrapperProviderFactory(xmlOptions);
            var instance        = new ValidationProblemDetails();
            var context         = new WrapperProviderContext(instance.GetType(), isSerialization: true);

            // Act
            var provider = providerFactory.GetProvider(context);

            // Assert
            var result = provider.Wrap(instance);

#pragma warning disable CS0618 // Type or member is obsolete
            var wrapper = Assert.IsType <ValidationProblemDetails21Wrapper>(result);
#pragma warning restore CS0618 // Type or member is obsolete
            Assert.Same(instance, wrapper.ProblemDetails);
        }
示例#5
0
        public void GetProvider_ReturnsWrapper_ForValidationProblemDetails()
        {
            // Arrange
            var xmlOptions = new MvcXmlOptions {
                AllowRfc7807CompliantProblemDetailsFormat = true
            };
            var providerFactory = new ProblemDetailsWrapperProviderFactory(xmlOptions);
            var instance        = new ValidationProblemDetails();
            var context         = new WrapperProviderContext(instance.GetType(), isSerialization: true);

            // Act
            var provider = providerFactory.GetProvider(context);

            // Assert
            var result  = provider.Wrap(instance);
            var wrapper = Assert.IsType <ValidationProblemDetailsWrapper>(result);

            Assert.Same(instance, wrapper.ProblemDetails);
        }
示例#6
0
 public ProblemDetailsWrapperProviderFactory(MvcXmlOptions options)
 {
     _options = options;
 }