From d8d037ae97501698b0181ff71913535d85c4ab71 Mon Sep 17 00:00:00 2001 From: Emil Weihe Date: Wed, 10 Jan 2024 16:34:08 +0000 Subject: [PATCH] Add test of parameter name --- .../GeneralGeneratorTests.cs | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/NJsonSchema.CodeGeneration.CSharp.Tests/GeneralGeneratorTests.cs b/src/NJsonSchema.CodeGeneration.CSharp.Tests/GeneralGeneratorTests.cs index 5ac78e2ff..19fa4ab06 100644 --- a/src/NJsonSchema.CodeGeneration.CSharp.Tests/GeneralGeneratorTests.cs +++ b/src/NJsonSchema.CodeGeneration.CSharp.Tests/GeneralGeneratorTests.cs @@ -154,6 +154,33 @@ public async Task When_property_name_is_created_by_custom_fun_then_attribute_is_ AssertCompile(output); } + [Fact] + public async Task When_property_name_is_created_by_custom_fun_then_parameter_name_is_correct_for_record() + { + //// Arrange + var schema = NewtonsoftJsonSchemaGenerator.FromType
(); + var schemaData = schema.ToJson(); + var settings = new CSharpGeneratorSettings + { + ClassStyle = CSharpClassStyle.Record, + PropertyNameGenerator = new CustomPropertyNameGenerator(), + }; + var generator = new CSharpGenerator(schema, settings); + + //// Act + var output = generator.GenerateFile("Address"); + + //// Assert + Assert.DoesNotContain(@"public string Street { get; }", output); + Assert.Contains(@"public string MyCustomStreet { get; }", output); + Assert.Contains(@"this.MyCustomStreet = @myCustomStreet;", output); + + Assert.DoesNotContain(@"public Address(string @city, string @street)", output); + Assert.Contains(@"public Address(string @myCustomCity, string @myCustomStreet)", output); + + AssertCompile(output); + } + [Fact] public async Task When_schema_contains_ref_to_definition_that_refs_another_definition_then_result_should_contain_correct_target_ref_type() { @@ -1821,7 +1848,7 @@ public async Task When_class_is_abstract_constructor_is_protected_for_record() var data = schema.ToJson(); var generator = new CSharpGenerator(schema, new CSharpGeneratorSettings { - ClassStyle = CSharpClassStyle.Record + ClassStyle = CSharpClassStyle.Record, }); //// Act