Exemplo n.º 1
0
        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, "-")
            });
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
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);
        }
        public void Configure_ServiceInfoOveridesConfig_ReturnsExpected()
        {
            var config = new MongoDbConnectorOptions()
            {
                Server   = "localhost",
                Port     = 1234,
                Username = "******",
                Password = "******",
                Database = "database"
            };

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

            var connString = configurer.Configure(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);
            Assert.Equal("mongodb://*****:*****@192.168.0.90:27017/cf_b4f8d2fa_a3ea_4e3a_a0e8_2cd040790355", connString);
        }