Skip to content

Commit d3f55b3

Browse files
authored
CSHARP-2480: Fix ambiguous API calls (#1474)
1 parent f73ba60 commit d3f55b3

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

src/MongoDB.Driver/IMongoCollectionExtensions.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ public static IFindFluent<TDocument, TDocument> Find<TDocument>(this IMongoColle
14261426
/// <returns>
14271427
/// The deleted document if one was deleted.
14281428
/// </returns>
1429-
public static TDocument FindOneAndDelete<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, FindOneAndDeleteOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
1429+
public static TDocument FindOneAndDelete<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, FindOneAndDeleteOptions<TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
14301430
{
14311431
Ensure.IsNotNull(collection, nameof(collection));
14321432
Ensure.IsNotNull(filter, nameof(filter));
@@ -1548,7 +1548,7 @@ public static IFindFluent<TDocument, TDocument> Find<TDocument>(this IMongoColle
15481548
/// <returns>
15491549
/// The deleted document if one was deleted.
15501550
/// </returns>
1551-
public static Task<TDocument> FindOneAndDeleteAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, FindOneAndDeleteOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
1551+
public static Task<TDocument> FindOneAndDeleteAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, FindOneAndDeleteOptions<TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
15521552
{
15531553
Ensure.IsNotNull(collection, nameof(collection));
15541554
Ensure.IsNotNull(filter, nameof(filter));
@@ -1672,7 +1672,7 @@ public static IFindFluent<TDocument, TDocument> Find<TDocument>(this IMongoColle
16721672
/// <returns>
16731673
/// The returned document.
16741674
/// </returns>
1675-
public static TDocument FindOneAndReplace<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
1675+
public static TDocument FindOneAndReplace<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
16761676
{
16771677
Ensure.IsNotNull(collection, nameof(collection));
16781678
Ensure.IsNotNull(filter, nameof(filter));
@@ -1800,7 +1800,7 @@ public static IFindFluent<TDocument, TDocument> Find<TDocument>(this IMongoColle
18001800
/// <returns>
18011801
/// The returned document.
18021802
/// </returns>
1803-
public static Task<TDocument> FindOneAndReplaceAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
1803+
public static Task<TDocument> FindOneAndReplaceAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, TDocument replacement, FindOneAndReplaceOptions<TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
18041804
{
18051805
Ensure.IsNotNull(collection, nameof(collection));
18061806
Ensure.IsNotNull(filter, nameof(filter));
@@ -1933,7 +1933,7 @@ public static IFindFluent<TDocument, TDocument> Find<TDocument>(this IMongoColle
19331933
/// <returns>
19341934
/// The returned document.
19351935
/// </returns>
1936-
public static TDocument FindOneAndUpdate<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
1936+
public static TDocument FindOneAndUpdate<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
19371937
{
19381938
Ensure.IsNotNull(collection, nameof(collection));
19391939
Ensure.IsNotNull(filter, nameof(filter));
@@ -2085,7 +2085,7 @@ public static IFindFluent<TDocument, TDocument> Find<TDocument>(this IMongoColle
20852085
/// <returns>
20862086
/// The returned document.
20872087
/// </returns>
2088-
public static Task<TDocument> FindOneAndUpdateAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument, TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
2088+
public static Task<TDocument> FindOneAndUpdateAsync<TDocument>(this IMongoCollection<TDocument> collection, Expression<Func<TDocument, bool>> filter, UpdateDefinition<TDocument> update, FindOneAndUpdateOptions<TDocument> options = null, CancellationToken cancellationToken = default(CancellationToken))
20892089
{
20902090
Ensure.IsNotNull(collection, nameof(collection));
20912091
Ensure.IsNotNull(filter, nameof(filter));

tests/MongoDB.Driver.Tests/IMongoCollectionExtensionsTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
using System.Threading;
2121
using FluentAssertions;
2222
using MongoDB.Bson;
23-
using MongoDB.Driver.Linq;
2423
using MongoDB.Driver.Tests.Linq.Linq3Implementation;
2524
using MongoDB.TestHelpers.XunitExtensions;
2625
using Moq;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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 Moq;
17+
using Xunit;
18+
19+
namespace MongoDB.Driver.Tests.Jira
20+
{
21+
public class CSharp2480Tests
22+
{
23+
[Fact(Skip = "No need to run the test, we just need to be sure that the method calls are non-ambiguous")]
24+
public void Test()
25+
{
26+
var collection = new Mock<IMongoCollection<Person>>().Object;
27+
28+
var replace = new Person { Name = "newName" };
29+
collection.FindOneAndReplace(c => c.Name == "Test", replace, new FindOneAndReplaceOptions<Person>());
30+
collection.FindOneAndReplaceAsync(c => c.Name == "Test", replace, new FindOneAndReplaceOptions<Person>());
31+
32+
var updateDefinition = new ObjectUpdateDefinition<Person>(new Person());
33+
collection.FindOneAndUpdate(c => c.Name == "Test", updateDefinition, new FindOneAndUpdateOptions<Person>());
34+
collection.FindOneAndUpdateAsync(c => c.Name == "Test", updateDefinition, new FindOneAndUpdateOptions<Person>());
35+
36+
collection.FindOneAndDelete(c => c.Name == "Test", new FindOneAndDeleteOptions<Person>());
37+
collection.FindOneAndDeleteAsync(c => c.Name == "Test", new FindOneAndDeleteOptions<Person>());
38+
}
39+
40+
private class Person
41+
{
42+
public string Name { get; set; }
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)