Skip to content

Commit

Permalink
refs
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Nov 9, 2024
1 parent b630988 commit 231191e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Argon" Version="0.24.1" />
<PackageVersion Include="Argon.FSharp" Version="0.24.1" />
<PackageVersion Include="Argon" Version="0.24.2" />
<PackageVersion Include="Argon.FSharp" Version="0.24.2" />
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
<PackageVersion Include="DiffEngine" Version="15.5.3" />
<PackageVersion Include="Expecto" Version="10.2.1" />
Expand Down
26 changes: 18 additions & 8 deletions src/Verify/Serialization/CustomContractResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,39 @@ protected override JsonDictionaryContract CreateDictionaryContract(Type objectTy
if (key is string stringKey &&
settings.TryGetScrubOrIgnoreByName(stringKey, out var scrubOrIgnore))
{
return ToInterceptResult(scrubOrIgnore.Value);
return ToInterceptKeyValueResult(scrubOrIgnore.Value);
}
if (value is not null &&
settings.TryGetScrubOrIgnoreByInstance(value, out scrubOrIgnore))
{
return ToInterceptResult(scrubOrIgnore.Value);
return ToInterceptKeyValueResult(scrubOrIgnore.Value);
}
return InterceptResult.Default;
return KeyValueInterceptResult.Default;
};

return contract;
}

static InterceptResult ToInterceptResult(ScrubOrIgnore scrubOrIgnore)
static KeyValueInterceptResult ToInterceptKeyValueResult(ScrubOrIgnore scrubOrIgnore)
{
if (scrubOrIgnore == ScrubOrIgnore.Ignore)
{
return InterceptResult.Ignore;
return KeyValueInterceptResult.Ignore;
}

return InterceptResult.Replace("{Scrubbed}");
return KeyValueInterceptResult.ReplaceValue("{Scrubbed}");
}

static ItemInterceptResult ToInterceptItemResult(ScrubOrIgnore scrubOrIgnore)
{
if (scrubOrIgnore == ScrubOrIgnore.Ignore)
{
return ItemInterceptResult.Ignore;
}

return ItemInterceptResult.Replace("{Scrubbed}");
}

string ResolveDictionaryKey(JsonDictionaryContract contract, string name, object original)
Expand Down Expand Up @@ -213,10 +223,10 @@ protected override JsonArrayContract CreateArrayContract(Type objectType)
if (item is not null &&
settings.TryGetScrubOrIgnoreByInstance(item, out var scrubOrIgnore))
{
return ToInterceptResult(scrubOrIgnore.Value);
return ToInterceptItemResult(scrubOrIgnore.Value);
}
return InterceptResult.Default;
return ItemInterceptResult.Default;
};

if (contract.CollectionItemType != null &&
Expand Down

0 comments on commit 231191e

Please sign in to comment.