static WebApi() { // Create the snake case naming policy. var snakeCaseNamingPolicy = new SnakeCaseJsonNamingPolicy(true); // Set the options. JsonSerializerOptions = new JsonSerializerOptions { PropertyNamingPolicy = snakeCaseNamingPolicy, Converters = { new JsonStringEnumConverter(snakeCaseNamingPolicy, false), new PolymorphicReadOnlyCollectionJsonConverter <Block>() }, IgnoreNullValues = true }; }
public void Test_Convert(string test, string expected, bool lowercaseParts) { // Validate parameters. if (string.IsNullOrWhiteSpace(test)) { throw new ArgumentNullException(nameof(test)); } if (string.IsNullOrWhiteSpace(expected)) { throw new ArgumentNullException(nameof(expected)); } // Create the policy. var policy = new SnakeCaseJsonNamingPolicy(lowercaseParts); // Convert. string actual = policy .ConvertName(test); // They are equal. Assert.Equal(expected, actual); }