|
| 1 | +// Copyright 2021-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 | +using System; |
| 16 | +using MongoDB.Analyzer.Tests.Common.DataModel; |
| 17 | +using MongoDB.Driver; |
| 18 | + |
| 19 | +namespace MongoDB.Analyzer.Tests.Common.TestCases.Builders |
| 20 | +{ |
| 21 | + public sealed class BuildersComplexExpressions : TestCasesBase |
| 22 | + { |
| 23 | + [NoDiagnostics] |
| 24 | + public void SortByFluentFunction() |
| 25 | + { |
| 26 | + Func<IFindFluent<User, User>, IOrderedFindFluent<User, User>> fluentFunction = x => x.SortBy(x => x.Age); |
| 27 | + } |
| 28 | + |
| 29 | + [NoDiagnostics] |
| 30 | + public void ThenByFluentFunction() |
| 31 | + { |
| 32 | + Func<IFindFluent<User, User>, IOrderedFindFluent<User, User>> fluentFunction = x => x.SortBy(x => x.Age).ThenBy(x => x.Height); |
| 33 | + } |
| 34 | + |
| 35 | + [NoDiagnostics] |
| 36 | + public void SortByAndThenByFluentFunctions() |
| 37 | + { |
| 38 | + Func<IFindFluent<User, User>, IFindFluent<User, User>> fluentFunction = x => x.Skip(10).Limit(12).SortBy(x => x.Age).ThenBy(x => x.Height); |
| 39 | + } |
| 40 | + |
| 41 | + [BuildersMQL("{ \"Age\" : -1, \"Name\" : 1, \"Address\" : 1 }")] |
| 42 | + public void SortFluentFunction() |
| 43 | + { |
| 44 | + Func<IFindFluent<User, User>, IFindFluent<User, User>> func = x => x.Sort(Builders<User>.Sort.Combine( |
| 45 | + Builders<User>.Sort.Descending(u => u.Age), |
| 46 | + Builders<User>.Sort.Ascending(u => u.Name), |
| 47 | + Builders<User>.Sort.Ascending(u => u.Address))); |
| 48 | + } |
| 49 | + |
| 50 | + [BuildersMQL("{ \"Age\" : 1, \"Address\" : 0, \"Height\" : 1 }")] |
| 51 | + public void ProjectFluentFunction() |
| 52 | + { |
| 53 | + Func<IFindFluent<User, User>, IFindFluent<User, Bson.BsonDocument>> func = x => x.Project(Builders<User>.Projection.Include(u => u.Age).Exclude(u => u.Address).Include(u => u.Height)); |
| 54 | + } |
| 55 | + |
| 56 | + [BuildersMQL("{ \"Age\" : -1, \"Name\" : 1, \"Address\" : 1 }")] |
| 57 | + [BuildersMQL("{ \"Age\" : 1, \"Address\" : 0, \"Height\" : 1 }")] |
| 58 | + public void SortAndProjectFluentFunction() |
| 59 | + { |
| 60 | + Func<IFindFluent<User, User>, IFindFluent<User, Bson.BsonDocument>> func = x => x.Sort(Builders<User>.Sort.Combine( |
| 61 | + Builders<User>.Sort.Descending(u => u.Age), |
| 62 | + Builders<User>.Sort.Ascending(u => u.Name), |
| 63 | + Builders<User>.Sort.Ascending(u => u.Address))) |
| 64 | + .Project(Builders<User>.Projection.Include(u => u.Age) |
| 65 | + .Exclude(u => u.Address).Include(u => u.Height)); |
| 66 | + } |
| 67 | + } |
| 68 | +} |
0 commit comments