public async Task Aggregate_should_execute_the_AggregateOperation_when_out_is_not_specified() { var pipeline = new object[] { BsonDocument.Parse("{$match: {x: 2}}") }; var fluent = _subject.Aggregate(new AggregateOptions { AllowDiskUse = true, BatchSize = 10, MaxTime = TimeSpan.FromSeconds(3), UseCursor = false }) .Match("{x: 2}"); var options = fluent.Options; var fakeCursor = NSubstitute.Substitute.For <IAsyncCursor <BsonDocument> >(); _operationExecutor.EnqueueResult(fakeCursor); await fluent.ToCursorAsync(CancellationToken.None); var call = _operationExecutor.GetReadCall <IAsyncCursor <BsonDocument> >(); call.Operation.Should().BeOfType <AggregateOperation <BsonDocument> >(); var operation = (AggregateOperation <BsonDocument>)call.Operation; operation.CollectionNamespace.FullName.Should().Be("foo.bar"); operation.AllowDiskUse.Should().Be(options.AllowDiskUse); operation.BatchSize.Should().Be(options.BatchSize); operation.MaxTime.Should().Be(options.MaxTime); operation.UseCursor.Should().Be(options.UseCursor); operation.Pipeline.Should().ContainInOrder(pipeline); }
public async Task Aggregate_should_execute_the_AggregateOperation_when_out_is_not_specified() { var pipeline = new object[] { BsonDocument.Parse("{ $match: { x: 2 } }"), BsonDocument.Parse("{ $project : { Age : \"$age\", Name : { $concat : [\"$firstName\", \" \", \"$lastName\"] }, _id : 0 } }"), BsonDocument.Parse("{ $group : { _id : \"$Age\", Name : { \"$first\" : \"$Name\" } } }"), BsonDocument.Parse("{ $project : { _id: 1 } }") }; var fluent = _subject.Aggregate(new AggregateOptions { AllowDiskUse = true, BatchSize = 10, MaxTime = TimeSpan.FromSeconds(3), UseCursor = false }) .Match("{x: 2}") .Project(x => new { Age = x["age"], Name = (string)x["firstName"] + " " + (string)x["lastName"] }) .Group(x => x.Age, g => new { _id = g.Key, Name = g.First().Name }) .Project("{ _id: 1 }"); var options = fluent.Options; var fakeCursor = NSubstitute.Substitute.For <IAsyncCursor <BsonDocument> >(); _operationExecutor.EnqueueResult(fakeCursor); await fluent.ToCursorAsync(CancellationToken.None); var call = _operationExecutor.GetReadCall <IAsyncCursor <BsonDocument> >(); call.Operation.Should().BeOfType <AggregateOperation <BsonDocument> >(); var operation = (AggregateOperation <BsonDocument>)call.Operation; operation.CollectionNamespace.FullName.Should().Be("foo.bar"); operation.AllowDiskUse.Should().Be(options.AllowDiskUse); operation.BatchSize.Should().Be(options.BatchSize); operation.MaxTime.Should().Be(options.MaxTime); operation.UseCursor.Should().Be(options.UseCursor); operation.Pipeline.Should().Equal(pipeline); }