Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Maya-Painter committed Oct 18, 2023
1 parent 0094685 commit 5ab7959
Show file tree
Hide file tree
Showing 5 changed files with 550 additions and 22 deletions.
1 change: 1 addition & 0 deletions Microsoft.Azure.Cosmos/src/Linq/SQLTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.Azure.Cosmos.Linq
using System.Collections.Generic;
using System.Linq.Expressions;
using Microsoft.Azure.Cosmos.Query.Core;
using Microsoft.Azure.Cosmos.Serializer;
using Microsoft.Azure.Cosmos.SqlObjects;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,236 @@
<Results>
<Result>
<Input>
<Description><![CDATA[Filter w/ constant value, camelcase = True]]></Description>
<Expression><![CDATA[query.Where(doc => (doc.NumericField == 1))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root["numberValueNewtonsoft"] = 1)]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Filter w/ DataObject initializer with constant value, camelcase = True]]></Description>
<Expression><![CDATA[query.Where(doc => (doc == new DataObjectNewtonsoftDataMemberSerializer() {NumericField = 1, StringField = "1"}))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root = {"numberValueNewtonsoft": 1, "stringValueNewtonsoft": "1", "id": null, "pk": null})]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Select w/ DataObject initializer, camelcase = True]]></Description>
<Expression><![CDATA[query.Select(doc => new DataObjectNewtonsoftDataMemberSerializer() {NumericField = 1, StringField = "1"})]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE {"numberValueNewtonsoft": 1, "stringValueNewtonsoft": "1", "id": null, "pk": null}
FROM root]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}"
]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Deeper than top level reference, camelcase = True]]></Description>
<Expression><![CDATA[query.Select(doc => IIF((doc.NumericField > 1), new DataObjectNewtonsoftDataMemberSerializer() {NumericField = 1, StringField = "1"}, new DataObjectNewtonsoftDataMemberSerializer() {NumericField = 1, StringField = "1"}))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE ((root["numberValueNewtonsoft"] > 1) ? {"numberValueNewtonsoft": 1, "stringValueNewtonsoft": "1", "id": null, "pk": null} : {"numberValueNewtonsoft": 1, "stringValueNewtonsoft": "1", "id": null, "pk": null})
FROM root]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}"
]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Filter w/ DataObject initializer with member initialization, camelcase = True]]></Description>
<Expression><![CDATA[query.Where(doc => (doc == new DataObjectNewtonsoftDataMemberSerializer() {NumericField = doc.NumericField, StringField = doc.StringField})).Select(b => "A")]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE "A"
FROM root
WHERE (root = {"numberValueNewtonsoft": root["numberValueNewtonsoft"], "stringValueNewtonsoft": root["stringValueNewtonsoft"]})]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Filter w/ constant value, camelcase = False]]></Description>
<Expression><![CDATA[query.Where(doc => (doc.NumericField == 1))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root["NumberValueNewtonsoft"] = 1)]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Filter w/ DataObject initializer with constant value, camelcase = False]]></Description>
<Expression><![CDATA[query.Where(doc => (doc == new DataObjectNewtonsoftDataMemberSerializer() {NumericField = 1, StringField = "1"}))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE root
FROM root
WHERE (root = {"NumberValueNewtonsoft": 1, "StringValueNewtonsoft": "1", "id": null, "Pk": null})]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Select w/ DataObject initializer, camelcase = False]]></Description>
<Expression><![CDATA[query.Select(doc => new DataObjectNewtonsoftDataMemberSerializer() {NumericField = 1, StringField = "1"})]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE {"NumberValueNewtonsoft": 1, "StringValueNewtonsoft": "1", "id": null, "Pk": null}
FROM root]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}"
]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Deeper than top level reference, camelcase = False]]></Description>
<Expression><![CDATA[query.Select(doc => IIF((doc.NumericField > 1), new DataObjectNewtonsoftDataMemberSerializer() {NumericField = 1, StringField = "1"}, new DataObjectNewtonsoftDataMemberSerializer() {NumericField = 1, StringField = "1"}))]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE ((root["NumberValueNewtonsoft"] > 1) ? {"NumberValueNewtonsoft": 1, "StringValueNewtonsoft": "1", "id": null, "Pk": null} : {"NumberValueNewtonsoft": 1, "StringValueNewtonsoft": "1", "id": null, "Pk": null})
FROM root]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}",
"{NumericField:0,StringField:,id:,Pk:}"
]]]></Results>
</Output>
</Result>
<Result>
<Input>
<Description><![CDATA[Filter w/ DataObject initializer with member initialization, camelcase = False]]></Description>
<Expression><![CDATA[query.Where(doc => (doc == new DataObjectNewtonsoftDataMemberSerializer() {NumericField = doc.NumericField, StringField = doc.StringField})).Select(b => "A")]]></Expression>
</Input>
<Output>
<SqlQuery><![CDATA[
SELECT VALUE "A"
FROM root
WHERE (root = {"NumberValueNewtonsoft": root["NumberValueNewtonsoft"], "StringValueNewtonsoft": root["StringValueNewtonsoft"]})]]></SqlQuery>
<InputData><![CDATA[[
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-True\", \"Pk\": \"Test\"}",
"{\"NumericField\": 0, \"StringField\": \"0\", \"id\": \"0-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 1, \"StringField\": \"1\", \"id\": \"1-False\", \"Pk\": \"Test\"}",
"{\"NumericField\": 2, \"StringField\": \"2\", \"id\": \"2-False\", \"Pk\": \"Test\"}"
]]]></InputData>
<Results><![CDATA[[]]]></Results>
</Output>
</Result>
</Results>
Loading

0 comments on commit 5ab7959

Please sign in to comment.