Exemple #1
0
        public void Configure_ServiceInfoOveridesConfig_ReturnsExpected()
        {
            var config = new CosmosDbConnectorOptions()
            {
                Host         = "https://someHost:443",
                MasterKey    = "masterKey",
                ReadOnlyKey  = "readOnlyKey",
                DatabaseId   = "databaseId",
                DatabaseLink = "databaseLink"
            };

            var configurer = new CosmosDbProviderConfigurer();
            var si         = new CosmosDbServiceInfo("MyId")
            {
                Host         = "https://u332d11658f3.documents.azure.com:443/",
                MasterKey    = "lXYMGIE4mYITjXvHwQjkh0U07lwF513NdbTfeyGndeqjVXzwKQ3ZalKXQNYeIZovoyl57IY1J0KnJUH36EPufA==",
                ReadOnlyKey  = "hy5XZOeVnBeMmbB9FGcD54tttGKExad9XkGhn5Esc4jAM60OF2U7TcCXgffqBtBRuPAp0uFqKvz1l13OX8auPw==",
                DatabaseId   = "u33ba24fd208",
                DatabaseLink = "cbs/sTB+AA==/"
            };

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

            Assert.Equal("https://u332d11658f3.documents.azure.com:443/", config.Host);
            Assert.Equal("lXYMGIE4mYITjXvHwQjkh0U07lwF513NdbTfeyGndeqjVXzwKQ3ZalKXQNYeIZovoyl57IY1J0KnJUH36EPufA==", config.MasterKey);
            Assert.Equal("hy5XZOeVnBeMmbB9FGcD54tttGKExad9XkGhn5Esc4jAM60OF2U7TcCXgffqBtBRuPAp0uFqKvz1l13OX8auPw==", config.ReadOnlyKey);
            Assert.Equal("u33ba24fd208", config.DatabaseId);
            Assert.Equal("cbs/sTB+AA==/", config.DatabaseLink);
            Assert.Equal("AccountEndpoint=https://u332d11658f3.documents.azure.com:443/;AccountKey=lXYMGIE4mYITjXvHwQjkh0U07lwF513NdbTfeyGndeqjVXzwKQ3ZalKXQNYeIZovoyl57IY1J0KnJUH36EPufA==;", connString);
        }
Exemple #2
0
        public void Constructor_ThrowsIfConfigNull()
        {
            CosmosDbConnectorOptions config = null;
            CosmosDbServiceInfo      si     = null;

            var ex = Assert.Throws <ArgumentNullException>(() => new CosmosDbConnectorFactory(si, config, typeof(CosmosClient)));

            Assert.Contains(nameof(config), ex.Message);
        }
Exemple #3
0
        private Connection GetConnection(CosmosDbServiceInfo info, IConfiguration configuration)
        {
            var cosmosConfig = new CosmosDbConnectorOptions(configuration);
            var configurer   = new CosmosDbProviderConfigurer();
            var conn         = new Connection(configurer.Configure(info, cosmosConfig), "CosmosDb", info);

            conn.Properties.Add("DatabaseId", cosmosConfig.DatabaseId);
            conn.Properties.Add("DatabaseLink", cosmosConfig.DatabaseLink);

            return(conn);
        }
        public void Constructor_ThrowsIfConfigNull_v3()
        {
            // Arrange
            CosmosDbConnectorOptions config = null;

            CosmosDbServiceInfo si = null;

            // Act and Assert
            var ex = Assert.Throws <ArgumentNullException>(() => new CosmosDbConnectorFactory(si, config, typeof(Microsoft.Azure.Cosmos.CosmosClient)));

            Assert.Contains(nameof(config), ex.Message);
        }
Exemple #5
0
        public void UpdateConfiguration(CosmosDbServiceInfo si, CosmosDbConnectorOptions configuration)
        {
            if (si == null)
            {
                return;
            }

            configuration.Host         = si.Host;
            configuration.MasterKey    = si.MasterKey;
            configuration.ReadOnlyKey  = si.ReadOnlyKey;
            configuration.DatabaseId   = si.DatabaseId;
            configuration.DatabaseLink = si.DatabaseLink;
        }
        public void Create_ReturnsCosmosDbConnection()
        {
            var si = new CosmosDbServiceInfo("MyId")
            {
                Host         = "https://someHost:443/",
                MasterKey    = "lXYMGIE4mYITjXaHwQjkh0U07lwF513NdbTfeyGndeqjVXzwKQ3ZalKXQNYeIZovoyl57IY1J0KnJUH36EPufA==",
                ReadOnlyKey  = "hy5XZOdVnBeMmbB9FGcD54tttGKExad9XkGhn5Esc4jAM60OF2U7TcCXgffqBtBRuPAp0uFqKvz1l13OX8auPw==",
                DatabaseId   = "databaseId",
                DatabaseLink = "databaseLink"
            };

            var factory    = new CosmosDbConnectorFactory(si, new CosmosDbConnectorOptions(), typeof(CosmosClient));
            var connection = factory.Create(null);

            Assert.NotNull(connection);
        }
        public void ConnectionTypeLocatorFindsTypeFromServiceInfo()
        {
            var cosmosInfo   = new CosmosDbServiceInfo("id");
            var mongoInfo    = new MongoDbServiceInfo("id", "mongodb://host");
            var mysqlInfo    = new MySqlServiceInfo("id", "mysql://host");
            var oracleInfo   = new OracleServiceInfo("id", "oracle://host");
            var postgresInfo = new PostgresServiceInfo("id", "postgres://host");
            var rabbitMqInfo = new RabbitMQServiceInfo("id", "rabbitmq://host");
            var redisInfo    = new RedisServiceInfo("id", "redis://host");
            var sqlInfo      = new SqlServerServiceInfo("id", "sqlserver://host");
            var manager      = new ConnectionStringManager(new ConfigurationBuilder().Build());

            Assert.StartsWith("CosmosDb", manager.GetFromServiceInfo(cosmosInfo).Name);
            Assert.StartsWith("MongoDb", manager.GetFromServiceInfo(mongoInfo).Name);
            Assert.StartsWith("MySql", manager.GetFromServiceInfo(mysqlInfo).Name);
            Assert.StartsWith("Oracle", manager.GetFromServiceInfo(oracleInfo).Name);
            Assert.StartsWith("Postgres", manager.GetFromServiceInfo(postgresInfo).Name);
            Assert.StartsWith("RabbitMQ", manager.GetFromServiceInfo(rabbitMqInfo).Name);
            Assert.StartsWith("Redis", manager.GetFromServiceInfo(redisInfo).Name);
            Assert.StartsWith("SqlServer", manager.GetFromServiceInfo(sqlInfo).Name);
        }
 public CosmosDbConnectorFactory(CosmosDbServiceInfo sinfo, CosmosDbConnectorOptions config, Type type)
 {
     _info         = sinfo;
     _config       = config ?? throw new ArgumentNullException(nameof(config));
     ConnectorType = type;
 }
Exemple #9
0
 public string Configure(CosmosDbServiceInfo si, CosmosDbConnectorOptions configuration)
 {
     UpdateConfiguration(si, configuration);
     return(configuration.ToString());
 }