예제 #1
0
        public ReadModelService(MongoSettings settings)
        {
            var client   = new MongoClient(settings.ConnectionString);
            var database = client.GetDatabase(settings.DatabaseName);

            this.collection = database.GetCollection <Package>(settings.ReadModelCollectionName);
        }
예제 #2
0
        /// <summary>
        /// Конструктор.
        /// </summary>
        /// <param name="settings">Настройки подключения к Mongo.</param>
        /// <param name="context">Контекст подключения к Mongo.</param>
        /// <param name="logger">Для логирования событий.</param>
        public MessageTemplatesRepository(IOptions <MongoSettings> settings, MongoContext context, ILogger <MessageTemplate> logger)
        {
            this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
            MongoSettings mongoSettings = settings?.Value ?? throw new ArgumentNullException(nameof(settings));

            collection = context.GetCollection <MessageTemplate>(mongoSettings.CollectionName);
        }
예제 #3
0
 public StatusController(ProxySettings proxySettings, MongoSettings mongoSettings, ProxyStore store, Status status)
 {
     ProxySettings = proxySettings;
     MongoSettings = mongoSettings;
     Store         = store;
     Status        = status;
 }
예제 #4
0
        public DataService(MongoSettings settings)
        {
            var client   = new MongoClient(settings.ConnectionString);
            var database = client.GetDatabase(settings.DatabaseName);

            _data = database.GetCollection <CellInfoMongoModel>(settings.CollectionName);
        }
예제 #5
0
        public MongoRepository(MongoSettings mongoSettings)
        {
            var database = new MongoClient(mongoSettings.ConnectionString)
                           .GetDatabase(mongoSettings.Database);

            _collection = database.GetCollection <TDocument>(GetCollectionName(typeof(TDocument)));
        }
예제 #6
0
        public ServicesRepository(MongoSettings settings)
        {
            var client   = new MongoClient(settings.ConnectionString);
            var database = client.GetDatabase(settings.DatabaseName);

            _services = database.GetCollection <Service>(settings.ServicesCollectionName);
        }
예제 #7
0
        public MongoWrapper(IOptionsMonitor <MongoSettings> dbConfig)
        {
            _options = dbConfig.CurrentValue;
            var mongoClient = new MongoClient(_options.ConnectionString);

            db = mongoClient.GetDatabase(_options.Database);
        }
 public SiteSettingsService(MongoSettings.Service.IMongoSettingsService dbService)
 {
     _dbService = dbService;
     _dbService.SettingsChanged += _dbService_SettingsChanged;
     
     LoadSiteSettings();
 }
예제 #9
0
        public TodoContext(MongoSettings settings)
        {
            var client = new MongoClient(settings.Host);
            var db     = client.GetDatabase(settings.Database);

            Todos = db.GetCollection <Todo>(nameof(Todo));
        }
예제 #10
0
        public MongoCRUD(MongoSettings settings)
        {
            var client = new MongoClient();

            this.db             = client.GetDatabase(settings.DataBaseName);
            this.collectionName = settings.CollectionName;
        }
예제 #11
0
        public NewsService(MongoSettings settings)
        {
            var client   = new MongoClient(settings.ConnectionString);
            var database = client.GetDatabase(settings.Database);

            _news = database.GetCollection <News> ("news");
        }
예제 #12
0
 public CRUDService(MongoService mongoService, MongoSettings settings, AppEngine lambdaManager)
 {
     _mongoService      = mongoService;
     _settings          = settings;
     this.lambdaManager = lambdaManager;
     LoadCollectionNames();
 }
예제 #13
0
        public void MongoBookDBContext_Constructor_Success()
        {
            try {
                var settings = new MongoSettings()
                {
                    Connection   = "mongodb://*****:*****@127.0.0.1:27017/BillTrackerDB",
                    DatabaseName = "BillTrackerDB"
                };
                _mockOptions.Setup(s => s.Value).Returns(settings);
                _mockClient.Setup(c => c
                                  .GetDatabase(_mockOptions.Object.Value.DatabaseName, null))
                .Returns(_mockDB.Object);

                //Action
                var context = new MongoDBContext(_mockOptions.Object);
                if (context != null)
                {
                    //Write test result in text file

                    String testResult = "MongoBookDBContext_Constructor_Success= True";
                    fileUtility.WriteTestCaseResuItInText(testResult);
                }
                //Assert
                Assert.NotNull(context);
            }
            catch (Exception ex)
            {
                var error = ex;
                //Write test result in text file

                String testResult = "MongoBookDBContext_Constructor_Success= False";
                fileUtility.WriteTestCaseResuItInText(testResult);
            }
        }
예제 #14
0
        public EventStoreService(MongoSettings settings)
        {
            var client   = new MongoClient(settings.ConnectionString);
            var database = client.GetDatabase(settings.DatabaseName);

            this.collection = database.GetCollection <EventStore>(settings.EventStoreCollectionName);
        }
예제 #15
0
        public async Task RunBeforeAllTests()
        {
            //Setup MongoDB InMemory
            MongoDbServer = MongoDbRunner.Start();

            // Setup IoC Container
            var builder = new ContainerBuilder();

            builder.RegisterModule(new IoCModuleApplicationService());
            builder.RegisterModule(new IoCModuleInfrastructure());
            builder.RegisterModule(new IoCModuleAutoMapper());
            builder.RegisterModule(new IoCModuleDomainTest());
            builder.RegisterModule(new IoCModuleDatabase());

            var settings = new MongoSettings
            {
                ConnectionString = MongoDbServer.ConnectionString,
                DatabaseName     = "Database-Domain-Tests"
            };

            builder.RegisterInstance(settings);
            Container = builder.Build();

            //Apply Db Migrations
            var migrator = Container.Resolve <IDatabaseMigrator>();
            await migrator.ApplyMigrations();
        }
예제 #16
0
        public MongoCodeManagmentService(IOptionsMonitor <MongoSettings> optionsMonitor)
        {
            _mongoDBStoreDatabaseSettings = optionsMonitor.CurrentValue;
            var client   = new MongoClient(_mongoDBStoreDatabaseSettings.ConnectionString);
            var database = client.GetDatabase(_mongoDBStoreDatabaseSettings.DatabaseName);

            _uploadData = database.GetCollection <UploadData>(CollectionName);
        }
예제 #17
0
        public MongoDataStore(IOptions <MongoSettings> mongoSettings)
        {
            _mongoSettings = mongoSettings.Value;
            var client   = new MongoClient(_mongoSettings.ConnectionString);
            var database = client.GetDatabase(_mongoSettings.DatabaseName);

            _collection = database.GetCollection <T>(GetCollectionName());
        }
예제 #18
0
        /// <summary>
        /// Конструктор, создает подключение к БД.
        /// </summary>
        /// <param name="settings">Настройки подключения к Mongo.</param>
        public MongoContext(IOptions <MongoSettings> settings)
        {
            MongoSettings mongoSettings = settings?.Value ?? throw new ArgumentNullException(nameof(settings));
            MongoUrl      url           = MongoUrl.Create(mongoSettings.ConnectionString);
            IMongoClient  client        = new MongoClient(url);

            database = client.GetDatabase(url.DatabaseName);
        }
        public MongoContext(MongoSettings mongoSettings)
        {
            _mongoSettings = mongoSettings;

            _commands = new List <Func <Task> >();

            Configure();
        }
예제 #20
0
        public ApplicationContext(MongoSettings settings)
        {
            string         connectionString = @"mongodb://*****:*****@mongo:27017";
            MongoClient    client           = new MongoClient(connectionString);
            IMongoDatabase database         = client.GetDatabase("resultsDB");

            Users    = database.GetCollection <User>("users");
            Criteria = database.GetCollection <ResultCriterion>("criteria");
        }
예제 #21
0
        public MongoDataContext(MongoSettings settings)
        {
            var client = new MongoClient(settings.ConnectionString);

            if (client != null)
            {
                _database = client.GetDatabase(settings.Database);
            }
        }
예제 #22
0
 public UsersApiController(IOptions <MongoSettings> mongoSettings, IOptions <EmailSettings> emailSettings, IViewRenderService viewRenderService)
 {
     _MongoSettings      = mongoSettings.Value;
     _EmailSettings      = emailSettings.Value;
     _client             = new MongoClient(_MongoSettings.MongoDbHost);
     _database           = _client.GetDatabase(_MongoSettings.DatabaseName);
     _emailHelper        = new EmailHelper(_EmailSettings);
     this._renderService = viewRenderService;
 }
예제 #23
0
        public MongoContext(IOptions <MongoSettings> mongoSettings)
        {
            _commands = new List <Func <Task> >();

            _mongoSettings = mongoSettings.Value;

            _mongoClient = new MongoClient(_mongoSettings.Connection);
            _db          = _mongoClient.GetDatabase(_mongoSettings.DatabaseName);
        }
예제 #24
0
        public QueridometroRepository(IOptions <MongoSettings> options)
        {
            _appSettings = options.Value;

            var client   = new MongoClient(_appSettings.ConnectionString);
            var database = client.GetDatabase(_appSettings.Database);

            _queridometro = database.GetCollection <Core.Entities.Queridometro>(_appSettings.Collection);
        }
예제 #25
0
 public ReviewsApiController(IOptions <MongoSettings> mongoSettings, IOptions <EmailSettings> emailSettings, IViewRenderService viewRenderService)
 {
     _MongoSettings = mongoSettings.Value;
     _client        = new MongoClient(_MongoSettings.MongoDbHost);
     _database      = _client.GetDatabase(_MongoSettings.DatabaseName);
     _imagesBucket  = new GridFSBucket(_database, new GridFSBucketOptions()
     {
         BucketName = "gallery"
     });
 }
예제 #26
0
        public DataBaseHelper(string connection, string database)
        {
            var settings = new MongoSettings
            {
                Connection   = connection,
                DatabaseName = database
            };

            _mongoContext = new MongoContext(settings);
        }
        public void Deve_Registrar_Logs_No_Repositorio_MongoDB()
        {
            //Given
            var dataBaseName = "mongo-auto-create";
            var entity       = new AggregateRoot();

            var mongoSettings = new MongoSettings
            {
                DatabaseName     = dataBaseName,
                ConnectionString = "mongodb://127.0.0.1:27017"
            };

            var setMock          = new Mock <IMongoCollection <AggregateRoot> >();
            var mongoContextMock = new Mock <MongoContext>(mongoSettings);

            var logger            = new XunitLogger <MongoRepository <AggregateRoot, Guid> >();
            var loggerFactoryMock = new Mock <ILoggerFactory>();

            loggerFactoryMock.Setup(setup => setup.CreateLogger(It.IsAny <string>())).Returns(logger);

            var repositoryMock = new MongoRepository <AggregateRoot, Guid>(mongoContextMock.Object, loggerFactoryMock.Object);

            //When
            repositoryMock.GetByIdAsync(entity.Id).ConfigureAwait(false);
            repositoryMock.GetAllAsync();
            repositoryMock.InsertAsync(entity);
            repositoryMock.UpdateAsync(entity);
            repositoryMock.DeleteAsync(entity);
            repositoryMock.DeleteAsync(entity.Id).ConfigureAwait(false);
            repositoryMock.SaveChangesAsync();

            //Then
            var msgContructor          = "Inicializando MongoRepository<AggregateRoot, Guid>";
            var msgGetById             = $"Método: GetByIdAsync( {{id:{ entity.Id }}} ) Retorno: type AggregateRoot";
            var msgGetAllAsync         = "Método: GetAllAsync() Retorno: IAsyncEnumerable<AggregateRoot>";
            var msgInsertAsync         = $"Método: InsertAsync( {{entity:{ entity.ToJson()}}} )";
            var msgUpdateAsync         = $"Método: UpdateAsync( {{entity:{ entity.ToJson()}}} )";
            var msgDeleteAsync         = $"Método: DeleteAsync( {{entity:{ entity.ToJson()}}} )";
            var msgDeleteNotFoundAsync = $"Método: DeleteAsync( {{id:{ entity.Id }}} ) Registro não encontrado";
            var msgSaveChanges         = "Método: SaveChangesAsync()";

            logger.Logs.Should().HaveCount(9);
            logger.Logs.Any(a => a.Equals(msgGetById)).Should().BeTrue();
            logger.Logs.Any(a => a.Equals(msgContructor)).Should().BeTrue();
            logger.Logs.Any(a => a.Equals(msgGetAllAsync)).Should().BeTrue();
            logger.Logs.Any(a => a.Equals(msgInsertAsync)).Should().BeTrue();
            logger.Logs.Any(a => a.Equals(msgUpdateAsync)).Should().BeTrue();
            logger.Logs.Any(a => a.Equals(msgDeleteAsync)).Should().BeTrue();
            logger.Logs.Any(a => a.Equals(msgDeleteNotFoundAsync)).Should().BeTrue();
            logger.Logs.Any(a => a.Equals(msgSaveChanges)).Should().BeTrue();

            mongoContextMock.Object.MongoClient.DropDatabase(dataBaseName);
            mongoContextMock.Object.Dispose();
        }
예제 #28
0
 public ImagesApiController(IHostingEnvironment env, IOptions <MongoSettings> mongoSettings)
 {
     hostingEnv     = env;
     _mongoSettings = mongoSettings.Value;
     _client        = new MongoClient(_mongoSettings.MongoDbHost);
     _database      = _client.GetDatabase(_mongoSettings.DatabaseName);
     _imagesBucket  = new GridFSBucket(_database, new GridFSBucketOptions()
     {
         BucketName = "gallery"
     });
 }
예제 #29
0
        public static void Setup(IServiceCollection services, AppSettings appSettings)
        {
            var mongoSettings = new MongoSettings(
                appSettings.MongoConfiguration.ConnectionString, appSettings.MongoConfiguration.Database);

            services.AddSingleton(typeof(IMongoSettings), mongoSettings);

            services.AddSingleton(typeof(IMongoClient), new MongoClient(mongoSettings.ConnectionString));

            services.AddSingleton <IMongoWrapper, MongoWrapper>();
        }
예제 #30
0
        public FileInfoService(
            MongoSettings mongoSettings,
            ISaveFileService saveFileService,
            IHttpContextAccessor contextAccessor)
        {
            var client   = new MongoClient(mongoSettings.ConnectionString);
            var database = client.GetDatabase(mongoSettings.DatabaseName);

            _files           = database.GetCollection <FileInfo>(mongoSettings.CollectionName);
            _saveFileService = saveFileService;
            _contextAccessor = contextAccessor;
        }
예제 #31
0
        private static IOptions <MongoSettings> CreateMongoSettingsOptions()
        {
            var mongoSettings = new MongoSettings()
            {
                ConnectionString = "mongodb://localhost:27017?maxPoolSize=5",
                Database         = DbName,
                CollectionPrefix = DbPrefix
            };
            var mongoSettingsOptions = Options.Create(mongoSettings);

            return(mongoSettingsOptions);
        }
예제 #32
0
 public MongoConnection(MongoSettings mongoSettings)
 {
     m_mongoSettings = mongoSettings;
 }