예제 #1
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();
                    }
        }
예제 #2
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();
                    }
        }
        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(string connectionString) : base()
        {
            _connectionFactory =
                String.IsNullOrEmpty(connectionString) ?
                new SqlServerConnectionFactory() :
                new SqlServerConnectionFactory(connectionString);

            _transactionFactory = new TransactionFactory();
            _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();
        }
예제 #8
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"]);
                }
        }