From 2ab31f491f683083937dd3ba9c9132e547c3b358 Mon Sep 17 00:00:00 2001 From: maliming Date: Mon, 2 Nov 2020 11:38:15 +0800 Subject: [PATCH] Rename AbpSystemTextJsonSupportTypeMatcher to AbpSystemTextJsonUnsupportedTypeMatcher. --- .../Mvc/Json/AbpHybridJsonInputFormatter.cs | 4 +- .../Mvc/Json/AbpHybridJsonOutputFormatter.cs | 4 +- .../AbpSystemTextJsonSerializerProvider.cs | 8 +-- ...bpSystemTextJsonUnsupportedTypeMatcher.cs} | 6 +- ...pSystemTextJsonSupportTypeMatcher_Tests.cs | 66 ------------------- ...temTextJsonUnsupportedTypeMatcher_Tests.cs | 66 +++++++++++++++++++ 6 files changed, 77 insertions(+), 77 deletions(-) rename framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/{AbpSystemTextJsonSupportTypeMatcher.cs => AbpSystemTextJsonUnsupportedTypeMatcher.cs} (57%) delete mode 100644 framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSupportTypeMatcher_Tests.cs create mode 100644 framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonUnsupportedTypeMatcher_Tests.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonInputFormatter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonInputFormatter.cs index 43d59c4e3d..bd2ade69ad 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonInputFormatter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonInputFormatter.cs @@ -25,8 +25,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Json protected virtual TextInputFormatter GetTextInputFormatter(InputFormatterContext context) { - var typesMatcher = context.HttpContext.RequestServices.GetRequiredService(); - if (typesMatcher.Match(context.ModelType)) + var typesMatcher = context.HttpContext.RequestServices.GetRequiredService(); + if (!typesMatcher.Match(context.ModelType)) { return context.HttpContext.RequestServices.GetRequiredService(); } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonOutputFormatter.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonOutputFormatter.cs index 54039abf1a..1507457f08 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonOutputFormatter.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/Json/AbpHybridJsonOutputFormatter.cs @@ -25,8 +25,8 @@ namespace Volo.Abp.AspNetCore.Mvc.Json protected virtual TextOutputFormatter GetTextInputFormatter(OutputFormatterWriteContext context) { - var typesMatcher = context.HttpContext.RequestServices.GetRequiredService(); - if (typesMatcher.Match(context.ObjectType)) + var typesMatcher = context.HttpContext.RequestServices.GetRequiredService(); + if (!typesMatcher.Match(context.ObjectType)) { return context.HttpContext.RequestServices.GetRequiredService(); } diff --git a/framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonSerializerProvider.cs b/framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonSerializerProvider.cs index 1bf5f214d6..570d1c162c 100644 --- a/framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonSerializerProvider.cs +++ b/framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonSerializerProvider.cs @@ -9,19 +9,19 @@ namespace Volo.Abp.Json.SystemTextJson { protected AbpSystemTextJsonSerializerOptions Options { get; } - protected AbpSystemTextJsonSupportTypeMatcher AbpSystemTextJsonSupportTypeMatcher { get; } + protected AbpSystemTextJsonUnsupportedTypeMatcher AbpSystemTextJsonUnsupportedTypeMatcher { get; } public AbpSystemTextJsonSerializerProvider( IOptions 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) diff --git a/framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonSupportTypeMatcher.cs b/framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonUnsupportedTypeMatcher.cs similarity index 57% rename from framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonSupportTypeMatcher.cs rename to framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonUnsupportedTypeMatcher.cs index 6b991f051a..2beea42c68 100644 --- a/framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonSupportTypeMatcher.cs +++ b/framework/src/Volo.Abp.Json/Volo/Abp/Json/SystemTextJson/AbpSystemTextJsonUnsupportedTypeMatcher.cs @@ -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 options) + public AbpSystemTextJsonUnsupportedTypeMatcher(IOptions options) { Options = options.Value; } public virtual bool Match(Type type) { - return !Options.UnsupportedTypes.Contains(type); + return Options.UnsupportedTypes.Contains(type); } } } diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSupportTypeMatcher_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSupportTypeMatcher_Tests.cs deleted file mode 100644 index 929e892af3..0000000000 --- a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonSupportTypeMatcher_Tests.cs +++ /dev/null @@ -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(); - } - - protected override void AfterAddApplication(IServiceCollection services) - { - services.Configure(options => - { - options.UnsupportedTypes.Add(); - options.UnsupportedTypes.Add(); - options.UnsupportedTypes.Add>(); - }); - } - - [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)).ShouldBeFalse(); - _abpSystemTextJsonSupportTypeMatcher.Match(typeof(IDictionary)).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; } - } - } -} diff --git a/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonUnsupportedTypeMatcher_Tests.cs b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonUnsupportedTypeMatcher_Tests.cs new file mode 100644 index 0000000000..cc31ceca34 --- /dev/null +++ b/framework/test/Volo.Abp.Json.Tests/Volo/Abp/Json/AbpSystemTextJsonUnsupportedTypeMatcher_Tests.cs @@ -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(); + } + + protected override void AfterAddApplication(IServiceCollection services) + { + services.Configure(options => + { + options.UnsupportedTypes.Add(); + options.UnsupportedTypes.Add(); + options.UnsupportedTypes.Add>(); + }); + } + + [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)).ShouldBeTrue(); + _abpSystemTextJsonUnsupportedTypeMatcher.Match(typeof(IDictionary)).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; } + } + } +}