Rename AbpSystemTextJsonSupportTypeMatcher to AbpSystemTextJsonUnsupportedTypeMatcher.

pull/5952/head
maliming 5 years ago
parent 5650f6461d
commit 2ab31f491f

@ -25,8 +25,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Json
protected virtual TextInputFormatter GetTextInputFormatter(InputFormatterContext context)
{
var typesMatcher = context.HttpContext.RequestServices.GetRequiredService<AbpSystemTextJsonSupportTypeMatcher>();
if (typesMatcher.Match(context.ModelType))
var typesMatcher = context.HttpContext.RequestServices.GetRequiredService<AbpSystemTextJsonUnsupportedTypeMatcher>();
if (!typesMatcher.Match(context.ModelType))
{
return context.HttpContext.RequestServices.GetRequiredService<SystemTextJsonInputFormatter>();
}

@ -25,8 +25,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Json
protected virtual TextOutputFormatter GetTextInputFormatter(OutputFormatterWriteContext context)
{
var typesMatcher = context.HttpContext.RequestServices.GetRequiredService<AbpSystemTextJsonSupportTypeMatcher>();
if (typesMatcher.Match(context.ObjectType))
var typesMatcher = context.HttpContext.RequestServices.GetRequiredService<AbpSystemTextJsonUnsupportedTypeMatcher>();
if (!typesMatcher.Match(context.ObjectType))
{
return context.HttpContext.RequestServices.GetRequiredService<SystemTextJsonOutputFormatter>();
}

@ -9,19 +9,19 @@ namespace Volo.Abp.Json.SystemTextJson
{
protected AbpSystemTextJsonSerializerOptions Options { get; }
protected AbpSystemTextJsonSupportTypeMatcher AbpSystemTextJsonSupportTypeMatcher { get; }
protected AbpSystemTextJsonUnsupportedTypeMatcher AbpSystemTextJsonUnsupportedTypeMatcher { get; }
public AbpSystemTextJsonSerializerProvider(
IOptions<AbpSystemTextJsonSerializerOptions> options,
AbpSystemTextJsonSupportTypeMatcher abpSystemTextJsonSupportTypeMatcher)
AbpSystemTextJsonUnsupportedTypeMatcher abpSystemTextJsonUnsupportedTypeMatcher)
{
AbpSystemTextJsonSupportTypeMatcher = abpSystemTextJsonSupportTypeMatcher;
AbpSystemTextJsonUnsupportedTypeMatcher = abpSystemTextJsonUnsupportedTypeMatcher;
Options = options.Value;
}
public bool CanHandle(Type type)
{
return AbpSystemTextJsonSupportTypeMatcher.Match(type);
return !AbpSystemTextJsonUnsupportedTypeMatcher.Match(type);
}
public string Serialize(object obj, bool camelCase = true, bool indented = false)

@ -4,18 +4,18 @@ using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Json.SystemTextJson
{
public class AbpSystemTextJsonSupportTypeMatcher : ITransientDependency
public class AbpSystemTextJsonUnsupportedTypeMatcher : ITransientDependency
{
protected AbpSystemTextJsonSerializerOptions Options { get; }
public AbpSystemTextJsonSupportTypeMatcher(IOptions<AbpSystemTextJsonSerializerOptions> options)
public AbpSystemTextJsonUnsupportedTypeMatcher(IOptions<AbpSystemTextJsonSerializerOptions> options)
{
Options = options.Value;
}
public virtual bool Match(Type type)
{
return !Options.UnsupportedTypes.Contains(type);
return Options.UnsupportedTypes.Contains(type);
}
}
}

@ -1,66 +0,0 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Json.SystemTextJson;
using Xunit;
namespace Volo.Abp.Json
{
public class AbpSystemTextJsonSupportTypeMatcher_Tests : AbpJsonTestBase
{
private readonly AbpSystemTextJsonSupportTypeMatcher _abpSystemTextJsonSupportTypeMatcher;
public AbpSystemTextJsonSupportTypeMatcher_Tests()
{
_abpSystemTextJsonSupportTypeMatcher = GetRequiredService<AbpSystemTextJsonSupportTypeMatcher>();
}
protected override void AfterAddApplication(IServiceCollection services)
{
services.Configure<AbpSystemTextJsonSerializerOptions>(options =>
{
options.UnsupportedTypes.Add<MyClass>();
options.UnsupportedTypes.Add<byte[]>();
options.UnsupportedTypes.Add<Dictionary<string, MyClass4>>();
});
}
[Fact]
public void CanHandle_Test()
{
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(MyClass)).ShouldBeFalse();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(byte[])).ShouldBeFalse();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(MyClass2)).ShouldBeTrue();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(MyClass3)).ShouldBeTrue();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(MyClass4)).ShouldBeTrue();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(string)).ShouldBeTrue();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(string[])).ShouldBeTrue();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(Dictionary<string, MyClass4>)).ShouldBeFalse();
_abpSystemTextJsonSupportTypeMatcher.Match(typeof(IDictionary<string, MyClass4>)).ShouldBeTrue();
}
class MyClass
{
public DateTime Prop1 { get; set; }
}
class MyClass2
{
public DateTime Prop1 { get; set; }
}
class MyClass3
{
public MyClass4 Prop1 { get; set; }
}
class MyClass4
{
public DateTime Prop1 { get; set; }
}
}
}

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;
using Volo.Abp.Json.SystemTextJson;
using Xunit;
namespace Volo.Abp.Json
{
public class AbpSystemTextJsonUnsupportedTypeMatcher_Tests : AbpJsonTestBase
{
private readonly AbpSystemTextJsonUnsupportedTypeMatcher _abpSystemTextJsonUnsupportedTypeMatcher;
public AbpSystemTextJsonUnsupportedTypeMatcher_Tests()
{
_abpSystemTextJsonUnsupportedTypeMatcher = GetRequiredService<AbpSystemTextJsonUnsupportedTypeMatcher>();
}
protected override void AfterAddApplication(IServiceCollection services)
{
services.Configure<AbpSystemTextJsonSerializerOptions>(options =>
{
options.UnsupportedTypes.Add<MyClass>();
options.UnsupportedTypes.Add<byte[]>();
options.UnsupportedTypes.Add<Dictionary<string, MyClass4>>();
});
}
[Fact]
public void Match_Test()
{
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(MyClass)).ShouldBeTrue();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(byte[])).ShouldBeTrue();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(MyClass2)).ShouldBeFalse();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(MyClass3)).ShouldBeFalse();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(MyClass4)).ShouldBeFalse();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(string)).ShouldBeFalse();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(string[])).ShouldBeFalse();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(Dictionary<string, MyClass4>)).ShouldBeTrue();
_abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(IDictionary<string, MyClass4>)).ShouldBeFalse();
}
class MyClass
{
public DateTime Prop1 { get; set; }
}
class MyClass2
{
public DateTime Prop1 { get; set; }
}
class MyClass3
{
public MyClass4 Prop1 { get; set; }
}
class MyClass4
{
public DateTime Prop1 { get; set; }
}
}
}
Loading…
Cancel
Save