Exemplo n.º 1
0
        public MongoRepository(MongoConnectionSettings settings)
        {
            IMongoClient   client = new MongoClient(settings.ConnectionString);
            IMongoDatabase db     = client.GetDatabase(settings.Database);

            itemCollection = db.GetCollection <T>(settings.CollectionName);
        }
Exemplo n.º 2
0
        public void ConfigureContainer(ContainerBuilder builder)
        {
            MongoConnectionSettings mongoSettings = GetMongoSettings();
            var mongoClient  = new MongoClient(mongoSettings.ConnectionString);
            var mongoContext = new MongoContext(mongoClient, mongoSettings);

            builder.Register(c => new PersonRepository(mongoContext)).AsImplementedInterfaces();
        }
Exemplo n.º 3
0
        public void Setup()
        {
            var sets     = MongoConnectionSettings.Get();
            var client   = new MongoClient(sets.GetConnectionString());
            var database = client.GetDatabase(sets.Database);

            _col = database.GetCollection <Person>("persons");
        }
        public MongoDbRepositoryBase(MongoConnectionSettings mongoConnectionSetting, string collectionName)
        {
            this.collectionName = collectionName;
            ConnectionSettingControl(mongoConnectionSetting);
            MongoClient client = mongoConnectionSetting.GetMongoClientSettings() == null
                ? new MongoClient(mongoConnectionSetting.ConnectionString)
                : new MongoClient(mongoConnectionSetting.GetMongoClientSettings());
            var database = client.GetDatabase(mongoConnectionSetting.DatabaseName);

            _collection = database.GetCollection <T>(collectionName);
        }
        private void ConnectionSettingControl(MongoConnectionSettings settings)
        {
            if (settings.GetMongoClientSettings() != null && (string.IsNullOrEmpty(collectionName) || string.IsNullOrEmpty(settings.DatabaseName)))
            {
                throw new Exception(DocumentDbMessages.NullOremptyMessage);
            }

            if (string.IsNullOrEmpty(collectionName) || string.IsNullOrEmpty(settings.ConnectionString) || string.IsNullOrEmpty(settings.DatabaseName))
            {
                throw new Exception(DocumentDbMessages.NullOremptyMessage);
            }
        }
        public async Task SeedPersons()
        {
            var sets     = MongoConnectionSettings.Get();
            var client   = new MongoClient(sets.GetConnectionString());
            var database = client.GetDatabase(sets.Database);

            string GetFileContent(string p) => File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(), "Seed", p));

            // Data generated with https://mockaroo.com/
            database.DropCollection("persons");
            var persons = JsonConvert.DeserializeObject <IEnumerable <Person> >(GetFileContent("persons.json"));
            var db      = database.GetCollection <Person>("persons");
            await db.InsertManyAsync(persons);
        }
Exemplo n.º 7
0
        public MongoRepository(MongoConnectionSettings connectionSettings)
        {
            var parsed = int.TryParse(connectionSettings.Port, out var port);
            var client = new MongoClient(new MongoClientSettings
            {
                Server = new MongoServerAddress(connectionSettings.Host, parsed ? port : DefaultMongoPort)
            });

            _db = client.GetDatabase(connectionSettings.Database);
            if (!CollectionExists(_db, "users"))
            {
                _db.CreateCollection("users");
            }
        }
Exemplo n.º 8
0
        private void ConnectionSettingControl(MongoConnectionSettings settings)
        {
            if (settings.GetMongoClientSettings() != null &&
                (string.IsNullOrEmpty(collectionName) || string.IsNullOrEmpty(settings.DatabaseName)))
            {
                throw new Exception("Value cannot be null or empty");
            }


            if (string.IsNullOrEmpty(collectionName) ||
                string.IsNullOrEmpty(settings.ConnectionString) ||
                string.IsNullOrEmpty(settings.DatabaseName))
            {
                throw new Exception("Value cannot be null or empty");
            }
        }
Exemplo n.º 9
0
        public virtual void Setup()
        {
            this.Runner = MongoDbRunner.Start();

            this.Settings = new MongoConnectionSettings
            {
                ConnectionString = this.Runner.ConnectionString,
                Database         = "IntegrationTests",
            };

            this.MongoClient = new MongoClient(this.Settings.ConnectionString);
            this.Database    = this.MongoClient.GetDatabase(this.Settings.Database);

            this.factory = new CustomWebApplicationFactory <Startup>(this.Settings);
            this.Client  = this.factory.CreateClient(new WebApplicationFactoryClientOptions
            {
                AllowAutoRedirect = false,
            });
        }
Exemplo n.º 10
0
 public PushController(MongoConnectionSettings settings, IConfiguration config)
 {
     settings.CollectionName = "push";
     _configuration          = config;
 }
Exemplo n.º 11
0
 public MongoPushRepo(MongoConnectionSettings settings) : base(settings)
 {
 }
Exemplo n.º 12
0
 public MongoItemRepo(MongoConnectionSettings settings) : base(settings)
 {
 }
Exemplo n.º 13
0
 protected MongoDbContextBase(IConfiguration configuration)
 {
     Configuration           = configuration;
     MongoConnectionSettings = configuration.GetSection("MongoDbSettings").Get <MongoConnectionSettings>();
 }
Exemplo n.º 14
0
 public CustomWebApplicationFactory(MongoConnectionSettings mongoSettings)
 {
     this.mongoSettings = mongoSettings;
 }