From 8eb8e02ba4137db9a5846655472c6e0b257dae4b Mon Sep 17 00:00:00 2001 From: Pure Krome Date: Tue, 22 Sep 2020 12:16:23 +1000 Subject: [PATCH] :wrench: Enum values were not getting camelcased. (#33) --- .../Extensions/IMvcBuilderExtensions.cs | 2 +- .../JsonOptionsTests/AddJsonOptionsTests.cs | 2 +- tests/Homely.AspNetCore.Mvc.Helpers.Tests/TestHelpers.cs | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Homely.AspNetCore.Mvc.Helpers/Extensions/IMvcBuilderExtensions.cs b/src/Homely.AspNetCore.Mvc.Helpers/Extensions/IMvcBuilderExtensions.cs index 7a1f5ea..9964f10 100644 --- a/src/Homely.AspNetCore.Mvc.Helpers/Extensions/IMvcBuilderExtensions.cs +++ b/src/Homely.AspNetCore.Mvc.Helpers/Extensions/IMvcBuilderExtensions.cs @@ -59,7 +59,7 @@ public static IMvcBuilder AddDefaultJsonOptions(this IMvcBuilder builder, options.JsonSerializerOptions.IgnoreNullValues = true; options.JsonSerializerOptions.WriteIndented = isIndented; options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; - options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); + options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)); // If we have specified a custom date-time format, then use the specific custom converter. if (!string.IsNullOrWhiteSpace(dateTimeFormat)) diff --git a/tests/Homely.AspNetCore.Mvc.Helpers.Tests/JsonOptionsTests/AddJsonOptionsTests.cs b/tests/Homely.AspNetCore.Mvc.Helpers.Tests/JsonOptionsTests/AddJsonOptionsTests.cs index 651c8d3..0d4da08 100644 --- a/tests/Homely.AspNetCore.Mvc.Helpers.Tests/JsonOptionsTests/AddJsonOptionsTests.cs +++ b/tests/Homely.AspNetCore.Mvc.Helpers.Tests/JsonOptionsTests/AddJsonOptionsTests.cs @@ -51,7 +51,7 @@ public async Task GivenSomeModel_Get_ReturnsASyntaxCorrectJsonText(int id, var responseBody = await response.Content.ReadAsStringAsync(); responseBody.ShouldContain("id", Case.Sensitive); // Camel case check. responseBody.ShouldNotContain("vin", Case.Insensitive); // IgnoreNullValues check. - responseBody.ShouldContain("Grey", Case.Sensitive); // Enum converter check. + responseBody.ShouldContain("grey", Case.Sensitive); // Enum converter check. responseBody.ShouldContain(expectedDateTime); var startingJson = isIdented diff --git a/tests/Homely.AspNetCore.Mvc.Helpers.Tests/TestHelpers.cs b/tests/Homely.AspNetCore.Mvc.Helpers.Tests/TestHelpers.cs index 06d5eb7..c930c0e 100644 --- a/tests/Homely.AspNetCore.Mvc.Helpers.Tests/TestHelpers.cs +++ b/tests/Homely.AspNetCore.Mvc.Helpers.Tests/TestHelpers.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc; using Shouldly; using System; using System.Net.Http; @@ -19,7 +19,7 @@ public static class TestHelpers PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; - options.Converters.Add(new JsonStringEnumConverter()); + options.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase)); return options; });