|
| 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.Linq; |
| 16 | +using MongoDB.Driver.Linq; |
| 17 | + |
| 18 | +namespace MongoDB.Analyzer.Tests.Common.TestCases.Linq |
| 19 | +{ |
| 20 | + public sealed class LinqDefaultVersionInference : TestCasesBase |
| 21 | + { |
| 22 | + // DriverVersion = (,2.14.0-beta1] |
| 23 | + // DefaultLinqProvider = V2 |
| 24 | + [InvalidLinq("{document}{Name}.Trim() is not supported.", DriverVersions.Linq2AndLower, LinqVersion.V2)] |
| 25 | + // DefaultLinqProvider = V3 |
| 26 | + [InvalidLinq("{document}{Name}.Trim() is not supported.", DriverVersions.Linq2AndLower, LinqVersion.V3)] |
| 27 | + // DefaultLinqProvider = Undefined |
| 28 | + [InvalidLinq("{document}{Name}.Trim() is not supported.", DriverVersions.Linq2AndLower, LinqVersion.Undefined)] |
| 29 | + public void Expression_should_not_be_supported_in_LINQ2_only() |
| 30 | + { |
| 31 | + _ = GetMongoQueryable() |
| 32 | + .Where(u => u.Name.Trim() == "123"); |
| 33 | + } |
| 34 | + |
| 35 | + // DriverVersion = [2.14.0-beta1, 2.19.0) |
| 36 | + // DefaultLinqProvider = V2 |
| 37 | + [NotSupportedLinq2("Supported in LINQ3 only: db.coll.Aggregate([{ \"$match\" : { \"Name\" : /^\\s*(?!\\s)123(?<!\\s)\\s*$/s } }])", version: DriverVersions.Linq3NonDefault, linqVersion:LinqVersion.V2)] |
| 38 | + // DefaultLinqProvider = V3 |
| 39 | + [MQL("db.coll.Aggregate([{ \"$match\" : { \"Name\" : /^\\s*(?!\\s)123(?<!\\s)\\s*$/s } }])", DriverVersions.Linq3NonDefault, LinqVersion.V3)] |
| 40 | + // DefaultLinqProvider = Undefined |
| 41 | + [NotSupportedLinq2("Supported in LINQ3 only: db.coll.Aggregate([{ \"$match\" : { \"Name\" : /^\\s*(?!\\s)123(?<!\\s)\\s*$/s } }])", version: DriverVersions.Linq3NonDefault, linqVersion: LinqVersion.Undefined)] |
| 42 | + public void Expression_should_be_supported_in_non_default_LINQ3() |
| 43 | + { |
| 44 | + _ = GetMongoQueryable() |
| 45 | + .Where(u => u.Name.Trim() == "123"); |
| 46 | + } |
| 47 | + |
| 48 | + // DriverVersion = [2.19.0,) |
| 49 | + // DefaultLinqProvider = V2 |
| 50 | + [NotSupportedLinq2("Supported in LINQ3 only: db.coll.Aggregate([{ \"$match\" : { \"Name\" : /^\\s*(?!\\s)123(?<!\\s)\\s*$/s } }])", version: DriverVersions.Linq3DefaultAndHigher)] |
| 51 | + // DefaultLinqProvider = V3 |
| 52 | + [MQL("db.coll.Aggregate([{ \"$match\" : { \"Name\" : /^\\s*(?!\\s)123(?<!\\s)\\s*$/s } }])", DriverVersions.Linq3DefaultAndHigher, LinqVersion.V3)] |
| 53 | + // DefaultLinqProvider = Undefined |
| 54 | + [MQL("db.coll.Aggregate([{ \"$match\" : { \"Name\" : /^\\s*(?!\\s)123(?<!\\s)\\s*$/s } }])", DriverVersions.Linq3DefaultAndHigher, LinqVersion.Undefined)] |
| 55 | + public void Expression_should_be_supported_in_default_LINQ3() |
| 56 | + { |
| 57 | + _ = GetMongoQueryable() |
| 58 | + .Where(u => u.Name.Trim() == "123"); |
| 59 | + } |
| 60 | + } |
| 61 | +} |
0 commit comments