public IUnifiedEntityTestOperation Build(string targetCollectionId, BsonDocument arguments) { var collection = _entityMap.GetCollection(targetCollectionId); AggregateOptions options = null; PipelineDefinition <BsonDocument, BsonDocument> pipeline = null; foreach (var argument in arguments) { switch (argument.Name) { case "pipeline": var stages = argument.Value.AsBsonArray.Cast <BsonDocument>(); pipeline = new BsonDocumentStagePipelineDefinition <BsonDocument, BsonDocument>(stages); break; default: throw new FormatException($"Invalid AggregateOperation argument name: '{argument.Name}'."); } } if (pipeline.Stages.Last().OperatorName == "$out") { return(new UnifiedAggregateToCollectionOperation(collection, pipeline, options)); } else { return(new UnifiedAggregateOnCollectionOperation(collection, pipeline, options)); } }
private ProjectedResult <TResult> Group <TKey, TResult>(Expression <Func <Root, TKey> > idProjector, Expression <Func <IGrouping <TKey, Root>, TResult> > groupProjector, ExpressionTranslationOptions translationOptions) { var queryable = __collection.AsQueryable() .GroupBy(idProjector) .Select(groupProjector); var collectionSerializer = (IBsonDocumentSerializer)BsonSerializer.LookupSerializer <Root>(); var context = TranslationContext.Create(queryable.Expression, collectionSerializer); var pipeline = ExpressionToPipelineTranslator.Translate(context, queryable.Expression); pipeline = AstPipelineOptimizer.Optimize(pipeline); var stages = pipeline.Stages.Select(s => s.Render()).Cast <BsonDocument>().ToList(); stages.Insert(1, new BsonDocument("$sort", new BsonDocument("_id", 1))); // force a standard order for testing purposes var pipelineDefinition = new BsonDocumentStagePipelineDefinition <Root, TResult>(stages, outputSerializer: (IBsonSerializer <TResult>)pipeline.OutputSerializer); var results = __collection.Aggregate(pipelineDefinition).ToList(); stages.RemoveAt(1); // remove $sort added above for predictable testing return(new ProjectedResult <TResult> { Stages = stages, Value = results[0] }); }
public object aggregate(object filter, object options) { AggregateOptions aggregateOptions = new AggregateOptions(); //bool? explain = options.GetString("explain")?.To(x => Convert.ToBoolean(x)); //if (explain.HasValue) //aggregateOptions.ex bool?allowDiskUse = options.GetProperty("allowDiskUse").ToBoolOrDefault(); if (allowDiskUse.HasValue) { aggregateOptions.AllowDiskUse = allowDiskUse.Value; } bool?bypassDocumentValidation = options.GetProperty("bypassDocumentValidation").ToBoolOrDefault(); if (bypassDocumentValidation.HasValue) { aggregateOptions.BypassDocumentValidation = bypassDocumentValidation.Value; } int?batchSize = options.GetProperty("cursor").GetProperty("batchSize").ToIntOrDefault(); if (batchSize.HasValue) { aggregateOptions.UseCursor = true; aggregateOptions.BatchSize = batchSize.Value; } var stages = ((Array)filter).OfType <object>().Select(x => x.ToBsonDocument()); var pipeline = new BsonDocumentStagePipelineDefinition <BsonDocument, BsonDocument>(stages); return(new MongoEvaluatedCursor <BsonDocument>(this._collection.Aggregate(pipeline, aggregateOptions))); }
public UnifiedAggregateOnDatabaseOperation Build(string targetDatabaseId, BsonDocument arguments) { var database = _entityMap.GetDatabase(targetDatabaseId); AggregateOptions options = null; PipelineDefinition <NoPipelineInput, BsonDocument> pipeline = null; foreach (var argument in arguments) { switch (argument.Name) { case "allowDiskUse": options ??= new AggregateOptions(); options.AllowDiskUse = argument.Value.AsBoolean; break; case "pipeline": var stages = argument.Value.AsBsonArray.Cast <BsonDocument>(); pipeline = new BsonDocumentStagePipelineDefinition <NoPipelineInput, BsonDocument>(stages); break; default: throw new FormatException($"Invalid AggregateOperation argument name: '{argument.Name}'."); } } return(new UnifiedAggregateOnDatabaseOperation(database, pipeline, options)); }
public UnifiedCreateChangeStreamOnCollectionOperation Build(string targetCollectionId, BsonDocument arguments) { var collection = _entityMap.GetCollection(targetCollectionId); ChangeStreamOptions options = null; BsonDocumentStagePipelineDefinition <ChangeStreamDocument <BsonDocument>, ChangeStreamDocument <BsonDocument> > pipeline = null; foreach (var argument in arguments) { switch (argument.Name) { case "batchSize": options = options ?? new ChangeStreamOptions(); options.BatchSize = argument.Value.AsInt32; break; case "pipeline": var stages = argument.Value.AsBsonArray.Cast <BsonDocument>(); pipeline = new BsonDocumentStagePipelineDefinition <ChangeStreamDocument <BsonDocument>, ChangeStreamDocument <BsonDocument> >(stages); break; default: throw new FormatException($"Invalid CreateChangeStreamOperation argument name: '{argument.Name}'."); } } return(new UnifiedCreateChangeStreamOnCollectionOperation(collection, pipeline, options)); }
private IAsyncCursor <ChangeStreamDocument <BsonDocument> > Watch(IMongoClient client, BsonDocument test) { var target = test["target"].AsString; var stages = test["changeStreamPipeline"].AsBsonArray.Cast <BsonDocument>(); var pipeline = new BsonDocumentStagePipelineDefinition <ChangeStreamDocument <BsonDocument>, ChangeStreamDocument <BsonDocument> >(stages); var options = ParseChangeStreamOptions(test["changeStreamOptions"].AsBsonDocument); if (target == "client") { return(client.Watch(pipeline, options)); } var database = client.GetDatabase(_databaseName); if (target == "database") { return(database.Watch(pipeline, options)); } var collection = database.GetCollection <BsonDocument>(_collectionName); if (target == "collection") { return(collection.Watch(pipeline, options)); } throw new FormatException($"Invalid target: \"{target}\"."); }
protected override UpdateResult ExecuteAndGetResult(IMongoDatabase database, IMongoCollection <BsonDocument> collection, bool async) { UpdateDefinition <BsonDocument> updateDefinition = null; if (_update is BsonDocument updateDocument) { updateDefinition = new BsonDocumentUpdateDefinition <BsonDocument>(updateDocument); } else if (_update is BsonArray stages) { var pipeline = new BsonDocumentStagePipelineDefinition <BsonDocument, BsonDocument>(stages.Cast <BsonDocument>()); updateDefinition = new PipelineUpdateDefinition <BsonDocument>(pipeline); } if (async) { return(collection .UpdateManyAsync(_filter, updateDefinition, _options) .GetAwaiter() .GetResult()); } else { return(collection.UpdateMany(_filter, updateDefinition, _options)); } }
internal override Task ExecuteAsync <TInput>(IMongoCollection <TInput> collection, AggregateOptions options, CancellationToken cancellationToken) { var pipeline = new BsonDocumentStagePipelineDefinition <TInput, TOutput>( _stages, _outputSerializer); return(collection.AggregateAsync(pipeline, options, cancellationToken)); }
public UnifiedCreateChangeStreamOnClientOperation( IMongoClient client, BsonDocumentStagePipelineDefinition <ChangeStreamDocument <BsonDocument>, ChangeStreamDocument <BsonDocument> > pipeline, ChangeStreamOptions options) { _client = client; _pipeline = pipeline; _options = options; }
public UnifiedCreateChangeStreamOnCollectionOperation( IMongoCollection <BsonDocument> collection, BsonDocumentStagePipelineDefinition <ChangeStreamDocument <BsonDocument>, ChangeStreamDocument <BsonDocument> > pipeline, ChangeStreamOptions options) { _collection = collection; _pipeline = pipeline; _options = options; }
/// <summary> /// Save As View /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSaveAsView_Click(object sender, EventArgs e) { if (stages.Count == 0) return; var strViewName = MyMessageBox.ShowInput("pls Input Aggregate Pipeline Name :", "Save Aggregate Pipeline"); var pipeline = new BsonDocumentStagePipelineDefinition<BsonDocument, BsonDocument>(stages.Values.Select(x => (BsonDocument)x)); RuntimeMongoDbContext.GetCurrentIMongoDataBase().CreateView(strViewName, RuntimeMongoDbContext.GetCurrentCollectionName() , pipeline); }
public UnifiedCreateChangeStreamOnDatabaseOperation( IMongoDatabase database, BsonDocumentStagePipelineDefinition <ChangeStreamDocument <BsonDocument>, ChangeStreamDocument <BsonDocument> > pipeline, ChangeStreamOptions options) { _database = database; _pipeline = pipeline; _options = options; }
/// <summary> /// 确定 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmdOK_Click(object sender, EventArgs e) { try { var pipeline = new BsonDocumentStagePipelineDefinition <BsonDocument, BsonDocument>(stages.Values.Select(x => (BsonDocument)x)); RuntimeMongoDbContext.GetCurrentIMongoDataBase().CreateView(txtViewName.Text, cmbViewOn.Text, pipeline); } catch (Exception ex) { Utility.ExceptionDeal(ex); } }
/// <summary> /// Save As View /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSaveAsView_Click(object sender, EventArgs e) { if (stages.Count == 0) { return; } var strViewName = MyMessageBox.ShowInput("pls Input Aggregate Pipeline Name :", "Save Aggregate Pipeline"); var pipeline = new BsonDocumentStagePipelineDefinition <BsonDocument, BsonDocument>(stages.Values.Select(x => (BsonDocument)x)); RuntimeMongoDbContext.GetCurrentIMongoDataBase().CreateView(strViewName, RuntimeMongoDbContext.GetCurrentCollectionName(), pipeline); }
public IUnifiedEntityTestOperation Build(string targetCollectionId, BsonDocument arguments) { var collection = _entityMap.GetCollection(targetCollectionId); AggregateOptions options = null; PipelineDefinition <BsonDocument, BsonDocument> pipeline = null; IClientSessionHandle session = null; foreach (var argument in arguments) { switch (argument.Name) { case "batchSize": options ??= new AggregateOptions(); options.BatchSize = argument.Value.ToInt32(); break; case "let": options ??= new AggregateOptions(); options.Let = argument.Value.AsBsonDocument; break; case "pipeline": var stages = argument.Value.AsBsonArray.Cast <BsonDocument>(); pipeline = new BsonDocumentStagePipelineDefinition <BsonDocument, BsonDocument>(stages); break; case "session": session = _entityMap.GetSession(argument.Value.AsString); break; default: throw new FormatException($"Invalid AggregateOperation argument name: '{argument.Name}'."); } } var lastStageName = pipeline.Stages.LastOrDefault()?.OperatorName; if (lastStageName == "$out" || lastStageName == "$merge") { return(new UnifiedAggregateToCollectionOperation(collection, pipeline, options)); } else { return(new UnifiedAggregateOnCollectionOperation(collection, pipeline, options, session)); } }
/// <summary> /// 确定 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmdOK_Click(object sender, EventArgs e) { try { var pipeline = new BsonDocumentStagePipelineDefinition <BsonDocument, BsonDocument>(stages.Values.Select(x => (BsonDocument)x)); CreateViewOptions <BsonDocument> OptionalDoc = null; if (mCollation != null) { OptionalDoc = new CreateViewOptions <BsonDocument>(); OptionalDoc.Collation = mCollation; } RuntimeMongoDbContext.GetCurrentIMongoDataBase().CreateView(txtViewName.Text, cmbViewOn.Text, pipeline, OptionalDoc); } catch (Exception ex) { Utility.ExceptionDeal(ex); } }
public override async Task <OperationResult> ExecuteAsync(CancellationToken cancellationToken) { var pipelineDefinition = new BsonDocumentStagePipelineDefinition <NoPipelineInput, BsonDocument>(_pipeline, BsonDocumentSerializer.Instance); try { using var cursor = _session == null ? await _database.AggregateAsync(pipelineDefinition, _options, cancellationToken) : await _database.AggregateAsync(_session, pipelineDefinition, _options, cancellationToken); var result = await cursor.ToListAsync(cancellationToken); return(OperationResult.FromResult(new BsonArray(result))); } catch (Exception exception) { return(OperationResult.FromException(exception)); } }
public override OperationResult Execute(CancellationToken cancellationToken) { var pipelineDefinition = new BsonDocumentStagePipelineDefinition <BsonDocument, BsonDocument>(_pipeline, BsonDocumentSerializer.Instance); try { using var cursor = _session == null ? _collection.Aggregate(pipelineDefinition, _options, cancellationToken) : _collection.Aggregate(_session, pipelineDefinition, _options, cancellationToken); var result = cursor.ToList(cancellationToken); return(OperationResult.FromResult(new BsonArray(result))); } catch (Exception exception) { return(OperationResult.FromException(exception)); } }
public void Nested_Select_should_work() { var client = DriverTestConfiguration.Linq3Client; var database = client.GetDatabase("FooBar"); var collection = database.GetCollection <FooNest>("Foos"); database.DropCollection("Foos"); collection.InsertOne( new FooNest { Name = "Parent", NestedCollection = new[] { new FooNest { Name = "Child" } } }); var queryable = collection.AsQueryable() .Select(top => top.NestedCollection.Select(child => new { ParentName = top.Name, child.Name })); var stages = Linq3TestHelpers.Translate(collection, queryable); var expectedStages = new[] { "{ $project : { _v : { $map : { input : '$NestedCollection', as : 'child', in : { ParentName : '$Name', Name : '$$child.Name' } } }, _id : 0 } }" }; Linq3TestHelpers.AssertStages(stages, expectedStages); var pipelineDefinition = new BsonDocumentStagePipelineDefinition <FooNest, BsonDocument>(stages); var resultAsDocument = collection.Aggregate(pipelineDefinition).ToList().Single(); resultAsDocument.Should().Be("{ _v : [{ ParentName : 'Parent', Name : 'Child' }] }"); var result = queryable.ToList().Single().ToList(); result.Should().HaveCount(1); result[0].ParentName.Should().Be("Parent"); result[0].Name.Should().Be("Child"); }
public override async Task <OperationResult> ExecuteAsync(CancellationToken cancellationToken) { var pipelineDefinition = new BsonDocumentStagePipelineDefinition <NoPipelineInput, BsonDocument>(_pipeline, BsonDocumentSerializer.Instance); try { if (_session == null) { await _database.AggregateToCollectionAsync(pipelineDefinition, _options, cancellationToken); } else { await _database.AggregateToCollectionAsync(_session, pipelineDefinition, _options, cancellationToken); } return(OperationResult.FromResult(null)); } catch (Exception exception) { return(OperationResult.FromException(exception)); } }
public override OperationResult Execute(CancellationToken cancellationToken) { var pipelineDefinition = new BsonDocumentStagePipelineDefinition <BsonDocument, BsonDocument>(_pipeline, BsonDocumentSerializer.Instance); try { if (_session == null) { _collection.AggregateToCollection(pipelineDefinition, _options, cancellationToken); } else { _collection.AggregateToCollection(_session, pipelineDefinition, _options, cancellationToken); } return(OperationResult.FromResult(null)); } catch (Exception exception) { return(OperationResult.FromException(exception)); } }
public void CreateView_should_execute_a_CreateViewOperation_with_the_expected_Collation( [Values(null, "en_US", "fr_CA")] string locale, [Values(false, true)] bool async) { var pipeline = new BsonDocumentStagePipelineDefinition<BsonDocument, BsonDocument>(new BsonDocument[0]); var collation = locale == null ? null : new Collation(locale); var options = new CreateViewOptions<BsonDocument> { Collation = collation }; if (async) { _subject.CreateViewAsync<BsonDocument, BsonDocument>("viewName", "viewOn", pipeline, options, CancellationToken.None).GetAwaiter().GetResult(); } else { _subject.CreateView<BsonDocument, BsonDocument>("viewName", "viewOn", pipeline, options, CancellationToken.None); } var call = _operationExecutor.GetWriteCall<BsonDocument>(); var operation = call.Operation.Should().BeOfType<CreateViewOperation>().Subject; operation.Collation.Should().BeSameAs(collation); }
public void Nested_Select_should_work() { var client = DriverTestConfiguration.Linq3Client; var database = client.GetDatabase("foo"); var parents = database.GetCollection <Parent>("parents"); var children = database.GetCollection <Child>("children"); var grandChildren = database.GetCollection <GrandChild>("grandChildren"); database.DropCollection("parents"); database.DropCollection("children"); database.DropCollection("grandChildren"); parents.InsertMany(new[] { new Parent { Id = 1, Name = "parent1" }, new Parent { Id = 2, Name = "parent2" } }); children.InsertMany(new[] { new Child { Id = 1, Name = "child1", ParentId = 2 }, new Child { Id = 2, Name = "child2", ParentId = 1 } }); grandChildren.InsertMany(new[] { new GrandChild { Id = 1, Name = "grandchild1", ChildId = 2 }, new GrandChild { Id = 2, Name = "grandchild2", ChildId = 1 } }); var aggregate = parents .Aggregate() .Lookup <Parent, Child, ParentProjection>( children, parent => parent.Id, child => child.ParentId, parentProjection => parentProjection.Children) .Lookup <ParentProjection, GrandChild, GrandChild, IEnumerable <GrandChild>, ParentProjection>( grandChildren, let: new BsonDocument { { "children", "$Children" } }, lookupPipeline: new BsonDocumentStagePipelineDefinition <GrandChild, GrandChild>( new[] { BsonDocument.Parse(@"{ $match : { $expr : { $and : [ { $in : [ ""$ChildId"", ""$$children._id"" ] } ] } } }") }), childProjection => childProjection.GrandChildren) .Project(parent => new ParentTree { Id = parent.Id, ParentName = parent.Name, Children = parent.Children .Select(child => new ChildTree { Id = child.Id, Name = child.Name, GrandChildren = parent .GrandChildren .Where(gc => gc.ChildId == child.Id) .Select(gc => new GrandChildProjection() { Id = gc.Id, Name = gc.Name }) }) }); var stages = Linq3TestHelpers.Translate(parents, aggregate); var expectedStages = new[] { @"{ '$lookup':{ 'from':'children', 'localField':'_id', 'foreignField':'ParentId', 'as':'Children' } }", @"{ '$lookup':{ 'from':'grandChildren', 'let':{'children':'$Children'}, 'pipeline':[ { '$match':{'$expr':{'$and':[{'$in':['$ChildId','$$children._id']}]}}} ], 'as':'GrandChildren' } }", @"{ '$project':{ '_id':'$_id', 'ParentName':'$Name', 'Children':{ '$map':{ 'input':'$Children', 'as':'child', 'in':{ '_id':'$$child._id', 'Name':'$$child.Name', 'GrandChildren':{ '$map':{ 'input':{ '$filter':{ 'input':'$GrandChildren', 'as':'gc', 'cond':{ '$eq':[ '$$gc.ChildId', '$$child._id' ] } } }, 'as':'gc', 'in':{ '_id':'$$gc._id', 'Name':'$$gc.Name' } } } } } } } }" }; Linq3TestHelpers.AssertStages(stages, expectedStages); var pipelineDefinition = new BsonDocumentStagePipelineDefinition <Parent, BsonDocument>(expectedStages.Select(s => BsonDocument.Parse(s))); var resultBsonDocuments = parents.Aggregate(pipelineDefinition).ToList(); var expectedBsonDocuments = new[] { "{ '_id' : 1, 'ParentName' : 'parent1', 'Children' : [{ '_id' : 2, 'Name' : 'child2', 'GrandChildren' : [{ '_id' : 1, 'Name' : 'grandchild1' }] }] }", "{ '_id' : 2, 'ParentName' : 'parent2', 'Children' : [{ '_id' : 1, 'Name' : 'child1', 'GrandChildren' : [{ '_id' : 2, 'Name' : 'grandchild2' }] }] }" }; resultBsonDocuments.Should().Equal(expectedBsonDocuments.Select(d => BsonDocument.Parse(d))); var result = aggregate.ToList(); var expectedResults = new[] { new ParentTree { Id = 1, ParentName = "parent1", Children = new[] { new ChildTree { Id = 2, Name = "child2", GrandChildren = new[] { new GrandChildProjection { Id = 1, Name = "grandchild1" } } } } }, new ParentTree { Id = 2, ParentName = "parent2", Children = new[] { new ChildTree { Id = 1, Name = "child1", GrandChildren = new[] { new GrandChildProjection { Id = 2, Name = "grandchild2" } } } } } }; var parentTreeComparer = new ParentTreeComparer(); result.Should().Equal(expectedResults, (x, y) => parentTreeComparer.Equals(x, y)); }
public void CreateView_should_throw_when_viewOn_is_null( [Values(false, true)] bool async) { var pipeline = new BsonDocumentStagePipelineDefinition<BsonDocument, BsonDocument>(new BsonDocument[0]); var exception = Record.Exception(() => { if (async) { _subject.CreateViewAsync<BsonDocument, BsonDocument>("viewName", null, pipeline).GetAwaiter().GetResult(); } else { _subject.CreateView<BsonDocument, BsonDocument>("viewName", null, pipeline); } }); var argumentNullException = exception.Should().BeOfType<ArgumentNullException>().Subject; argumentNullException.ParamName.Should().Be("viewOn"); }
public void CreateView_should_execute_a_CreateViewOperation_with_the_expected_Pipeline( [Values(1, 2)] int x, [Values(false, true)] bool async) { var stages = new[] { new BsonDocument("$match", new BsonDocument("x", x)) }; var pipeline = new BsonDocumentStagePipelineDefinition<BsonDocument, BsonDocument>(stages); if (async) { _subject.CreateViewAsync<BsonDocument, BsonDocument>("viewName", "viewOn", pipeline, null, CancellationToken.None).GetAwaiter().GetResult(); } else { _subject.CreateView<BsonDocument, BsonDocument>("viewName", "viewOn", pipeline, null, CancellationToken.None); } var call = _operationExecutor.GetWriteCall<BsonDocument>(); var operation = call.Operation.Should().BeOfType<CreateViewOperation>().Subject; operation.Pipeline.Should().Equal(stages); }
public void CreateView_should_execute_a_CreateViewOperation_with_the_expected_WriteConcern( [Values(1, 2)] int w, [Values(false, true)] bool async) { var writeConcern = new WriteConcern(w); var subject = _subject.WithWriteConcern(writeConcern); var pipeline = new BsonDocumentStagePipelineDefinition<BsonDocument, BsonDocument>(new BsonDocument[0]); if (async) { subject.CreateViewAsync<BsonDocument, BsonDocument>("viewName", "viewOn", pipeline, null, CancellationToken.None).GetAwaiter().GetResult(); } else { subject.CreateView<BsonDocument, BsonDocument>("viewName", "viewOn", pipeline, null, CancellationToken.None); } var call = _operationExecutor.GetWriteCall<BsonDocument>(); var operation = call.Operation.Should().BeOfType<CreateViewOperation>().Subject; operation.WriteConcern.Should().BeSameAs(writeConcern); }
/// <summary> /// 确定 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cmdOK_Click(object sender, EventArgs e) { try { var pipeline = new BsonDocumentStagePipelineDefinition<BsonDocument, BsonDocument>(stages.Values.Select(x => (BsonDocument)x)); CreateViewOptions<BsonDocument> OptionalDoc = null; if (mCollation != null) { OptionalDoc = new CreateViewOptions<BsonDocument>(); OptionalDoc.Collation = mCollation; } RuntimeMongoDbContext.GetCurrentIMongoDataBase().CreateView(txtViewName.Text, cmbViewOn.Text, pipeline, OptionalDoc); } catch (Exception ex) { Utility.ExceptionDeal(ex); } }
public void CreateView_should_execute_a_CreateViewOperation_with_the_expected_CancellationToken( [Values(false, true)] bool async) { var pipeline = new BsonDocumentStagePipelineDefinition<BsonDocument, BsonDocument>(new BsonDocument[0]); var cancellationToken = new CancellationTokenSource().Token; if (async) { _subject.CreateViewAsync<BsonDocument, BsonDocument>("viewName", "viewOn", pipeline, null, cancellationToken).GetAwaiter().GetResult(); } else { _subject.CreateView<BsonDocument, BsonDocument>("viewName", "viewOn", pipeline, null, cancellationToken); } var call = _operationExecutor.GetWriteCall<BsonDocument>(); var operation = call.Operation.Should().BeOfType<CreateViewOperation>().Subject; call.CancellationToken.Should().Be(cancellationToken); }
public void CreateView_should_execute_a_CreateViewOperation_with_the_expected_ViewOn( [Values("a", "b")] string viewOn, [Values(false, true)] bool async) { var pipeline = new BsonDocumentStagePipelineDefinition<BsonDocument, BsonDocument>(new BsonDocument[0]); if (async) { _subject.CreateViewAsync<BsonDocument, BsonDocument>("viewName", viewOn, pipeline, null, CancellationToken.None).GetAwaiter().GetResult(); } else { _subject.CreateView<BsonDocument, BsonDocument>("viewName", viewOn, pipeline, null, CancellationToken.None); } var call = _operationExecutor.GetWriteCall<BsonDocument>(); var operation = call.Operation.Should().BeOfType<CreateViewOperation>().Subject; operation.ViewOn.Should().Be(viewOn); }