Exemple #1
0
        public void SqlServerConnectionFactory_ReadProcedure()
        {
            var parameterFactory  = new SqlServerParameterFactory();
            var adapterFactory    = new SqlServerDataAdapterFactory();
            var connectionFactory = new SqlServerConnectionFactory();

            // on using transactions
            // https://stackoverflow.com/questions/6418992/is-it-a-better-practice-to-explicitly-call-transaction-rollback-or-let-an-except
            using (var connection = connectionFactory.Open(AppState.ConnectionString))
                using (var transaction = connection.BeginTransaction())
                    using (var proc = new ReadProcedure(connection, parameterFactory, adapterFactory))
                    {
                        Assert.IsNotNull(proc);
                        var getParams = new Get
                        {
                            Id = 1
                        };
                        var readResult = proc.Read(getParams, transaction);

                        Assert.AreEqual(-1, readResult.ReturnValue);
                        Assert.AreEqual(1, readResult.DataSet.Tables.Count);
                        Assert.AreEqual(1, readResult.DataSet.Tables[0].Rows.Count);
                        Assert.AreEqual(1, getParams.Status);
                        Assert.AreEqual(1, readResult.DataSet.Tables[0].Rows[0]["Id"]);
                        Assert.AreEqual("one", readResult.DataSet.Tables[0].Rows[0]["Name"]);

                        transaction.Commit();
                    }
        }
Exemple #2
0
        public void SqlServerConnectionFactory_ReadProcedure_GetObjects()
        {
            var parameterFactory  = new SqlServerParameterFactory();
            var adapterFactory    = new SqlServerDataAdapterFactory();
            var connectionFactory = new SqlServerConnectionFactory();

            using (var connection = connectionFactory.Open(AppState.ConnectionString))
                using (var transaction = connection.BeginTransaction())
                    using (var proc = new ReadProcedure(connection, parameterFactory, adapterFactory))
                    {
                        var getParams = new Get
                        {
                            Id = 1
                        };
                        var readResult = proc.Read(getParams, transaction);
                        var tests      = readResult.DataSet.Tables[0].Rows.ToArray <Test>();
                        Assert.IsNotNull(tests);
                        Assert.AreEqual(1, tests.Length);
                        var test = tests.FirstOrDefault();
                        Assert.IsNotNull(test);
                        Assert.AreEqual(1, test.Id);
                        Assert.AreEqual("one", test.Name);

                        transaction.Commit();
                    }
        }
        public SqlServerDataComponentFactory(string connectionString) : base()
        {
            _connectionFactory =
                String.IsNullOrEmpty(connectionString) ?
                new SqlServerConnectionFactory() :
                new SqlServerConnectionFactory(connectionString);

            _transactionFactory = new TransactionFactory();
            _dataAdapterFactory = new SqlServerDataAdapterFactory();
            _parameterFactory   = new SqlServerParameterFactory();
        }
        public SqlServerDataComponentFactory(RetryOptions retryOptions, string connectionString) : base()
        {
            _connectionFactory =
                String.IsNullOrEmpty(connectionString) ?
                new SqlServerConnectionFactoryWithRetry(retryOptions) :
                new SqlServerConnectionFactoryWithRetry(retryOptions, connectionString);

            _transactionFactory = new SqlServerTransactionFactoryWithRetry(retryOptions);
            _dataAdapterFactory = new SqlServerDataAdapterFactory();
            _parameterFactory   = new SqlServerParameterFactory();
        }
        public SqlServerDataComponentFactory(SqlServerTransientRetryPolicy retryPolicy, IConnectionStringFactory connectionStringFactory) : base()
        {
            _connectionFactory =
                connectionStringFactory == null ?
                new SqlServerConnectionFactoryWithRetry(retryPolicy) :
                new SqlServerConnectionFactoryWithRetry(retryPolicy, connectionStringFactory);

            _transactionFactory = new SqlServerTransactionFactoryWithRetry(retryPolicy);
            _dataAdapterFactory = new SqlServerDataAdapterFactory();
            _parameterFactory   = new SqlServerParameterFactory();
        }
        public SqlServerDataComponentFactory(IConnectionStringFactory connectionStringFactory) : base()
        {
            _connectionFactory =
                connectionStringFactory == null ?
                new SqlServerConnectionFactory() :
                new SqlServerConnectionFactory(connectionStringFactory);

            _transactionFactory = new TransactionFactory();
            _dataAdapterFactory = new SqlServerDataAdapterFactory();
            _parameterFactory   = new SqlServerParameterFactory();
        }
        public SqlServerDataComponentFactory(SqlServerTransientRetryPolicy retryPolicy, string connectionString) : base()
        {
            _connectionFactory =
                string.IsNullOrEmpty(connectionString) ?
                new SqlServerConnectionFactoryWithRetry(retryPolicy) :
                new SqlServerConnectionFactoryWithRetry(retryPolicy, connectionString);

            _transactionFactory = new SqlServerTransactionFactoryWithRetry(retryPolicy);
            _dataAdapterFactory = new SqlServerDataAdapterFactory();
            _parameterFactory   = new SqlServerParameterFactory();
        }
        public void CreateDataAdapter()
        {
            IDataAdapterFactory dataAdapterFactory = new SqlServerDataAdapterFactory();
            IConnectionFactory  connectionFactory  = new SqlServerConnectionFactory();

            using (var connection = connectionFactory.Open(AppState.ConnectionString))
                using (var command = connection.CreateCommand())
                    using (var dataAdapter = dataAdapterFactory.CreateDataAdapter(command))
                    {
                        Assert.IsNotNull(dataAdapter);
                        Assert.AreEqual(command, dataAdapter.SelectCommand);
                    }
        }
Exemple #9
0
        public void Command_CreateParamsFromSqlText()
        {
            //string sql = "select * from [tb] where [tb].[col] = @ParamOne";

            var adapterFactory    = new SqlServerDataAdapterFactory();
            var connectionFactory = new SqlServerConnectionFactory();

            using (var connection = connectionFactory.Open(AppState.ConnectionString))
                using (var command = connection.CreateCommand())
                    using (var adapter = adapterFactory.CreateDataAdapter(command))
                    {
                        Assert.IsNotNull(adapter);
                        Assert.AreEqual(command, adapter.SelectCommand);
                    }
        }
Exemple #10
0
        public void SqlServerConnectionFactory_ReadProcedure()
        {
            var parameterFactory  = new SqlServerParameterFactory();
            var adapterFactory    = new SqlServerDataAdapterFactory();
            var connectionFactory = new SqlServerConnectionFactory();

            using (var connection = connectionFactory.Open(AppState.ConnectionString))
                using (var proc = new ReadProcedure(connection, parameterFactory, adapterFactory))
                {
                    Assert.IsNotNull(proc);
                    var getParams  = new Get();
                    var readResult = proc.Read(getParams);

                    Assert.AreEqual(99, readResult.ReturnValue);
                    Assert.AreEqual(1, readResult.DataSet.Tables.Count);
                    Assert.AreEqual(1, readResult.DataSet.Tables[0].Rows.Count);
                    Assert.AreEqual(33, getParams.Out);
                    Assert.AreEqual(1, readResult.DataSet.Tables[0].Rows[0]["TestId"]);
                    Assert.AreEqual("one", readResult.DataSet.Tables[0].Rows[0]["Name"]);
                }
        }