mirror of https://github.com/abpframework/abp.git
5 changed files with 117 additions and 1 deletions
@ -0,0 +1,39 @@ |
|||
using System; |
|||
using System.Text.RegularExpressions; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.AuditLogging; |
|||
|
|||
public class AuditLogEntityTypeFullNameConverter : ITransientDependency |
|||
{ |
|||
public virtual string Convert(string typeFullName) |
|||
{ |
|||
var genericType = Regex.Match(typeFullName, @"(.+?)`1\[\["); |
|||
if (!genericType.Success) |
|||
{ |
|||
return ReplaceGenericSymbol(typeFullName); |
|||
} |
|||
|
|||
var type = Regex.Match(typeFullName, @"`1\[\[(.+?), "); |
|||
if (!type.Success) |
|||
{ |
|||
return typeFullName; |
|||
} |
|||
|
|||
if (type.Groups[1].Value.Contains("System.Nullable`1[[")) |
|||
{ |
|||
return genericType.Groups[1].Value + "<" + type.Groups[1].Value.Replace("System.Nullable`1[[", "") + "?>"; |
|||
} |
|||
|
|||
return genericType.Groups[1].Value.Contains("System.Nullable") |
|||
? type.Groups[1].Value + "?" |
|||
: genericType.Groups[1].Value + "<" + ReplaceGenericSymbol(type.Groups[1].Value) + ">"; |
|||
} |
|||
|
|||
protected virtual string ReplaceGenericSymbol(string typeFullName) |
|||
{ |
|||
return typeFullName.Contains("`1+") |
|||
? typeFullName.Substring(0, typeFullName.IndexOf("[[", StringComparison.Ordinal)).Replace("`1+", ".") |
|||
: typeFullName; |
|||
} |
|||
} |
|||
@ -0,0 +1,6 @@ |
|||
namespace Volo.Abp.AuditLogging.EntityFrameworkCore; |
|||
|
|||
public class AuditLogEntityTypeFullNameConverter_Tests : AuditLogEntityTypeFullNameConverter_Tests<AbpAuditLoggingEntityFrameworkCoreTestModule> |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.AuditLogging.MongoDB; |
|||
|
|||
[Collection(MongoTestCollection.Name)] |
|||
public class AuditLogEntityTypeFullNameConverter_Tests : AuditLogEntityTypeFullNameConverter_Tests<AbpAuditLoggingMongoDbTestModule> |
|||
{ |
|||
|
|||
} |
|||
@ -0,0 +1,46 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Collections.ObjectModel; |
|||
using Shouldly; |
|||
using Volo.Abp.Modularity; |
|||
using Xunit; |
|||
|
|||
namespace Volo.Abp.AuditLogging; |
|||
|
|||
public abstract class AuditLogEntityTypeFullNameConverter_Tests<TStartupModule> : AuditLoggingTestBase<TStartupModule> |
|||
where TStartupModule : IAbpModule |
|||
{ |
|||
private readonly AuditLogEntityTypeFullNameConverter _typeFullNameConverter; |
|||
|
|||
protected AuditLogEntityTypeFullNameConverter_Tests() |
|||
{ |
|||
_typeFullNameConverter = GetRequiredService<AuditLogEntityTypeFullNameConverter>(); |
|||
} |
|||
|
|||
[Fact] |
|||
public void AuditLogEntityTypeFullNameConverter_Test() |
|||
{ |
|||
_typeFullNameConverter.Convert("MyType").ShouldBe("MyType"); |
|||
|
|||
_typeFullNameConverter.Convert(typeof(string).FullName!).ShouldBe("System.String"); |
|||
_typeFullNameConverter.Convert(typeof(Guid).FullName!).ShouldBe("System.Guid"); |
|||
_typeFullNameConverter.Convert(typeof(Guid?).FullName!).ShouldBe("System.Guid?"); |
|||
_typeFullNameConverter.Convert(typeof(int).FullName!).ShouldBe("System.Int32"); |
|||
_typeFullNameConverter.Convert(typeof(long?).FullName!).ShouldBe("System.Int64?"); |
|||
_typeFullNameConverter.Convert(typeof(MyClass).FullName!).ShouldBe("Volo.Abp.AuditLogging.AuditLogEntityTypeFullNameConverter_Tests.MyClass"); |
|||
|
|||
_typeFullNameConverter.Convert(typeof(ICollection<string>).FullName!).ShouldBe($"System.Collections.Generic.ICollection<System.String>"); |
|||
_typeFullNameConverter.Convert(typeof(Collection<int>).FullName!).ShouldBe($"System.Collections.ObjectModel.Collection<System.Int32>"); |
|||
_typeFullNameConverter.Convert(typeof(List<Guid>).FullName!).ShouldBe($"System.Collections.Generic.List<System.Guid>"); |
|||
_typeFullNameConverter.Convert(typeof(List<MyClass>).FullName!).ShouldBe($"System.Collections.Generic.List<Volo.Abp.AuditLogging.AuditLogEntityTypeFullNameConverter_Tests.MyClass>"); |
|||
|
|||
_typeFullNameConverter.Convert(typeof(ICollection<long?>).FullName!).ShouldBe($"System.Collections.Generic.ICollection<System.Int64?>"); |
|||
_typeFullNameConverter.Convert(typeof(Collection<int?>).FullName!).ShouldBe($"System.Collections.ObjectModel.Collection<System.Int32?>"); |
|||
_typeFullNameConverter.Convert(typeof(List<Guid?>).FullName!).ShouldBe($"System.Collections.Generic.List<System.Guid?>"); |
|||
} |
|||
|
|||
public class MyClass |
|||
{ |
|||
|
|||
} |
|||
} |
|||
Loading…
Reference in new issue