|
12 | 12 | // See the License for the specific language governing permissions and |
13 | 13 | // limitations under the License. |
14 | 14 |
|
| 15 | +using System; |
15 | 16 | using System.Linq; |
16 | 17 | using MongoDB.Analyzer.Tests.Common.DataModel; |
| 18 | +using MongoDB.Driver; |
17 | 19 | using MongoDB.Driver.Linq; |
18 | 20 |
|
19 | 21 | namespace MongoDB.Analyzer.Tests.Common.TestCases.Linq |
@@ -101,5 +103,70 @@ public void Query_Syntax() |
101 | 103 | where person.Vehicle.VehicleType.Type == VehicleTypeEnum.Bus || person.Vehicle.VehicleType.Type == VehicleTypeEnum.Motorcylce |
102 | 104 | select person.Vehicle.LicenceNumber; |
103 | 105 | } |
| 106 | + |
| 107 | + |
| 108 | + [MQL("aggregate([{ \"$match\" : { \"MPG\" : { \"$gt\" : 20.0 } } }, { \"$project\" : { \"Item1\" : \"$VehicleMake\", \"Item2\" : \"$Type\", \"_id\" : 0 } }])")] |
| 109 | + public void Enum_in_type_argument_1() |
| 110 | + { |
| 111 | + _ = GetMongoCollection<VehicleType>().AsQueryable() |
| 112 | + .Where(v => v.MPG > 20) |
| 113 | + .Select(v => new Tuple<VehicleMake, VehicleTypeEnum>(v.VehicleMake, v.Type)); |
| 114 | + } |
| 115 | + |
| 116 | + [MQL("aggregate([{ \"$match\" : { \"MPG\" : { \"$gt\" : 20.0 } } }, { \"$project\" : { \"Item1\" : \"$VehicleMake\", \"Item2\" : \"$Type\", \"_id\" : 0 } }])")] |
| 117 | + public void Enum_in_type_argument_query_syntax_1() |
| 118 | + { |
| 119 | + _ = from vehicleType in GetMongoQueryable<VehicleType>() |
| 120 | + where vehicleType.MPG > 20 |
| 121 | + select new Tuple<VehicleMake, VehicleTypeEnum>(vehicleType.VehicleMake, vehicleType.Type); |
| 122 | + } |
| 123 | + |
| 124 | + [MQL("aggregate([{ \"$match\" : { \"MPG\" : { \"$gt\" : 20.0 } } }, { \"$project\" : { \"__fld0\" : [0, 1, 2], \"_id\" : 0 } }])")] |
| 125 | + public void Enum_in_type_argument_2() |
| 126 | + { |
| 127 | + _ = GetMongoCollection<VehicleType>().AsQueryable() |
| 128 | + .Where(v => v.MPG > 20) |
| 129 | + .Select(v => new System.Collections.Generic.List<VehicleTypeEnum> { VehicleTypeEnum.Bus, VehicleTypeEnum.Car, VehicleTypeEnum.Motorcylce }); |
| 130 | + } |
| 131 | + |
| 132 | + [MQL("aggregate([{ \"$match\" : { \"MPG\" : { \"$gt\" : 20.0 } } }, { \"$project\" : { \"__fld0\" : [0, 1, 2], \"_id\" : 0 } }])")] |
| 133 | + public void Enum_in_type_argument_query_syntax_2() |
| 134 | + { |
| 135 | + _ = from vehicleType in GetMongoQueryable<VehicleType>() |
| 136 | + where vehicleType.MPG > 20 |
| 137 | + select new System.Collections.Generic.List<VehicleTypeEnum> { VehicleTypeEnum.Bus, VehicleTypeEnum.Car, VehicleTypeEnum.Motorcylce }; |
| 138 | + } |
| 139 | + |
| 140 | + [MQL("aggregate([{ \"$match\" : { \"SiblingsCount\" : { \"$gt\" : 10 } } }, { \"$project\" : { \"__fld0\" : { \"Bus\" : 0, \"Car\" : 1 }, \"_id\" : 0 } }])")] |
| 141 | + public void Enum_in_type_argument_3() |
| 142 | + { |
| 143 | + _ = GetMongoCollection<Person>().AsQueryable() |
| 144 | + .Where(p => p.SiblingsCount > 10) |
| 145 | + .Select(p => new System.Collections.Generic.Dictionary<string, VehicleTypeEnum> { { "Bus", VehicleTypeEnum.Bus }, { "Car", VehicleTypeEnum.Car } }); |
| 146 | + } |
| 147 | + |
| 148 | + [MQL("aggregate([{ \"$match\" : { \"SiblingsCount\" : { \"$gt\" : 10 } } }, { \"$project\" : { \"__fld0\" : { \"Bus\" : 0, \"Car\" : 1 }, \"_id\" : 0 } }])")] |
| 149 | + public void Enum_in_type_argument_query_syntax_3() |
| 150 | + { |
| 151 | + _ = from person in GetMongoQueryable<Person>() |
| 152 | + where person.SiblingsCount > 10 |
| 153 | + select new System.Collections.Generic.Dictionary<string, VehicleTypeEnum> { { "Bus", VehicleTypeEnum.Bus }, { "Car", VehicleTypeEnum.Car } }; |
| 154 | + } |
| 155 | + |
| 156 | + [MQL("aggregate([{ \"$match\" : { \"MPG\" : { \"$gt\" : 20.0 } } }, { \"$project\" : { \"Item1\" : \"$VehicleMake\", \"Item2\" : { \"Item1\" : \"$Type\", \"Item2\" : \"$Type\" }, \"_id\" : 0 } }])")] |
| 157 | + public void Enum_in_nested_type_argument() |
| 158 | + { |
| 159 | + _ = GetMongoCollection<VehicleType>().AsQueryable() |
| 160 | + .Where(v => v.MPG > 20) |
| 161 | + .Select(v => new Tuple<VehicleMake, Tuple<VehicleTypeEnum, VehicleTypeEnum>>(v.VehicleMake, new Tuple<VehicleTypeEnum, VehicleTypeEnum>(v.Type, v.Type))); |
| 162 | + } |
| 163 | + |
| 164 | + [MQL("aggregate([{ \"$match\" : { \"MPG\" : { \"$gt\" : 20.0 } } }, { \"$project\" : { \"Item1\" : \"$VehicleMake\", \"Item2\" : { \"Item1\" : \"$Type\", \"Item2\" : \"$Type\" }, \"_id\" : 0 } }])")] |
| 165 | + public void Enum_in_nested_type_argument_query_syntax() |
| 166 | + { |
| 167 | + _ = from vehicleType in GetMongoQueryable<VehicleType>() |
| 168 | + where vehicleType.MPG > 20 |
| 169 | + select new Tuple<VehicleMake, Tuple<VehicleTypeEnum, VehicleTypeEnum>>(vehicleType.VehicleMake, new Tuple<VehicleTypeEnum, VehicleTypeEnum>(vehicleType.Type, vehicleType.Type)); |
| 170 | + } |
104 | 171 | } |
105 | 172 | } |
0 commit comments