Skip to content

Allow null values in constant collections #1375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 @@ -54,7 +54,7 @@ public CollectionConstantNode(IEnumerable<object> objectCollection, string liter

foreach (object item in objectCollection)
{
this.collection.Add(new ConstantNode(item, item.ToString(), this.itemType));
this.collection.Add(new ConstantNode(item, item != null ? item.ToString() : "null", this.itemType));
Copy link
Member

Choose a reason for hiding this comment

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

May we replace the hard code "null" as other code?

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ public void StringCollectionThroughLiteralTokenIsSetCorrectly()
collectionConstantNode.Collection.ShouldBeEquivalentTo(expectedList);
}

[Fact]
public void NullableCollectionTypeSetsConstantNodeCorrectly()
{
const string text = "('abc','def', null)";
var expectedType = new EdmCollectionTypeReference(new EdmCollectionType(EdmCoreModel.Instance.GetString(true)));
object collection = ODataUriConversionUtils.ConvertFromCollectionValue("['abc','def', null]", HardCodedTestModel.TestModel, expectedType);
LiteralToken literalToken = new LiteralToken(collection, text, expectedType);

CollectionConstantNode collectionConstantNode = new CollectionConstantNode(
(literalToken.Value as ODataCollectionValue)?.Items, text, expectedType);

var expectedList = new ConstantNode[] {
new ConstantNode("abc", "abc", EdmCoreModel.Instance.GetString(true)),
new ConstantNode("def", "def", EdmCoreModel.Instance.GetString(true)),
new ConstantNode(null, "null", EdmCoreModel.Instance.GetString(true)),
};

collectionConstantNode.Collection.ShouldBeEquivalentTo(expectedList);
}

[Fact]
public void TextIsSetCorrectly()
{
Expand Down