public Connection Get(IConfiguration configuration, string serviceName)
        {
            var info = serviceName == null
               ? configuration.GetSingletonServiceInfo <MongoDbServiceInfo>()
               : configuration.GetRequiredServiceInfo <MongoDbServiceInfo>(serviceName);

            var mongoConfig = new MongoDbConnectorOptions(configuration);
            var configurer  = new MongoDbProviderConfigurer();

            return(new Connection
            {
                ConnectionString = configurer.Configure(info, mongoConfig),
                Name = "MongoDb" + serviceName?.Insert(0, "-")
            });
        }
示例#2
0
        public void Configure_NoServiceInfo_ReturnsExpected()
        {
            MongoDbConnectorOptions config = new MongoDbConnectorOptions()
            {
                Server   = "localhost",
                Port     = 1234,
                Username = "******",
                Password = "******",
                Database = "database"
            };

            MongoDbProviderConfigurer configurer = new MongoDbProviderConfigurer();
            var opts = configurer.Configure(null, config);

            Assert.Equal("mongodb://*****:*****@localhost:1234/database", opts);
        }
        public void UpdateConfiguration_WithNullMongoDbServiceInfo_ReturnsExpected()
        {
            var configurer = new MongoDbProviderConfigurer();
            var config = new MongoDbConnectorOptions()
            {
                Server = "localhost",
                Port = 1234,
                Username = "******",
                Password = "******",
                Database = "database"
            };
            configurer.UpdateConfiguration(null, config);

            Assert.Equal("localhost", config.Server);
            Assert.Equal(1234, config.Port);
            Assert.Equal("username", config.Username);
            Assert.Equal("password", config.Password);
            Assert.Equal("database", config.Database);
            Assert.Null(config.ConnectionString);
        }
示例#4
0
        public void UpdateConfiguration_WithMongoDbServiceInfo_ReturnsExpected()
        {
            MongoDbProviderConfigurer configurer = new MongoDbProviderConfigurer();
            MongoDbConnectorOptions   config     = new MongoDbConnectorOptions()
            {
                Server   = "localhost",
                Port     = 1234,
                Username = "******",
                Password = "******",
                Database = "database"
            };
            MongoDbServiceInfo si = new MongoDbServiceInfo("MyId", "mongodb://*****:*****@192.168.0.90:27017/cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355");

            configurer.UpdateConfiguration(si, config);

            Assert.Equal("192.168.0.90", config.Server);
            Assert.Equal(27017, config.Port);
            Assert.Equal("Dd6O1BPXUHdrmzbP", config.Username);
            Assert.Equal("7E1LxXnlH2hhlPVt", config.Password);
            Assert.Equal("cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355", config.Database);
        }
示例#5
0
        public void Configure_ServiceInfoOveridesConfig_ReturnsExpected()
        {
            MongoDbConnectorOptions config = new MongoDbConnectorOptions()
            {
                Server   = "localhost",
                Port     = 1234,
                Username = "******",
                Password = "******",
                Database = "database"
            };

            MongoDbProviderConfigurer configurer = new MongoDbProviderConfigurer();
            MongoDbServiceInfo        si         = new MongoDbServiceInfo("MyId", "mongodb://*****:*****@192.168.0.90:27017/cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355");

            var opts = configurer.Configure(si, config);

            Assert.Equal("mongodb://*****:*****@192.168.0.90:27017/cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355", opts);
            Assert.DoesNotContain("localhost", opts);
            Assert.DoesNotContain("1234", opts);
            Assert.DoesNotContain("username", opts);
            Assert.DoesNotContain("password", opts);
            Assert.DoesNotContain("database", opts);
        }