Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
- [Dotnet] Fixed code generation for types that accept List<T> as parameters. Constructors were not properly handling null input. [clrudolphi]
Copy link
Contributor

@mpkorstanje mpkorstanje Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spotted this after merging. Changes should be listed as one of Added, Changed, ect. I'll fix it on main.


## [26.0.0] - 2024-08-15
### Added
Expand Down
8 changes: 6 additions & 2 deletions codegen/templates/dotnet.dotnet.erb
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,14 @@ public sealed class <%= class_name(key) %>
required = (schema['required'] || []).index(property_name)
-%>
<% if required -%>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<% if required -%>
<%- if required -%>

RequireNonNull<<%= type_for(class_name(key), property_name, property) -%>>(<%= property_name %>, "<%= capitalize(property_name) %>", "<%= class_name(key) %>.<%= capitalize(property_name) %> cannot be null");
RequireNonNull<<%= type_for(class_name(key), property_name, property) -%>>(<%= property_name %>, "<%= capitalize(property_name) %>", "<%= class_name(key) %>.<%= capitalize(property_name) %> cannot be null");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
RequireNonNull<<%= type_for(class_name(key), property_name, property) -%>>(<%= property_name %>, "<%= capitalize(property_name) %>", "<%= class_name(key) %>.<%= capitalize(property_name) %> cannot be null");
RequireNonNull<<%= type_for(class_name(key), property_name, property) -%>>(<%= property_name %>, "<%= capitalize(property_name) %>", "<%= class_name(key) %>.<%= capitalize(property_name) %> cannot be null");

<%- end -%>
<%- if property['items'] -%>
this.<%= capitalize(property_name) %> = new <%= type_for(class_name(key), property_name, property) -%>(<%= property_name %>);
<%- if required -%>
this.<%= capitalize(property_name) %> = new <%= type_for(class_name(key), property_name, property) -%>(<%= property_name %>);
<%- else -%>
this.<%= capitalize(property_name) %> = <%= property_name %> == null ? new <%= type_for(class_name(key), property_name, property) -%>() : new <%= type_for(class_name(key), property_name, property) -%>(<%= property_name %>);
<%- end -%>
<%- else -%>
this.<%= capitalize(property_name) %> = <%= property_name %>;
<%- end -%>
Expand Down
Binary file not shown.
10 changes: 10 additions & 0 deletions dotnet/Cucumber.Messages.Specs/BasicMessageSerializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,15 @@ public void SerializesAnEnvelopeToNDJSONCorrectly()
Assert.Equal(expectedStepDefinition, reconstructedStepDefinition);
}

[Fact]
public void ProperlyDeserializesCollectionProperties() {

// The following is from the CCK hooks sample
var json = @"{""id"":""33"",""pickleId"":""20"",""testSteps"":[{""hookId"":""0"",""id"":""29""},{""hookId"":""1"",""id"":""30""},{""id"":""31"",""pickleStepId"":""19"",""stepDefinitionIds"":[""2""],""stepMatchArgumentsLists"":[{""stepMatchArguments"":[]}]},{""hookId"":""4"",""id"":""32""}]}";

// This test will pass if the deserializer does not throw an exception
var testCase = NdjsonSerializer.Deserialize<TestCase>(json);
Assert.Equal(4, testCase.TestSteps.Count);
}
}
}
6 changes: 3 additions & 3 deletions dotnet/Cucumber.Messages/generated/Attachment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ public Attachment(
string url
)
{
RequireNonNull<string>(body, "Body", "Attachment.Body cannot be null");
RequireNonNull<string>(body, "Body", "Attachment.Body cannot be null");
this.Body = body;
RequireNonNull<AttachmentContentEncoding>(contentEncoding, "ContentEncoding", "Attachment.ContentEncoding cannot be null");
RequireNonNull<AttachmentContentEncoding>(contentEncoding, "ContentEncoding", "Attachment.ContentEncoding cannot be null");
this.ContentEncoding = contentEncoding;
this.FileName = fileName;
RequireNonNull<string>(mediaType, "MediaType", "Attachment.MediaType cannot be null");
RequireNonNull<string>(mediaType, "MediaType", "Attachment.MediaType cannot be null");
this.MediaType = mediaType;
this.Source = source;
this.TestCaseStartedId = testCaseStartedId;
Expand Down
14 changes: 7 additions & 7 deletions dotnet/Cucumber.Messages/generated/Background.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ public Background(
string id
)
{
RequireNonNull<Location>(location, "Location", "Background.Location cannot be null");
RequireNonNull<Location>(location, "Location", "Background.Location cannot be null");
this.Location = location;
RequireNonNull<string>(keyword, "Keyword", "Background.Keyword cannot be null");
RequireNonNull<string>(keyword, "Keyword", "Background.Keyword cannot be null");
this.Keyword = keyword;
RequireNonNull<string>(name, "Name", "Background.Name cannot be null");
RequireNonNull<string>(name, "Name", "Background.Name cannot be null");
this.Name = name;
RequireNonNull<string>(description, "Description", "Background.Description cannot be null");
RequireNonNull<string>(description, "Description", "Background.Description cannot be null");
this.Description = description;
RequireNonNull<List<Step>>(steps, "Steps", "Background.Steps cannot be null");
this.Steps = new List<Step>(steps);
RequireNonNull<string>(id, "Id", "Background.Id cannot be null");
RequireNonNull<List<Step>>(steps, "Steps", "Background.Steps cannot be null");
this.Steps = new List<Step>(steps);
RequireNonNull<string>(id, "Id", "Background.Id cannot be null");
this.Id = id;
}

Expand Down
2 changes: 1 addition & 1 deletion dotnet/Cucumber.Messages/generated/Ci.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public Ci(
Git git
)
{
RequireNonNull<string>(name, "Name", "Ci.Name cannot be null");
RequireNonNull<string>(name, "Name", "Ci.Name cannot be null");
this.Name = name;
this.Url = url;
this.BuildNumber = buildNumber;
Expand Down
4 changes: 2 additions & 2 deletions dotnet/Cucumber.Messages/generated/Comment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public Comment(
string text
)
{
RequireNonNull<Location>(location, "Location", "Comment.Location cannot be null");
RequireNonNull<Location>(location, "Location", "Comment.Location cannot be null");
this.Location = location;
RequireNonNull<string>(text, "Text", "Comment.Text cannot be null");
RequireNonNull<string>(text, "Text", "Comment.Text cannot be null");
this.Text = text;
}

Expand Down
6 changes: 3 additions & 3 deletions dotnet/Cucumber.Messages/generated/DataTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ public DataTable(
List<TableRow> rows
)
{
RequireNonNull<Location>(location, "Location", "DataTable.Location cannot be null");
RequireNonNull<Location>(location, "Location", "DataTable.Location cannot be null");
this.Location = location;
RequireNonNull<List<TableRow>>(rows, "Rows", "DataTable.Rows cannot be null");
this.Rows = new List<TableRow>(rows);
RequireNonNull<List<TableRow>>(rows, "Rows", "DataTable.Rows cannot be null");
this.Rows = new List<TableRow>(rows);
}

public override bool Equals(Object o)
Expand Down
6 changes: 3 additions & 3 deletions dotnet/Cucumber.Messages/generated/DocString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ public DocString(
string delimiter
)
{
RequireNonNull<Location>(location, "Location", "DocString.Location cannot be null");
RequireNonNull<Location>(location, "Location", "DocString.Location cannot be null");
this.Location = location;
this.MediaType = mediaType;
RequireNonNull<string>(content, "Content", "DocString.Content cannot be null");
RequireNonNull<string>(content, "Content", "DocString.Content cannot be null");
this.Content = content;
RequireNonNull<string>(delimiter, "Delimiter", "DocString.Delimiter cannot be null");
RequireNonNull<string>(delimiter, "Delimiter", "DocString.Delimiter cannot be null");
this.Delimiter = delimiter;
}

Expand Down
4 changes: 2 additions & 2 deletions dotnet/Cucumber.Messages/generated/Duration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ public Duration(
long nanos
)
{
RequireNonNull<long>(seconds, "Seconds", "Duration.Seconds cannot be null");
RequireNonNull<long>(seconds, "Seconds", "Duration.Seconds cannot be null");
this.Seconds = seconds;
RequireNonNull<long>(nanos, "Nanos", "Duration.Nanos cannot be null");
RequireNonNull<long>(nanos, "Nanos", "Duration.Nanos cannot be null");
this.Nanos = nanos;
}

Expand Down
18 changes: 9 additions & 9 deletions dotnet/Cucumber.Messages/generated/Examples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,20 @@ public Examples(
string id
)
{
RequireNonNull<Location>(location, "Location", "Examples.Location cannot be null");
RequireNonNull<Location>(location, "Location", "Examples.Location cannot be null");
this.Location = location;
RequireNonNull<List<Tag>>(tags, "Tags", "Examples.Tags cannot be null");
this.Tags = new List<Tag>(tags);
RequireNonNull<string>(keyword, "Keyword", "Examples.Keyword cannot be null");
RequireNonNull<List<Tag>>(tags, "Tags", "Examples.Tags cannot be null");
this.Tags = new List<Tag>(tags);
RequireNonNull<string>(keyword, "Keyword", "Examples.Keyword cannot be null");
this.Keyword = keyword;
RequireNonNull<string>(name, "Name", "Examples.Name cannot be null");
RequireNonNull<string>(name, "Name", "Examples.Name cannot be null");
this.Name = name;
RequireNonNull<string>(description, "Description", "Examples.Description cannot be null");
RequireNonNull<string>(description, "Description", "Examples.Description cannot be null");
this.Description = description;
this.TableHeader = tableHeader;
RequireNonNull<List<TableRow>>(tableBody, "TableBody", "Examples.TableBody cannot be null");
this.TableBody = new List<TableRow>(tableBody);
RequireNonNull<string>(id, "Id", "Examples.Id cannot be null");
RequireNonNull<List<TableRow>>(tableBody, "TableBody", "Examples.TableBody cannot be null");
this.TableBody = new List<TableRow>(tableBody);
RequireNonNull<string>(id, "Id", "Examples.Id cannot be null");
this.Id = id;
}

Expand Down
2 changes: 1 addition & 1 deletion dotnet/Cucumber.Messages/generated/Exception.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public Exception(
string stackTrace
)
{
RequireNonNull<string>(type, "Type", "Exception.Type cannot be null");
RequireNonNull<string>(type, "Type", "Exception.Type cannot be null");
this.Type = type;
this.Message = message;
this.StackTrace = stackTrace;
Expand Down
18 changes: 9 additions & 9 deletions dotnet/Cucumber.Messages/generated/Feature.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,20 +56,20 @@ public Feature(
List<FeatureChild> children
)
{
RequireNonNull<Location>(location, "Location", "Feature.Location cannot be null");
RequireNonNull<Location>(location, "Location", "Feature.Location cannot be null");
this.Location = location;
RequireNonNull<List<Tag>>(tags, "Tags", "Feature.Tags cannot be null");
this.Tags = new List<Tag>(tags);
RequireNonNull<string>(language, "Language", "Feature.Language cannot be null");
RequireNonNull<List<Tag>>(tags, "Tags", "Feature.Tags cannot be null");
this.Tags = new List<Tag>(tags);
RequireNonNull<string>(language, "Language", "Feature.Language cannot be null");
this.Language = language;
RequireNonNull<string>(keyword, "Keyword", "Feature.Keyword cannot be null");
RequireNonNull<string>(keyword, "Keyword", "Feature.Keyword cannot be null");
this.Keyword = keyword;
RequireNonNull<string>(name, "Name", "Feature.Name cannot be null");
RequireNonNull<string>(name, "Name", "Feature.Name cannot be null");
this.Name = name;
RequireNonNull<string>(description, "Description", "Feature.Description cannot be null");
RequireNonNull<string>(description, "Description", "Feature.Description cannot be null");
this.Description = description;
RequireNonNull<List<FeatureChild>>(children, "Children", "Feature.Children cannot be null");
this.Children = new List<FeatureChild>(children);
RequireNonNull<List<FeatureChild>>(children, "Children", "Feature.Children cannot be null");
this.Children = new List<FeatureChild>(children);
}

public override bool Equals(Object o)
Expand Down
4 changes: 2 additions & 2 deletions dotnet/Cucumber.Messages/generated/GherkinDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ List<Comment> comments
{
this.Uri = uri;
this.Feature = feature;
RequireNonNull<List<Comment>>(comments, "Comments", "GherkinDocument.Comments cannot be null");
this.Comments = new List<Comment>(comments);
RequireNonNull<List<Comment>>(comments, "Comments", "GherkinDocument.Comments cannot be null");
this.Comments = new List<Comment>(comments);
}

public override bool Equals(Object o)
Expand Down
4 changes: 2 additions & 2 deletions dotnet/Cucumber.Messages/generated/Git.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ public Git(
string tag
)
{
RequireNonNull<string>(remote, "Remote", "Git.Remote cannot be null");
RequireNonNull<string>(remote, "Remote", "Git.Remote cannot be null");
this.Remote = remote;
RequireNonNull<string>(revision, "Revision", "Git.Revision cannot be null");
RequireNonNull<string>(revision, "Revision", "Git.Revision cannot be null");
this.Revision = revision;
this.Branch = branch;
this.Tag = tag;
Expand Down
4 changes: 2 additions & 2 deletions dotnet/Cucumber.Messages/generated/Group.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public Group(
string value
)
{
RequireNonNull<List<Group>>(children, "Children", "Group.Children cannot be null");
this.Children = new List<Group>(children);
RequireNonNull<List<Group>>(children, "Children", "Group.Children cannot be null");
this.Children = new List<Group>(children);
this.Start = start;
this.Value = value;
}
Expand Down
4 changes: 2 additions & 2 deletions dotnet/Cucumber.Messages/generated/Hook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ public Hook(
string tagExpression
)
{
RequireNonNull<string>(id, "Id", "Hook.Id cannot be null");
RequireNonNull<string>(id, "Id", "Hook.Id cannot be null");
this.Id = id;
this.Name = name;
RequireNonNull<SourceReference>(sourceReference, "SourceReference", "Hook.SourceReference cannot be null");
RequireNonNull<SourceReference>(sourceReference, "SourceReference", "Hook.SourceReference cannot be null");
this.SourceReference = sourceReference;
this.TagExpression = tagExpression;
}
Expand Down
8 changes: 4 additions & 4 deletions dotnet/Cucumber.Messages/generated/JavaMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public JavaMethod(
List<string> methodParameterTypes
)
{
RequireNonNull<string>(className, "ClassName", "JavaMethod.ClassName cannot be null");
RequireNonNull<string>(className, "ClassName", "JavaMethod.ClassName cannot be null");
this.ClassName = className;
RequireNonNull<string>(methodName, "MethodName", "JavaMethod.MethodName cannot be null");
RequireNonNull<string>(methodName, "MethodName", "JavaMethod.MethodName cannot be null");
this.MethodName = methodName;
RequireNonNull<List<string>>(methodParameterTypes, "MethodParameterTypes", "JavaMethod.MethodParameterTypes cannot be null");
this.MethodParameterTypes = new List<string>(methodParameterTypes);
RequireNonNull<List<string>>(methodParameterTypes, "MethodParameterTypes", "JavaMethod.MethodParameterTypes cannot be null");
this.MethodParameterTypes = new List<string>(methodParameterTypes);
}

public override bool Equals(Object o)
Expand Down
6 changes: 3 additions & 3 deletions dotnet/Cucumber.Messages/generated/JavaStackTraceElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ public JavaStackTraceElement(
string methodName
)
{
RequireNonNull<string>(className, "ClassName", "JavaStackTraceElement.ClassName cannot be null");
RequireNonNull<string>(className, "ClassName", "JavaStackTraceElement.ClassName cannot be null");
this.ClassName = className;
RequireNonNull<string>(fileName, "FileName", "JavaStackTraceElement.FileName cannot be null");
RequireNonNull<string>(fileName, "FileName", "JavaStackTraceElement.FileName cannot be null");
this.FileName = fileName;
RequireNonNull<string>(methodName, "MethodName", "JavaStackTraceElement.MethodName cannot be null");
RequireNonNull<string>(methodName, "MethodName", "JavaStackTraceElement.MethodName cannot be null");
this.MethodName = methodName;
}

Expand Down
2 changes: 1 addition & 1 deletion dotnet/Cucumber.Messages/generated/Location.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public Location(
Nullable<long> column
)
{
RequireNonNull<long>(line, "Line", "Location.Line cannot be null");
RequireNonNull<long>(line, "Line", "Location.Line cannot be null");
this.Line = line;
this.Column = column;
}
Expand Down
10 changes: 5 additions & 5 deletions dotnet/Cucumber.Messages/generated/Meta.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ public Meta(
Ci ci
)
{
RequireNonNull<string>(protocolVersion, "ProtocolVersion", "Meta.ProtocolVersion cannot be null");
RequireNonNull<string>(protocolVersion, "ProtocolVersion", "Meta.ProtocolVersion cannot be null");
this.ProtocolVersion = protocolVersion;
RequireNonNull<Product>(implementation, "Implementation", "Meta.Implementation cannot be null");
RequireNonNull<Product>(implementation, "Implementation", "Meta.Implementation cannot be null");
this.Implementation = implementation;
RequireNonNull<Product>(runtime, "Runtime", "Meta.Runtime cannot be null");
RequireNonNull<Product>(runtime, "Runtime", "Meta.Runtime cannot be null");
this.Runtime = runtime;
RequireNonNull<Product>(os, "Os", "Meta.Os cannot be null");
RequireNonNull<Product>(os, "Os", "Meta.Os cannot be null");
this.Os = os;
RequireNonNull<Product>(cpu, "Cpu", "Meta.Cpu cannot be null");
RequireNonNull<Product>(cpu, "Cpu", "Meta.Cpu cannot be null");
this.Cpu = cpu;
this.Ci = ci;
}
Expand Down
12 changes: 6 additions & 6 deletions dotnet/Cucumber.Messages/generated/ParameterType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ public ParameterType(
SourceReference sourceReference
)
{
RequireNonNull<string>(name, "Name", "ParameterType.Name cannot be null");
RequireNonNull<string>(name, "Name", "ParameterType.Name cannot be null");
this.Name = name;
RequireNonNull<List<string>>(regularExpressions, "RegularExpressions", "ParameterType.RegularExpressions cannot be null");
this.RegularExpressions = new List<string>(regularExpressions);
RequireNonNull<bool>(preferForRegularExpressionMatch, "PreferForRegularExpressionMatch", "ParameterType.PreferForRegularExpressionMatch cannot be null");
RequireNonNull<List<string>>(regularExpressions, "RegularExpressions", "ParameterType.RegularExpressions cannot be null");
this.RegularExpressions = new List<string>(regularExpressions);
RequireNonNull<bool>(preferForRegularExpressionMatch, "PreferForRegularExpressionMatch", "ParameterType.PreferForRegularExpressionMatch cannot be null");
this.PreferForRegularExpressionMatch = preferForRegularExpressionMatch;
RequireNonNull<bool>(useForSnippets, "UseForSnippets", "ParameterType.UseForSnippets cannot be null");
RequireNonNull<bool>(useForSnippets, "UseForSnippets", "ParameterType.UseForSnippets cannot be null");
this.UseForSnippets = useForSnippets;
RequireNonNull<string>(id, "Id", "ParameterType.Id cannot be null");
RequireNonNull<string>(id, "Id", "ParameterType.Id cannot be null");
this.Id = id;
this.SourceReference = sourceReference;
}
Expand Down
4 changes: 2 additions & 2 deletions dotnet/Cucumber.Messages/generated/ParseError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public ParseError(
string message
)
{
RequireNonNull<SourceReference>(source, "Source", "ParseError.Source cannot be null");
RequireNonNull<SourceReference>(source, "Source", "ParseError.Source cannot be null");
this.Source = source;
RequireNonNull<string>(message, "Message", "ParseError.Message cannot be null");
RequireNonNull<string>(message, "Message", "ParseError.Message cannot be null");
this.Message = message;
}

Expand Down
Loading