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 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 async Task OpenAsync() { IConnectionFactory factory = new SqlServerConnectionFactory(); using (var connection = await factory.OpenAsync(AppState.ConnectionString)) { Assert.IsNotNull(connection); Assert.AreEqual(ConnectionState.Open, connection.State); connection.Close(); } }
public void Open() { IConnectionFactory factory = new SqlServerConnectionFactory(); using (var connection = factory.Open(AppState.ConnectionString)) { Assert.IsNotNull(connection); Assert.AreEqual(ConnectionState.Open, connection.State); connection.Close(); } }
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); } }
public void BeginTransaction_WithIsolationLevel() { ITransactionFactory transactionFactory = new TransactionFactory(); IConnectionFactory connectionFactory = new SqlServerConnectionFactory(); using (var connection = connectionFactory.Open(AppState.ConnectionString)) using (var transaction = transactionFactory.BeginTransaction(connection, IsolationLevel.Snapshot)) { Assert.IsNotNull(transaction); Assert.AreEqual(connection, transaction.Connection); Assert.AreEqual(IsolationLevel.Snapshot, transaction.IsolationLevel); transaction.Rollback(); } }
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); } }
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"]); } }