|
| 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.Driver.Linq; |
| 18 | +using MongoDB.TestHelpers.XunitExtensions; |
| 19 | +using Xunit; |
| 20 | + |
| 21 | +namespace MongoDB.Driver.Tests.Linq.Linq3Implementation.Jira |
| 22 | +{ |
| 23 | + public class CSharp4723Tests : Linq3IntegrationTest |
| 24 | + { |
| 25 | + [Theory] |
| 26 | + [ParameterAttributeData] |
| 27 | + public void Find_projection_in_findoneandupdate_should_work( |
| 28 | + [Values(LinqProvider.V2, LinqProvider.V3)] LinqProvider linqProvider) |
| 29 | + { |
| 30 | + var collection = GetCollection(linqProvider); |
| 31 | + |
| 32 | + var update = Builders<A>.Update.Set("Value", "updated"); |
| 33 | + var options = new FindOneAndUpdateOptions<A> |
| 34 | + { |
| 35 | + Projection = Builders<A>.Projection.Expression(x => x) |
| 36 | + }; |
| 37 | + |
| 38 | + var result = collection.FindOneAndUpdate<A, A>(x => x.Id == 1, update, options); |
| 39 | + |
| 40 | + result.Id.Should().Be(1); |
| 41 | + result.Value.Should().Be("1"); |
| 42 | + } |
| 43 | + |
| 44 | + [Theory] |
| 45 | + [ParameterAttributeData] |
| 46 | + public void Find_projection_in_findoneandreplace_should_work( |
| 47 | + [Values(LinqProvider.V2, LinqProvider.V3)] LinqProvider linqProvider) |
| 48 | + { |
| 49 | + var collection = GetCollection(linqProvider); |
| 50 | + var options = new FindOneAndReplaceOptions<A, A> |
| 51 | + { |
| 52 | + Projection = Builders<A>.Projection.Expression(x => x) |
| 53 | + }; |
| 54 | + |
| 55 | + var result = collection.FindOneAndReplace<A, A>(x => x.Id == 1, new A { Id = 1, Value = "updated" }, options); |
| 56 | + |
| 57 | + result.Id.Should().Be(1); |
| 58 | + result.Value.Should().Be("1"); |
| 59 | + } |
| 60 | + |
| 61 | + [Theory] |
| 62 | + [ParameterAttributeData] |
| 63 | + public void Find_projection_in_findoneanddelete_should_work( |
| 64 | + [Values(LinqProvider.V2, LinqProvider.V3)] LinqProvider linqProvider) |
| 65 | + { |
| 66 | + var collection = GetCollection(linqProvider); |
| 67 | + |
| 68 | + var options = new FindOneAndDeleteOptions<A> |
| 69 | + { |
| 70 | + Projection = Builders<A>.Projection.Expression(x => x), |
| 71 | + }; |
| 72 | + |
| 73 | + var result = collection.FindOneAndDelete<A, A>(x => x.Id == 1, options); |
| 74 | + |
| 75 | + result.Id.Should().Be(1); |
| 76 | + result.Value.Should().Be("1"); |
| 77 | + } |
| 78 | + |
| 79 | + private IMongoCollection<A> GetCollection(LinqProvider linqProvider) |
| 80 | + { |
| 81 | + var collection = GetCollection<A>("test", linqProvider); |
| 82 | + CreateCollection( |
| 83 | + collection, |
| 84 | + new A { Id = 1, Value = "1"}); |
| 85 | + return collection; |
| 86 | + } |
| 87 | + |
| 88 | + private class A |
| 89 | + { |
| 90 | + public int Id { get; set; } |
| 91 | + |
| 92 | + public string Value { get; set; } |
| 93 | + } |
| 94 | + } |
| 95 | +} |
0 commit comments