Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommonDbms"/> class.
        /// </summary>
        /// <param name="invariantProviderName">Name of the invariant provider.</param>
        /// <param name="connectionString">The connection string.</param>
        /// <param name="connectionStringKey">The connection string key.</param>
        /// <param name="encryptionMetaJson">The encryption meta json.</param>
        /// <exception cref="System.ArgumentNullException">
        /// invariantProviderName;The expected provider name is not here.
        /// or
        /// connectionString;The expected connection string is not here.
        /// </exception>
        public CommonDbms(string invariantProviderName, string connectionString, string connectionStringKey, string encryptionMetaJson)
        {
            if (string.IsNullOrEmpty(invariantProviderName))
            {
                throw new ArgumentNullException("invariantProviderName", "The expected provider name is not here.");
            }
            if (string.IsNullOrEmpty(connectionString))
            {
                throw new ArgumentNullException("connectionString", "The expected connection string is not here.");
            }

            this._invariantProviderName = invariantProviderName;
            this._factory = CommonDbmsUtility.GetProviderFactory(this._invariantProviderName);

            if (!string.IsNullOrEmpty(encryptionMetaJson))
            {
                if (File.Exists(encryptionMetaJson))
                {
                    encryptionMetaJson = File.ReadAllText(encryptionMetaJson);
                }
                var encryptionMeta = JsonConvert.DeserializeObject <EncryptionMetadata>(encryptionMetaJson);
                connectionString = (!string.IsNullOrEmpty(connectionStringKey)) ?
                                   encryptionMeta.GetConnectionStringWithDecryptedValue(connectionString, connectionStringKey)
                    :
                                   encryptionMeta.Decrypt(connectionString);
            }

            this._connection = CommonDbmsUtility.GetConnection(this._factory, connectionString);
            this._connection.Open();
            this.OnConnectionOpen(this._connection);
        }
Exemplo n.º 2
0
        public static void ShouldOpenConnection(this TestContext context, string dbFolder)
        {
            var invariantProviderName = context.Properties["invariantProviderName"].ToString();

            var connectionString = context.ShouldGetConnectionString(dbFolder);

            using (var connection = CommonDbmsUtility.GetConnection(invariantProviderName, connectionString))
            {
                connection.Open();
                Assert.AreEqual(connection.State, ConnectionState.Open, "The expected Open Connection State is not here.");
            }
        }