|
20 | 20 | using FluentAssertions;
|
21 | 21 | using MongoDB.Bson;
|
22 | 22 | using MongoDB.Bson.Serialization;
|
| 23 | +using MongoDB.Driver.Core.Misc; |
| 24 | +using MongoDB.Driver.Core.TestHelpers.XunitExtensions; |
| 25 | +using MongoDB.Driver.Linq; |
| 26 | +using MongoDB.Driver.Tests.Linq.Linq3ImplementationTests; |
23 | 27 | using MongoDB.TestHelpers.XunitExtensions;
|
24 | 28 | using Moq;
|
25 | 29 | using Xunit;
|
26 | 30 |
|
27 | 31 | namespace MongoDB.Driver.Tests
|
28 | 32 | {
|
29 |
| - public class IFindFluentExtensionsTests |
| 33 | + public class IFindFluentExtensionsTests : Linq3IntegrationTest |
30 | 34 | {
|
31 | 35 | // public methods
|
32 | 36 | [Theory]
|
@@ -228,15 +232,27 @@ public void Project_should_generate_the_correct_fields_when_a_string_is_used()
|
228 | 232 | AssertProjection(subject, expectedProjection);
|
229 | 233 | }
|
230 | 234 |
|
231 |
| - [Fact] |
232 |
| - public void Project_should_generate_the_correct_fields_and_assign_the_correct_result_serializer() |
| 235 | + [Theory] |
| 236 | + [ParameterAttributeData] |
| 237 | + public void Project_should_generate_the_correct_fields_and_assign_the_correct_result_serializer( |
| 238 | + [Values(LinqProvider.V2, LinqProvider.V3)] LinqProvider linqProvider) |
233 | 239 | {
|
234 |
| - var subject = CreateSubject() |
| 240 | + if (linqProvider == LinqProvider.V3) |
| 241 | + { |
| 242 | + RequireServer.Check().Supports(Feature.FindProjectionExpressions); |
| 243 | + } |
| 244 | + |
| 245 | + var subject = CreateSubject(linqProvider) |
235 | 246 | .Project(x => x.FirstName + " " + x.LastName);
|
236 | 247 |
|
237 |
| - var expectedProjection = BsonDocument.Parse("{FirstName: 1, LastName: 1, _id: 0}"); |
| 248 | + var expectedProjection = linqProvider == LinqProvider.V2 ? |
| 249 | + BsonDocument.Parse("{ FirstName : 1, LastName : 1, _id : 0}") : |
| 250 | + BsonDocument.Parse("{ _v : { $concat : ['$FirstName', ' ', '$LastName'] }, _id : 0 }"); |
238 | 251 |
|
239 |
| - AssertProjection(subject, expectedProjection); |
| 252 | + AssertProjection(subject, expectedProjection, linqProvider); |
| 253 | + |
| 254 | + var results = subject.ToList(); |
| 255 | + results.Should().Equal("John Doe"); |
240 | 256 | }
|
241 | 257 |
|
242 | 258 | [Theory]
|
@@ -435,23 +451,31 @@ public void SortByDescending_ThenByDescending_should_generate_the_correct_sort()
|
435 | 451 | AssertSort(subject, expectedSort);
|
436 | 452 | }
|
437 | 453 |
|
438 |
| - private static void AssertProjection<TResult>(IFindFluent<Person, TResult> subject, BsonDocument expectedProjection) |
| 454 | + private static void AssertProjection<TResult>(IFindFluent<Person, TResult> subject, BsonDocument expectedProjection, LinqProvider linqProvider = LinqProvider.V3) |
439 | 455 | {
|
440 |
| - Assert.Equal(expectedProjection, subject.Options.Projection.Render(BsonSerializer.SerializerRegistry.GetSerializer<Person>(), BsonSerializer.SerializerRegistry).Document); |
| 456 | + Assert.Equal(expectedProjection, subject.Options.Projection.Render(BsonSerializer.SerializerRegistry.GetSerializer<Person>(), BsonSerializer.SerializerRegistry, linqProvider).Document); |
441 | 457 | }
|
442 | 458 |
|
443 | 459 | private static void AssertSort(IFindFluent<Person, Person> subject, BsonDocument expectedSort)
|
444 | 460 | {
|
445 | 461 | Assert.Equal(expectedSort, subject.Options.Sort.Render(BsonSerializer.SerializerRegistry.GetSerializer<Person>(), BsonSerializer.SerializerRegistry));
|
446 | 462 | }
|
447 | 463 |
|
448 |
| - private IFindFluent<Person, Person> CreateSubject() |
| 464 | + private IMongoCollection<Person> CreateCollection(LinqProvider linqProvider = LinqProvider.V3) |
| 465 | + { |
| 466 | + var collection = GetCollection<Person>(linqProvider: linqProvider); |
| 467 | + |
| 468 | + CreateCollection( |
| 469 | + collection, |
| 470 | + new Person { FirstName = "John", LastName = "Doe", Age = 21 }); |
| 471 | + |
| 472 | + return collection; |
| 473 | + } |
| 474 | + |
| 475 | + private IFindFluent<Person, Person> CreateSubject(LinqProvider linqProvider = LinqProvider.V3) |
449 | 476 | {
|
450 |
| - var settings = new MongoCollectionSettings(); |
451 |
| - var mockCollection = new Mock<IMongoCollection<Person>>(); |
452 |
| - mockCollection.SetupGet(c => c.Settings).Returns(settings); |
453 |
| - var options = new FindOptions<Person, Person>(); |
454 |
| - return new FindFluent<Person, Person>(session: null, collection: mockCollection.Object, filter: new BsonDocument(), options: options); |
| 477 | + var collection = CreateCollection(linqProvider); |
| 478 | + return collection.Find("{}"); |
455 | 479 | }
|
456 | 480 |
|
457 | 481 | public class Person
|
|
0 commit comments