-
-
Notifications
You must be signed in to change notification settings - Fork 511
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add snapshot test for en locale schema (#518)
* Add snapshot test for en locale schema * Enable JObject sorting * Use net472 for Bogus.Tests.csproj set .editorconfig and .gitattributes for Verify update docs on net472 requirement
- Loading branch information
Showing
6 changed files
with
10,596 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
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,78 @@ | ||
#if NET6_0_OR_GREATER | ||
using Argon; | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading.Tasks; | ||
using VerifyTests; | ||
using VerifyXunit; | ||
using Xunit; | ||
using static VerifyXunit.Verifier; | ||
|
||
namespace Bogus.Tests.SchemaTests; | ||
|
||
|
||
public static class ModuleInit | ||
{ | ||
[ModuleInitializer] | ||
public static void Init() | ||
{ | ||
VerifierSettings.SortJsonObjects(); | ||
} | ||
} | ||
|
||
|
||
[UsesVerify] | ||
public class EnLocaleSchemaTests | ||
{ | ||
[Fact] | ||
public Task ensure_wellknown_en_locale_schema() | ||
{ | ||
var localeJson = File.ReadAllText("../../../../Bogus/data/en.locale.json"); | ||
|
||
var enLocale = JToken.Parse(localeJson); | ||
|
||
var settings = new VerifySettings(); | ||
|
||
settings.AddExtraSettings(jss => jss.ContractResolver = new InterceptedContractResolver(jss.ContractResolver)); | ||
|
||
return Verify(enLocale, settings); | ||
} | ||
} | ||
|
||
public class InterceptedContractResolver : IContractResolver | ||
{ | ||
private readonly IContractResolver defaultResolver; | ||
|
||
public InterceptedContractResolver(IContractResolver defaultResolver) | ||
{ | ||
this.defaultResolver = defaultResolver; | ||
} | ||
|
||
public JsonNameTable GetNameTable() | ||
{ | ||
return defaultResolver.GetNameTable(); | ||
} | ||
|
||
public JsonContract ResolveContract(Type type) | ||
{ | ||
var contract = this.defaultResolver.ResolveContract(type); | ||
if( contract is JsonDictionaryContract jdc ) | ||
{ | ||
var defaultIntercept = jdc.InterceptSerializeItem; | ||
jdc.InterceptSerializeItem = (key, val) => { | ||
if( val is JArray arr && arr.Children().OfType<JValue>().Any() ) | ||
{ | ||
var children = arr.Children(); | ||
var first = children.First(); | ||
return InterceptResult.Replace($"[Array {first.Type}; {children.Count()}]"); | ||
} | ||
|
||
return defaultIntercept(key, val); | ||
}; | ||
} | ||
return contract; | ||
} | ||
} | ||
#endif |
Oops, something went wrong.