|
| 1 | +using System.Linq; |
| 2 | +using Xunit; |
| 3 | + |
| 4 | +namespace MongoDB.Driver.Tests.Linq.Linq3ImplementationTests.Jira |
| 5 | +{ |
| 6 | + public class CSharp4316Tests : Linq3IntegrationTest |
| 7 | + { |
| 8 | + [Fact] |
| 9 | + public void Nullable_type_translate_should_work() |
| 10 | + { |
| 11 | + var collection = GetCollection<ModelContainNullableType>(); |
| 12 | + var fluent = collection.Aggregate() |
| 13 | + .Group(x => new { Some = x.Some.Value, x.AnotherKeyGroup, x.Some.HasValue }, x => x.Select(t => t)); |
| 14 | + |
| 15 | + var stages = Translate(collection, fluent); |
| 16 | + var expected = new [] |
| 17 | + { |
| 18 | + "{ $group : {'_id' : { Some : '$Some', AnotherKeyGroup : '$AnotherKeyGroup', HasValue : { $ne : ['$Some', null] }}, __agg0 : { '$push' : '$$ROOT'}}}", |
| 19 | + "{ $project : { '_v' : '$__agg0', _id : 0 } }" |
| 20 | + }; |
| 21 | + |
| 22 | + AssertStages(stages, expected); |
| 23 | + } |
| 24 | + |
| 25 | + [Fact] |
| 26 | + public void Type_contains_property_value_translate_should_work() |
| 27 | + { |
| 28 | + var collection = GetCollection<ModelWithoutNullable>(); |
| 29 | + var fluent = collection.Aggregate() |
| 30 | + .Group(x => new { Key1 = x.Property.Value, Key2 = x.SomeData, Key3 = x.Property.HasValue}, x => x.Select(t => t)); |
| 31 | + |
| 32 | + var stages = Translate(collection, fluent); |
| 33 | + var expected = new [] |
| 34 | + { |
| 35 | + "{ $group : {'_id' : { Key1 : '$Property.Value', Key2 : '$SomeData', Key3 : '$Property.HasValue' }, __agg0 : { '$push' : '$$ROOT'}}}", |
| 36 | + "{ $project : { '_v' : '$__agg0', _id : 0 } }" |
| 37 | + }; |
| 38 | + AssertStages(stages, expected); |
| 39 | + } |
| 40 | + |
| 41 | + public class ModelContainNullableType |
| 42 | + { |
| 43 | + public int? Some { get; set; } |
| 44 | + public float AnotherKeyGroup { get; set; } |
| 45 | + |
| 46 | + } |
| 47 | + |
| 48 | + public class ModelWithoutNullable |
| 49 | + { |
| 50 | + public CustomTypeLikeNullable Property { get; set; } |
| 51 | + public int SomeData { get; set; } |
| 52 | + } |
| 53 | + |
| 54 | + public class CustomTypeLikeNullable |
| 55 | + { |
| 56 | + public string Value { get; set; } |
| 57 | + public bool HasValue { get; set; } |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments