public void constructor_should_initialize_instance( [Values(false, true)] bool withSession) { var collection = Mock.Of <IMongoCollection <BsonDocument> >(); var session = withSession ? Mock.Of <IClientSessionHandle>() : null; var options = new AggregateOptions(); var subject = new MongoQueryProviderImpl <BsonDocument>(collection, session, options); subject._collection().Should().BeSameAs(collection); subject._session().Should().BeSameAs(session); subject._options().Should().BeSameAs(options); }
public void ExecuteModel_should_call_Execute_with_expected_arguments( [Values(false, true)] bool withSession, [Values(false, true)] bool async) { var collection = Mock.Of <IMongoCollection <BsonDocument> >(); var session = withSession ? Mock.Of <IClientSessionHandle>() : null; var options = new AggregateOptions(); var subject = new MongoQueryProviderImpl <BsonDocument>(collection, session, options); var mockModel = new Mock <QueryableExecutionModel>(); var cancellationToken = new CancellationToken(); if (async) { subject.ExecuteModelAsync(mockModel.Object, cancellationToken).GetAwaiter().GetResult(); mockModel.Verify(m => m.ExecuteAsync(collection, session, options, cancellationToken), Times.Once); } else { subject.ExecuteModel(mockModel.Object); mockModel.Verify(m => m.Execute(collection, session, options), Times.Once); } }
public static AggregateOptions _options <TDocument>(this MongoQueryProviderImpl <TDocument> obj) { var fieldInfo = typeof(MongoQueryProviderImpl <TDocument>).GetField("_options", BindingFlags.NonPublic | BindingFlags.Instance); return((AggregateOptions)fieldInfo.GetValue(obj)); }
public static IMongoCollection <TDocument> _collection <TDocument>(this MongoQueryProviderImpl <TDocument> obj) { var fieldInfo = typeof(MongoQueryProviderImpl <TDocument>).GetField("_collection", BindingFlags.NonPublic | BindingFlags.Instance); return((IMongoCollection <TDocument>)fieldInfo.GetValue(obj)); }
public static IClientSessionHandle _session <TDocument>(this MongoQueryProviderImpl <TDocument> obj) => (IClientSessionHandle)Reflector.GetFieldValue(obj, nameof(_session));
public static AggregateOptions _options <TDocument>(this MongoQueryProviderImpl <TDocument> obj) => (AggregateOptions)Reflector.GetFieldValue(obj, nameof(_options));
public static IMongoCollection <TDocument> _collection <TDocument>(this MongoQueryProviderImpl <TDocument> obj) => (IMongoCollection <TDocument>)Reflector.GetFieldValue(obj, nameof(_collection));
/// <summary> /// Creates a queryable source of documents. /// </summary> /// <typeparam name="TDocument">The type of the document.</typeparam> /// <param name="collection">The collection.</param> /// <returns>A queryable source of documents.</returns> public static IMongoQueryable <TDocument> AsQueryable <TDocument>(this IMongoCollection <TDocument> collection) { var provider = new MongoQueryProviderImpl <TDocument>(collection, new AggregateOptions()); return(new MongoQueryableImpl <TDocument, TDocument>(provider)); }