Skip to content
Open
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 @@ -52,7 +52,7 @@ public async Task When_property_is_required_and_abstract_then_it_is_not_instanti

/// Assert
Assert.Contains("foo: AbstractClass", code);
Assert.Contains("this.foo = _data[\"Foo\"] ? AbstractClass.fromJS(_data[\"Foo\"]) : <any>undefined;", code);
Assert.Contains("this.foo = _data[\"Foo\"] ? AbstractClass.fromJS(_data[\"Foo\"]) : _data[\"Foo\"];", code);
}

[KnownType(typeof(SuperClass))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public void When_object_property_is_required_or_not_then_the_code_has_correct_in
Assert.Contains("this.a = _data[\"A\"] ? A.fromJS(_data[\"A\"]) : new A();", code);

Assert.Contains("b: B;", code);
Assert.Contains("this.b = _data[\"B\"] ? B.fromJS(_data[\"B\"]) : <any>undefined;", code);
Assert.Contains("this.b = _data[\"B\"] ? B.fromJS(_data[\"B\"]) : _data[\"B\"];", code);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public async Task When_date_handling_is_moment_then_moment_property_is_generated

//// Assert
Assert.Contains("myDate: moment.Moment", code);
Assert.Contains("this.myDate = _data[\"myDate\"] ? moment(_data[\"myDate\"].toString()) : <any>undefined;", code);
Assert.Contains("data[\"myDate\"] = this.myDate ? this.myDate.format('YYYY-MM-DD') : <any>undefined;", code);
Assert.Contains("this.myDate = _data[\"myDate\"] ? moment(_data[\"myDate\"].toString()) : _data[\"myDate\"];", code);
Assert.Contains("data[\"myDate\"] = this.myDate ? this.myDate.format('YYYY-MM-DD') : this.myDate;", code);
}

[Fact]
Expand All @@ -72,8 +72,8 @@ public async Task When_date_handling_is_moment_then_duration_property_is_generat

//// Assert
Assert.Contains("myTimeSpan: moment.Duration", code);
Assert.Contains("this.myTimeSpan = _data[\"myTimeSpan\"] ? moment.duration(_data[\"myTimeSpan\"].toString()) : <any>undefined;", code);
Assert.Contains("data[\"myTimeSpan\"] = this.myTimeSpan ? this.myTimeSpan.format('d.hh:mm:ss.SS', { trim: false }) : <any>undefined;", code);
Assert.Contains("this.myTimeSpan = _data[\"myTimeSpan\"] ? moment.duration(_data[\"myTimeSpan\"].toString()) : _data[\"myTimeSpan\"];", code);
Assert.Contains("data[\"myTimeSpan\"] = this.myTimeSpan ? this.myTimeSpan.format('d.hh:mm:ss.SS', { trim: false }) : this.myTimeSpan;", code);
}

[Fact]
Expand All @@ -92,8 +92,8 @@ public async Task When_date_handling_is_date_then_date_property_is_generated_in_

//// Assert
Assert.Contains("myDate: Date", code);
Assert.Contains("this.myDate = _data[\"myDate\"] ? new Date(_data[\"myDate\"].toString()) : <any>undefined;", code);
Assert.Contains("data[\"myDate\"] = this.myDate ? formatDate(this.myDate) : <any>undefined;", code);
Assert.Contains("this.myDate = _data[\"myDate\"] ? new Date(_data[\"myDate\"].toString()) : _data[\"myDate\"];", code);
Assert.Contains("data[\"myDate\"] = this.myDate ? formatDate(this.myDate) : this.myDate;", code);
Assert.Contains("function formatDate(", code);
}

Expand All @@ -113,8 +113,8 @@ public async Task When_date_handling_is_offset_moment_then_date_property_is_gene

//// Assert
Assert.Contains("myDate: moment.Moment", code);
Assert.Contains("this.myDate = _data[\"myDate\"] ? moment.parseZone(_data[\"myDate\"].toString()) : <any>undefined;", code);
Assert.Contains("data[\"myDate\"] = this.myDate ? this.myDate.format('YYYY-MM-DD') : <any>undefined;", code);
Assert.Contains("this.myDate = _data[\"myDate\"] ? moment.parseZone(_data[\"myDate\"].toString()) : _data[\"myDate\"];", code);
Assert.Contains("data[\"myDate\"] = this.myDate ? this.myDate.format('YYYY-MM-DD') : this.myDate;", code);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public async Task When_date_handling_is_moment_then_moment_property_are_generate

//// Assert
Assert.Contains("myDateTime: moment.Moment", code);
Assert.Contains("this.myDateTime = _data[\"MyDateTime\"] ? moment(_data[\"MyDateTime\"].toString()) : <any>undefined;", code);
Assert.Contains("data[\"MyDateTime\"] = this.myDateTime ? this.myDateTime.toISOString() : <any>undefined;", code);
Assert.Contains("this.myDateTime = _data[\"MyDateTime\"] ? moment(_data[\"MyDateTime\"].toString()) : _data[\"MyDateTime\"];", code);
Assert.Contains("data[\"MyDateTime\"] = this.myDateTime ? this.myDateTime.toISOString() : this.myDateTime;", code);
}

[Fact]
Expand All @@ -68,8 +68,8 @@ public async Task When_date_handling_is_offset_moment_then_moment_property_are_g

//// Assert
Assert.Contains("myDateTime: moment.Moment", code);
Assert.Contains("this.myDateTime = _data[\"MyDateTime\"] ? moment.parseZone(_data[\"MyDateTime\"].toString()) : <any>undefined;", code);
Assert.Contains("data[\"MyDateTime\"] = this.myDateTime ? this.myDateTime.toISOString(true) : <any>undefined;", code);
Assert.Contains("this.myDateTime = _data[\"MyDateTime\"] ? moment.parseZone(_data[\"MyDateTime\"].toString()) : _data[\"MyDateTime\"];", code);
Assert.Contains("data[\"MyDateTime\"] = this.myDateTime ? this.myDateTime.toISOString(true) : this.myDateTime;", code);
}

[Fact]
Expand All @@ -88,8 +88,8 @@ public async Task When_date_handling_is_date_then_date_property_are_generated_in

//// Assert
Assert.Contains("myDateTime: Date", code);
Assert.Contains("this.myDateTime = _data[\"MyDateTime\"] ? new Date(_data[\"MyDateTime\"].toString()) : <any>undefined;", code);
Assert.Contains("data[\"MyDateTime\"] = this.myDateTime ? this.myDateTime.toISOString() : <any>undefined;", code);
Assert.Contains("this.myDateTime = _data[\"MyDateTime\"] ? new Date(_data[\"MyDateTime\"].toString()) : _data[\"MyDateTime\"];", code);
Assert.Contains("data[\"MyDateTime\"] = this.myDateTime ? this.myDateTime.toISOString() : this.myDateTime;", code);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,8 @@ public async Task When_property_uses_custom_dictionary_class_then_class_is_gener
Assert.DoesNotContain("this.foo = {};", code);
Assert.DoesNotContain("data[\"Foo\"] = {};", code);

Assert.Contains(@"this.foo = _data[""Foo""] ? DisplayValueDictionary.fromJS(_data[""Foo""]) : <any>undefined;", code);
Assert.Contains(@"data[""Foo""] = this.foo ? this.foo.toJSON() : <any>undefined;", code);
Assert.Contains(@"this.foo = _data[""Foo""] ? DisplayValueDictionary.fromJS(_data[""Foo""]) : _data[""Foo""];", code);
Assert.Contains(@"data[""Foo""] = this.foo ? this.foo.toJSON() : this.foo;", code);

Assert.Contains("foo: DisplayValueDictionary", code);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% if IsNewableObject -%}
{% if CheckNewableObject -%}
{{ Variable }} = {{ Value }} ? {{ Type }}.fromJS({{ Value }}{% if HandleReferences -%}, _mappings{% endif %}) : {% if HasDefaultValue %}{{ DefaultValue }}{% else %}<any>{{ NullValue }}{% endif %};
{{ Variable }} = {{ Value }} ? {{ Type }}.fromJS({{ Value }}{% if HandleReferences -%}, _mappings{% endif %}) : {% if HasDefaultValue %}{{ DefaultValue }}{% else %}{{ Value }}{% endif %};
{% else -%}
{{ Variable }} = {{ Type }}.fromJS({{ Value }}{% if HandleReferences -%}, _mappings{% endif %});
{% endif -%}
Expand All @@ -24,14 +24,14 @@ if ({{ Value }}) {
for (let key in {{ Value }}) {
if ({{ Value }}.hasOwnProperty(key))
{% if IsDictionaryValueNewableObject -%}
{{ Variable }}{% if RequiresStrictPropertyInitialization %}!{% endif %}[key] = {{ Value }}[key] ? {{ DictionaryValueType }}.fromJS({{ Value }}[key]{% if HandleReferences %}, _mappings{% endif %}) : {% if HasDictionaryValueDefaultValue %}{{ DictionaryValueDefaultValue }}{% else %}<any>{{ NullValue }}{% endif %};
{{ Variable }}{% if RequiresStrictPropertyInitialization %}!{% endif %}[key] = {{ Value }}[key] ? {{ DictionaryValueType }}.fromJS({{ Value }}[key]{% if HandleReferences %}, _mappings{% endif %}) : {% if HasDictionaryValueDefaultValue %}{{ DictionaryValueDefaultValue }}{% else %}{{ Value }}[key]{% endif %};
{% elseif IsDictionaryValueNewableArray -%}
{{ Variable }}{% if RequiresStrictPropertyInitialization %}!{% endif %}[key] = {{ Value }}[key] ? {{ Value }}[key].map((i: any) => {{ DictionaryValueArrayItemType }}.fromJS(i{% if HandleReferences %}, _mappings{% endif %})) : {% if HasDictionaryValueDefaultValue %}{{ DictionaryValueDefaultValue }}{% else %}<any>{{ NullValue }}{% endif %};
{{ Variable }}{% if RequiresStrictPropertyInitialization %}!{% endif %}[key] = {{ Value }}[key] ? {{ Value }}[key].map((i: any) => {{ DictionaryValueArrayItemType }}.fromJS(i{% if HandleReferences %}, _mappings{% endif %})) : {% if HasDictionaryValueDefaultValue %}{{ DictionaryValueDefaultValue }}{% else %}{{ Value }}[key]{% endif %};
{% elseif IsDictionaryValueDate or IsDictionaryValueDateTime -%}
{{ Variable }}{% if RequiresStrictPropertyInitialization %}!{% endif %}[key] = {{ Value }}[key] ? {{ StringToDateCode }}({{ Value }}[key].toString()) : {% if HasDictionaryValueDefaultValue %}{{ DictionaryValueDefaultValue }}{% else %}<any>{{ NullValue }}{% endif %};
{{ Variable }}{% if RequiresStrictPropertyInitialization %}!{% endif %}[key] = {{ Value }}[key] ? {{ StringToDateCode }}({{ Value }}[key].toString()) : {% if HasDictionaryValueDefaultValue %}{{ DictionaryValueDefaultValue }}{% else %}{{ Value }}[key]{% endif %};
{% else -%}
{% if(HasDictionaryValueDefaultValue || NullValue != "undefined"){ -%}
{{ Variable }}{% if RequiresStrictPropertyInitialization %}!{% endif %}[key] = {{ Value }}[key] !== undefined ? {{ Value }}[key] : {% if HasDictionaryValueDefaultValue %}{{ DictionaryValueDefaultValue }}{% else %}<any>{{ NullValue }}{% endif %};
{{ Variable }}{% if RequiresStrictPropertyInitialization %}!{% endif %}[key] = {{ Value }}[key] !== undefined ? {{ Value }}[key] : {% if HasDictionaryValueDefaultValue %}{{ DictionaryValueDefaultValue }}{% else %}{{ Value }}[key]{% endif %};
{% else -%}
{{ Variable }}{% if RequiresStrictPropertyInitialization %}!{% endif %}[key] = {{ Value }}[key];
{% endif -%}
Expand All @@ -40,10 +40,10 @@ if ({{ Value }}) {
}
{% else -%}
{% if IsDate or IsDateTime -%}
{{ Variable }} = {{ Value }} ? {{ StringToDateCode }}({{ Value }}.toString()) : {% if HasDefaultValue %}{{ StringToDateCode }}({{ DefaultValue }}){% else %}<any>{{ NullValue }}{% endif %};
{{ Variable }} = {{ Value }} ? {{ StringToDateCode }}({{ Value }}.toString()) : {% if HasDefaultValue %}{{ StringToDateCode }}({{ DefaultValue }}){% else %}{{ Value }}{% endif %};
{% else -%}
{% if HasDefaultValue or NullValue != "undefined" -%}
{{ Variable }} = {{ Value }} !== undefined ? {{ Value }} : {% if HasDefaultValue %}{{ DefaultValue }}{% else %}<any>{{ NullValue }}{% endif %};
{% if HasDefaultValue -%}
{{ Variable }} = {{ Value }} !== undefined ? {{ Value }} : {{ DefaultValue }};
{% else -%}
{{ Variable }} = {{ Value }};
{% endif -%}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% if IsNewableObject -%}
{{ Variable }} = {{ Value }} ? {{ Value }}.toJSON() : <any>{{ NullValue }};
{{ Variable }} = {{ Value }} ? {{ Value }}.toJSON() : {{ Value }};
{% elseif IsArray -%}
if (Array.isArray({{ Value }})) {
{{ Variable }} = [];
Expand All @@ -20,26 +20,20 @@ if ({{ Value }}) {
for (let key in {{ Value }}) {
if ({{ Value }}.hasOwnProperty(key))
{% if IsDictionaryValueNewableObject -%}
{{ Variable }}[key] = {{ Value }}[key] ? {{ Value }}[key].toJSON() : <any>{{ NullValue }};
{{ Variable }}[key] = {{ Value }}[key] ? {{ Value }}[key].toJSON() : {{ Variable }}[key];
{% elseif IsDictionaryValueDate -%}
{{ Variable }}[key] = {{ Value }}[key] ? {% if UseJsDate %}formatDate({{ Value }}[key]){% else %}{{ Value }}[key].format('YYYY-MM-DD'){% endif %} : <any>{{ NullValue }};
{{ Variable }}[key] = {{ Value }}[key] ? {% if UseJsDate %}formatDate({{ Value }}[key]){% else %}{{ Value }}[key].format('YYYY-MM-DD'){% endif %} : {{ Variable }}[key];
{% elseif IsDictionaryValueDateTime -%}
{{ Variable }}[key] = {{ Value }}[key] ? {{ Value }}[key].{{ DateTimeToStringCode }} : <any>{{ NullValue }};
{{ Variable }}[key] = {{ Value }}[key] ? {{ Value }}[key].{{ DateTimeToStringCode }} : {{ Variable }}[key];
{% else -%}
{% if NullValue != "undefined" -%}
{{ Variable }}[key] = {{ Value }}[key] !== undefined ? {{ Value }}[key] : <any>{{ NullValue }};
{% else -%}
{{ Variable }}[key] = {{ Value }}[key];
{% endif -%}
{% endif -%}
}
}
{% elseif IsDate -%}
{{ Variable }} = {{ Value }} ? {% if UseJsDate %}formatDate({{ Value }}){% else %}{{ Value }}.format('YYYY-MM-DD'){% endif %} : {% if HasDefaultValue -%}{{ DefaultValue }}{% else %}<any>{{ NullValue }}{% endif %};
{{ Variable }} = {{ Value }} ? {% if UseJsDate %}formatDate({{ Value }}){% else %}{{ Value }}.format('YYYY-MM-DD'){% endif %} : {% if HasDefaultValue -%}{{ DefaultValue }}{% else %}{{ Value }}{% endif %};
{% elseif IsDateTime -%}
{{ Variable }} = {{ Value }} ? {{ Value }}.{{ DateTimeToStringCode }} : {% if HasDefaultValue %}{{ DefaultValue }}{% else %}<any>{{ NullValue }}{% endif %};
{% elseif NullValue != "undefined" -%}
{{ Variable }} = {{ Value }} !== undefined ? {{ Value }} : <any>{{ NullValue }};
{{ Variable }} = {{ Value }} ? {{ Value }}.{{ DateTimeToStringCode }} : {% if HasDefaultValue %}{{ DefaultValue }}{% else %}{{ Value }}{% endif %};
{% else -%}
{{ Variable }} = {{ Value }};
{% endif -%}