public static void CreateConnection_WhenInvoked_ReturnsConnectionInClosedState()
        {
            var factory = new OracleConnectionFactory("Data Source=127.0.0.1/orcl; User Id=SYSTEM; Password=oracle");

            using var connection = factory.CreateConnection();

            Assert.That(connection.State, Is.EqualTo(ConnectionState.Closed));
        }
Ejemplo n.º 2
0
        private static DbConnection BuildConnection(IConnectionSettings connectionSettings)
        {
            if (null == connectionSettings)
            {
                connectionSettings = ConnectionSettings;
            }

            switch (connectionSettings.ProviderInvariantName)
            {
            case DataConfiguration.SqlServerCompactProviderInvariantName:
            {
                var connectionFactory =
                    new SqlCeConnectionFactory(DataConfiguration.SqlServerCompactProviderInvariantName);
                return(connectionFactory.CreateConnection(connectionSettings.ConnectionString));
            }

            case DataConfiguration.SqlServerProviderInvariantName:
            {
                var connectionFactory = new SqlConnectionFactory();
                return(connectionFactory.CreateConnection(connectionSettings.ConnectionString));
            }

            case DataConfiguration.MySqlProviderInvariantName:
            {
                var connectionFactory = new MySqlConnectionFactory();
                return(connectionFactory.CreateConnection(connectionSettings.ConnectionString));
            }

            case DataConfiguration.PostgreSqlProviderInvariantName:
            {
                var connectionFactory = new NpgsqlConnectionFactory();
                return(connectionFactory.CreateConnection(connectionSettings.ConnectionString));
            }

            case DataConfiguration.OracleDBProviderInvariantName:
            {
                var connectionFactory = new OracleConnectionFactory();
                return(connectionFactory.CreateConnection(connectionSettings.ConnectionString));
            }

            default:
                throw new InvalidOperationException("connectionSettings.ProviderInvariantName == " +
                                                    connectionSettings.ProviderInvariantName);
            }
        }