Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<Address>();
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()
{
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
{%- else %}
[Newtonsoft.Json.JsonConstructor]
{%- endif %}
{% if IsAbstract %}protected{% else %}public{% endif %} {{ClassName}}({% for property in sortedProperties %}{%- if skipComma %}{%- assign skipComma = false %}{% else %}, {% endif %}{{ property.Type }} @{{ property.Name | lowercamelcase }}{% endfor %})
{% if IsAbstract %}protected{% else %}public{% endif %} {{ClassName}}({% for property in sortedProperties %}{%- if skipComma %}{%- assign skipComma = false %}{% else %}, {% endif %}{{ property.Type }} @{{ property.PropertyName | lowercamelcase }}{% endfor %})
{%- assign skipComma = true %}
{%- if HasInheritance %}
: base({%- for property in sortedParentProperties %}{%- if skipComma %}{%- assign skipComma = false %}{% else %}, {% endif %}{{ property.Name | lowercamelcase }}{%- endfor %})
: base({%- for property in sortedParentProperties %}{%- if skipComma %}{%- assign skipComma = false %}{% else %}, {% endif %}{{ property.PropertyName | lowercamelcase }}{%- endfor %})
{%- endif %}
{
{%- for property in Properties %}
this.{{property.PropertyName}} = @{{property.Name | lowercamelcase}};
this.{{property.PropertyName}} = @{{property.PropertyName | lowercamelcase}};
{%- endfor %}
}