|
| 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 FluentAssertions; |
| 17 | +using MongoDB.Bson.Serialization; |
| 18 | +using MongoDB.Driver.Linq; |
| 19 | +using MongoDB.TestHelpers.XunitExtensions; |
| 20 | +using Xunit; |
| 21 | + |
| 22 | +namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira |
| 23 | +{ |
| 24 | + public class CSharp4681Tests : Linq3IntegrationTest |
| 25 | + { |
| 26 | + [Theory] |
| 27 | + [ParameterAttributeData] |
| 28 | + public void Find_projection_render_should_work( |
| 29 | + [Values(LinqProvider.V2, LinqProvider.V3)] LinqProvider linqProvider) |
| 30 | + { |
| 31 | + var collection = GetCollection(linqProvider); |
| 32 | + |
| 33 | + var fluentFind = collection.Find(a => a.Id == "1").Project(a => a.Id); |
| 34 | + |
| 35 | + var documentSerializer = collection.DocumentSerializer; |
| 36 | + var serializerRegistry = BsonSerializer.SerializerRegistry; |
| 37 | + var renderedProjection = fluentFind.Options.Projection.Render(documentSerializer, serializerRegistry, linqProvider); |
| 38 | + |
| 39 | + renderedProjection.Document.Should().Be("{ _id : 1 }"); |
| 40 | + |
| 41 | + var result = fluentFind.Single(); |
| 42 | + result.Should().Be("1"); |
| 43 | + } |
| 44 | + |
| 45 | + private IMongoCollection<A> GetCollection(LinqProvider linqProvider) |
| 46 | + { |
| 47 | + var collection = GetCollection<A>("test", linqProvider); |
| 48 | + CreateCollection( |
| 49 | + collection, |
| 50 | + new A { Id = "1" }, |
| 51 | + new A { Id = "2" }); |
| 52 | + return collection; |
| 53 | + } |
| 54 | + |
| 55 | + private class A |
| 56 | + { |
| 57 | + public string Id { get; set; } |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments