/// <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)); }
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); }
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); }
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); }
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); }
public ProblemDetailsWrapperProviderFactory(MvcXmlOptions options) { _options = options; }