Utilities to help unit tests validate JSON attribute usage and other small testing concerns.
Versioning
- As of version 8.x the package major version follows the .NET target version (e.g.
8.x.xtargetsnet8.0).
Supported target framework
net8.0
Intended use
- Project supplies lightweight test helpers (designed to be referenced from unit test projects) that integrate with NUnit's
TestCaseDatato produce parameterized tests.
Namespaces and important types
TipsTrade.ApiClient.Testing
JsonAttributeAssert— static test helper focused on JSON attribute consistency across serializers:- Test-case generation:
GetTestCases(this Assembly assembly, Func<Type, bool>? typePredicate = null, Func<PropertyInfo, bool>? propertyPredicate = null)— enumerate properties from an assembly that have JSON attributes and returnIEnumerable<TestCaseData<PropertyInfo>>.GetTestCases<T>(Func<PropertyInfo, bool>? predicate = null)— properties for a specific type.GetTestCases(this Type type, Func<PropertyInfo, bool>? predicate = null)— properties for a givenType.GetTestCases(this IEnumerable<PropertyInfo> properties)— buildTestCaseDatafor an enumerable of properties.
- Assertions:
IsConsistent(PropertyInfo property)— asserts both ignore and name attributes are consistent.IsNameConsistent(PropertyInfo property)— assertsNewtonsoft.Json.JsonPropertyandSystem.Text.Json.Serialization.JsonPropertyName(if present) have the same name.IsIgnoreConsistent(PropertyInfo property)— assertsJsonIgnoreattributes are present/absent consistently between Newtonsoft and System.Text.Json.
- Test-case generation:
Behavior details
- The helper looks for both
Newtonsoft.JsonandSystem.Text.Jsonattributes and yields NUnitTestCaseDatanamed using the declaring type and property name. - Designed to be used from NUnit tests via
TestCaseSourceor by iterating the test cases returned from an assembly/type.
Notes
- This README was updated to reflect the actual public surface found in source (
JsonAttributeAssert) and the project's target framework (net8.0). - For examples, see the repository's
Testsproject which consumes these helpers to validate JSON attribute consistency across models.