|
| 1 | +/* Copyright 2010-present MongoDB Inc. |
| 2 | +* |
| 3 | +* Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +* you may not use this file except in compliance with the License. |
| 5 | +* You may obtain a copy of the License at |
| 6 | +* |
| 7 | +* http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +* |
| 9 | +* Unless required by applicable law or agreed to in writing, software |
| 10 | +* distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +* See the License for the specific language governing permissions and |
| 13 | +* limitations under the License. |
| 14 | +*/ |
| 15 | + |
| 16 | +using System.Linq; |
| 17 | +using FluentAssertions; |
| 18 | +using MongoDB.Bson.Serialization.Attributes; |
| 19 | +using Xunit; |
| 20 | + |
| 21 | +namespace MongoDB.Driver.Tests.Linq.Linq3ImplementationTests.Jira |
| 22 | +{ |
| 23 | + public class CSharp4049Tests : Linq3IntegrationTest |
| 24 | + { |
| 25 | + [Fact] |
| 26 | + public void Aggregate_Project_should_translate_as_expected() |
| 27 | + { |
| 28 | + var collection = CreateCollection(); |
| 29 | + var aggregate = collection.Aggregate() |
| 30 | + .Project(x => new TestClass { Property = x.Property.ToUpper() }); |
| 31 | + |
| 32 | + var stages = Translate(collection, aggregate); |
| 33 | + AssertStages(stages, "{ $project : { _p : { $toUpper : '$_p' }, _id : 0 } }"); |
| 34 | + |
| 35 | + var results = aggregate.ToList().Single(); |
| 36 | + results.Property.Should().Be("ABC"); |
| 37 | + } |
| 38 | + |
| 39 | + [Fact] |
| 40 | + public void Queryable_Select_should_translate_as_expected() |
| 41 | + { |
| 42 | + var collection = CreateCollection(); |
| 43 | + var queryable = collection.AsQueryable() |
| 44 | + .Select(x => new TestClass { Property = x.Property.ToUpper() }); |
| 45 | + |
| 46 | + var stages = Translate(collection, queryable); |
| 47 | + AssertStages(stages, "{ $project : { _p : { $toUpper : '$_p' }, _id : 0 } }"); |
| 48 | + |
| 49 | + var results = queryable.ToList().Single(); |
| 50 | + results.Property.Should().Be("ABC"); |
| 51 | + } |
| 52 | + |
| 53 | + private IMongoCollection<TestClass> CreateCollection() |
| 54 | + { |
| 55 | + var collection = GetCollection<TestClass>(); |
| 56 | + |
| 57 | + var documents = new[] |
| 58 | + { |
| 59 | + new TestClass { Property = "abc" } |
| 60 | + }; |
| 61 | + CreateCollection(collection, documents); |
| 62 | + |
| 63 | + return collection; |
| 64 | + } |
| 65 | + |
| 66 | + public class TestClass |
| 67 | + { |
| 68 | + [BsonElement("_p")] |
| 69 | + public string Property { get; set; } |
| 70 | + } |
| 71 | + } |
| 72 | +} |
0 commit comments