-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
83 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using System.Reflection; | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Serialization; | ||
|
||
namespace Abp.Auditing | ||
{ | ||
/// <summary> | ||
/// Decides which properties of auditing class to be serialized | ||
/// </summary> | ||
public class AuditingContractResolver : CamelCasePropertyNamesContractResolver | ||
{ | ||
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization) | ||
{ | ||
JsonProperty property = base.CreateProperty(member, memberSerialization); | ||
|
||
if (member.IsDefined(typeof(DisableAuditingAttribute)) || member.IsDefined(typeof(JsonIgnoreAttribute))) | ||
{ | ||
property.ShouldSerialize = instance => false; | ||
} | ||
|
||
return property; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using Abp.Auditing; | ||
using Shouldly; | ||
using Xunit; | ||
|
||
namespace Abp.Tests.Auditing | ||
{ | ||
public class AuditingHelper_Tests | ||
{ | ||
[Fact] | ||
public void Ignored_Properties_Should_Not_Be_Serialized() | ||
{ | ||
var json = AuditingHelper.Serialize(new AuditingHelperTestPersonDto | ||
{ | ||
FullName = "John Doe", | ||
Age = 18, | ||
School = new AuditingHelperTestSchoolDto | ||
{ | ||
Name = "Crosswell Secondary", | ||
Address = "Broadway Ave, West Bend" | ||
} | ||
}); | ||
|
||
json.ShouldBe("{\"fullName\":\"John Doe\",\"school\":{\"name\":\"Crosswell Secondary\"}}"); | ||
} | ||
|
||
public class AuditingHelperTestPersonDto | ||
{ | ||
public string FullName { get; set; } | ||
|
||
[DisableAuditing] | ||
public int Age { get; set; } | ||
|
||
public AuditingHelperTestSchoolDto School { get; set; } | ||
} | ||
|
||
public class AuditingHelperTestSchoolDto | ||
{ | ||
public string Name { get; set; } | ||
|
||
[DisableAuditing] | ||
public string Address { get; set; } | ||
} | ||
} | ||
} |