JamesNK / Newtonsoft.Json.Schema

Json.NET Schema is a powerful, complete and easy to use JSON Schema framework for .NET
http://www.newtonsoft.com/jsonschema
Other
248 stars 107 forks source link

Testability of inheritors of JSchemaGenerationProvider #246

Open Ozzah opened 3 years ago

Ozzah commented 3 years ago

I've created a bunch of classes that extend JSchemaGenerationProvider, overriding the bool CanGenerateSchema(JSchemaTypeGenerationContext) and JSchema GetSchem(JSchemaTypeGenerationContext) methods.

I'd like to at least unit test these, but the constructor for JSchemaTypeGenerationContext is internal, so my hands are tied. I can probably get around it by writing wrappers around everything, but it would be cumbersome.

I'm not sure what the best solution would be - probably to make JSchemaTypeGenerationContext implement some interface so it can easily be mocked for testing?

JamesNK commented 3 years ago

The problem here is the constructor takes an internal type. Making it public isn't possible.

Perhaps a special ctor just for testing could be introduced that skips the internal type argument.