Beispiel #1
0
        public MongoDbWriteModelUnitOfWorkTests()
        {
            fixture = new Fixture();

            //Setup mongo configuration
            configuration = fixture.Create <MongoDbConfiguration>();

            //Setup client factory
            client        = Substitute.For <IMongoClient>();
            sessionHandle = Substitute.For <IClientSessionHandle>();
            database      = Substitute.For <IMongoDatabase>();
            clientFactory = Substitute.For <IMongoClientFactory>();

            client.StartSession().Returns(sessionHandle);
            client.GetDatabase(Arg.Any <string>()).Returns(database);
            clientFactory.CreateClient(Arg.Any <MongoDbConfiguration>()).Returns(client);

            //Setup user factory
            cryptService = Substitute.For <ICryptService>();
            cryptService.Crypt(Arg.Any <string>()).Returns(args => args[0]);
            userFactory = new WriteModelUserFactory(cryptService);

            //Create unit of work
            unitOfWork = new MongoDbWriteModelUnitOfWork(configuration, clientFactory, userFactory);
        }
Beispiel #2
0
 public MongoDbAccess(
     IMongoClientFactory mongoClientFactory,
     IMongoDbSettingsProvider databaseSettingsProvider)
 {
     _mongoClientFactory = mongoClientFactory;
     _mongoDbSettings    = databaseSettingsProvider.ProvideMongoDbSettings();
 }
 public MongoDBContextTests()
 {
     _mockFactory = new Mock <IMongoClientFactory>();
     _mockFactory
     .Setup(x => x.CreateClient())
     .ReturnsAsync(new MongoClient("mongodb://test1"));
     _factory = _mockFactory.Object;
 }
Beispiel #4
0
        /// <summary>
        /// Internal constructor to allow dependency injection for unit testing.
        /// </summary>
        internal MongoSessionManager(
            HarnessConfiguration settings, IMongoClientFactory clientFactory, IFileSystem fileSystem)
        {
            this.Settings      = settings;
            this.ClientFactory = clientFactory;
            this.FileSystem    = fileSystem;

            this.MongoClients = new Dictionary <string, IMongoClient>();
        }
 public MongoDatabaseFactory(ConnectionSettings connectionSettings, IMongoClientFactory clientFactory)
 {
     _connectionSettings = connectionSettings;
     _clientFactory      = clientFactory;
     BsonSerializer.RegisterSerializer(typeof(decimal), new DecimalSerializer(BsonType.Decimal128));
     BsonSerializer.RegisterSerializer(typeof(decimal?), new NullableSerializer <decimal>(new DecimalSerializer(BsonType.Decimal128)));
     BsonSerializer.RegisterSerializer(typeof(DateTime), new DateTimeSerializer(DateTimeKind.Utc));
     BsonSerializer.RegisterSerializer(typeof(DateTime?), new NullableSerializer <DateTime>(new DateTimeSerializer(DateTimeKind.Utc)));
 }
        public static IMongoClient Create(this IMongoClientFactory mongoClientFactory, MongoDBOptions options, string defaultName)
        {
            var name = options.ClientName;

            if (string.IsNullOrWhiteSpace(name))
            {
                name = defaultName;
            }

            return(mongoClientFactory.Create(name));
        }
Beispiel #7
0
 public MongoGrainStorage(
     IMongoClientFactory mongoClientFactory,
     ILogger <MongoGrainStorage> logger,
     IGrainStateSerializer serializer,
     IOptions <MongoDBGrainStorageOptions> options)
 {
     this.mongoClient = mongoClientFactory.Create(options.Value, "Storage");
     this.logger      = logger;
     this.options     = options.Value;
     this.serializer  = serializer;
 }
 public MongoStorageProvider(
     ILogger <MongoStorageProvider <TValue> > logger,
     IOptions <MongoStoringOptions> options,
     IMongoClientFactory clientFactory,
     ISystemClock clock)
 {
     this.logger     = logger;
     this.options    = options.Value;
     this.collection = clientFactory.GetDatabase().GetCollection <MongoRecord>(this.options.SingleCollectionName);
     this.clock      = clock;
 }
 public MongoMembershipTable(
     IMongoClientFactory mongoClientFactory,
     ILogger <MongoMembershipTable> logger,
     IOptions <ClusterOptions> clusterOptions,
     IOptions <MongoDBMembershipTableOptions> options)
 {
     this.mongoClient = mongoClientFactory.Create(options.Value, "Membership");
     this.logger      = logger;
     this.options     = options.Value;
     this.clusterId   = clusterOptions.Value.ClusterId;
 }
 public MongoDbWriteModelUnitOfWork(
     MongoDbConfiguration configuration,
     IMongoClientFactory clientFactory,
     Budget.Users.Domain.WriteModel.Factories.WriteModelUserFactory userFactory
     )
 {
     Configuration  = configuration;
     Client         = clientFactory.CreateClient(configuration);
     Session        = Client.StartSession();
     Database       = Client.GetDatabase(databaseName);
     UserRepository = new MongoDbWriteModelUserRepository(Database, userFactory);
 }
Beispiel #11
0
 public MongoReminderTable(
     IMongoClientFactory mongoClientFactory,
     ILogger <MongoReminderTable> logger,
     IOptions <MongoDBRemindersOptions> options,
     IOptions <ClusterOptions> clusterOptions,
     IGrainReferenceConverter grainReferenceConverter)
 {
     this.mongoClient             = mongoClientFactory.Create(options.Value, "Membership");
     this.logger                  = logger;
     this.options                 = options.Value;
     this.serviceId               = clusterOptions.Value.ServiceId ?? string.Empty;
     this.grainReferenceConverter = grainReferenceConverter;
 }
Beispiel #12
0
 public MongoGatewayListProvider(
     IMongoClientFactory mongoClientFactory,
     ILogger <MongoGatewayListProvider> logger,
     IOptions <ClusterOptions> clusterOptions,
     IOptions <GatewayOptions> gatewayOptions,
     IOptions <MongoDBGatewayListProviderOptions> options)
 {
     this.mongoClient  = mongoClientFactory.Create(options.Value, "Membership");
     this.logger       = logger;
     this.options      = options.Value;
     this.clusterId    = clusterOptions.Value.ClusterId;
     this.MaxStaleness = gatewayOptions.Value.GatewayListRefreshPeriod;
 }
 /// <summary/>
 public MongoRecordClient(
     ILogger <MongoRecordClient> logger,
     IOptionsMonitor <MongoHandlingServerOptions> options,
     ITypeEncoder typeEncoder,
     IMongoClientFactory clientFactory)
 {
     this.logger      = logger;
     this.options     = options;
     this.typeEncoder = typeEncoder;
     this.collection  = clientFactory
                        .GetDatabase(MongoOptionsNames.DefaultName)
                        .GetCollection <MongoRecord>(MongoNames.MessageCollectionName);
 }
Beispiel #14
0
        public MongoHistoricalStorageProvider(
            ILogger <MongoHistoricalStorageProvider <TValue> > logger,
            IOptions <MongoStoringOptions> options,
            IMongoClientFactory clientFactory,
            ISystemClock clock)
        {
            this.logger  = logger;
            this.options = options.Value;
            this.clock   = clock;

            var database = clientFactory.GetDatabase();

            this.keyCollection      = database.GetCollection <MongoKeyRecord>(this.options.KeyCollectionName);
            this.keyValueCollection = database.GetCollection <MongoKeyValueRecord>(this.options.KeyValueCollectionName);
            this.valueCollection    = database.GetCollection <MongoValueRecord>(this.options.ValueCollectionName);
        }
 public MongoMessageHandlerProxy(
     ILogger <MongoMessageHandlerProxy <TMessage, TResponse> > logger,
     IOptions <MongoHandlingClientOptions> options,
     IDiagnosticContext context,
     ITypeEncoder typeEncoder,
     IMongoClientFactory clientFactory,
     ISystemClock clock,
     ExceptionModelConverter converter)
 {
     this.logger      = logger;
     this.context     = context;
     this.typeEncoder = typeEncoder;
     this.clock       = clock;
     this.options     = options.Value;
     this.collection  = clientFactory
                        .GetDatabase()
                        .GetCollection <MongoRecord>(MongoNames.MessageCollectionName);
     this.converter = converter;
 }
Beispiel #16
0
        public MongoContext(IMongoConfigurationFactory configurationFactory,
                            IMongoClientFactory clientFactory,
                            IMongoDatabaseFactory databaseFactory,
                            IMongoCollectionFactory <Question> questionCollectionFactory,
                            IMongoCollectionFactory <Answer> answerCollectionFactory,
                            IMongoCollectionFactory <SearchTerm> searchTermCollectionFactory)
        {
            this.configurationFactory        = configurationFactory;
            this.clientFactory               = clientFactory;
            this.databaseFactory             = databaseFactory;
            this.questionCollectionFactory   = questionCollectionFactory;
            this.answerCollectionFactory     = answerCollectionFactory;
            this.searchTermCollectionFactory = searchTermCollectionFactory;

            configuration = configurationFactory.Create();
            var client = clientFactory.Create(configuration);

            database = databaseFactory.GetDatabase(configuration, client);

            EnforceTextIndexes();
        }
 public DefaultMongoDbContextTest()
 {
     _configuration      = new MongoDbConfiguration();
     _mongoClientFactory = new MongoClientFactory();
     _mongoDbContext     = new DefaultMongoDbContext(_configuration, _mongoClientFactory);
 }
Beispiel #18
0
        public DefaultMongoGridFSInfrastructure(MongoContextOptions <TMongoContext> _mongoContextOptions, IMongoClientFactory _mongoClientFactory, IServiceProvider serviceProvider)
        {
            currentContextOptions = _mongoContextOptions;
            //获取mongo客户端信息
            var mongoClientInfo = _mongoClientFactory.GetMongoClient <TMongoContext>();

            //获取客户端
            currentMongoClient = mongoClientInfo.Item1;
            //获取当前上下文信息
            currentMongoContext = serviceProvider.GetService(MergeNamedType.Get(typeof(TMongoContext).Name)) as TMongoContext;
            //构建GridFS对象
            gridFSBucket = Build(currentMongoClient.GetDatabase(mongoClientInfo.Item2.DataBase), currentMongoContext.BucketName);
        }
Beispiel #19
0
        public MongoInfrastructure(MongoContextOptions <TMongoContext> _mongoContextOptions, IMongoClientFactory _mongoClientFactory)
        {
            currentContextOptions = _mongoContextOptions;
            //获取mongo客户端信息
            var mongoClientInfo = _mongoClientFactory.GetMongoClient <TMongoContext>();

            currentMongoClient   = mongoClientInfo.Item1;
            currentMongoDatabase = Build(mongoClientInfo.Item2.DataBase);
        }
Beispiel #20
0
 public MongoDBLocationStore(IMongoClientFactory factory, ILogger <MongoDBLocationStore> logger)
 {
     _factory = factory;
     _factory.Create2dSphereIndex();
     _logger = logger;
 }
Beispiel #21
0
 public MongoDBContext(IMongoClientFactory client)
 {
     _client = client.CreateClient().Result;
     _db     = _client.GetDatabase("Atlas");
 }
 public MongoDbAuditingStore(IMongoClientFactory clientFactory, IAuditingMongoDbConfiguration mongoDbConfiguration)
 {
     _clientFactory        = clientFactory;
     _mongoDbConfiguration = mongoDbConfiguration;
 }
Beispiel #23
0
 public MongoDbAccess(IMongoClientFactory mongoClientFactory, IAppSettingsProvider appSettingsProvider)
 {
     _mongoClientFactory = mongoClientFactory;
     _mongoDbSettings    = appSettingsProvider.GetAppSettings().MongoDbSettings;
 }
 /// <summary>
 /// Create a new instance of <see cref="DefaultMongoDbContext"/>.
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="mongoClientFactory"></param>
 public DefaultMongoDbContext(IMongoDbConfiguration configuration, IMongoClientFactory mongoClientFactory)
 {
     _mongoDbConfiguration = configuration;
     RegisterConventions();
     MongoClient = mongoClientFactory.CreateClient(configuration.ConnectionString);
 }
 public MongoDbRepository(IMongoDBConfiguration mongoDbConfiguration, IMongoClientFactory databaseFactory)
 {
     _databaseFactory = databaseFactory;
 }