public void BindByName_Tests() { { using (var connection = new TestDbConnection(new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"), new TestProfiler())) { using (var command = connection.CreateCommand() as AdoNetProfilerDbCommand) { command.BindByName = true; Assert.False(command.BindByName); } using (var command = connection.CreateCommand() as AdoNetProfilerDbCommand) { command.BindByName = false; Assert.False(command.BindByName); } } } #if NET46 || NET461 { using (var connection = new TestDbConnection(new OracleConnection(""), new TestProfiler())) { using (var command = connection.CreateCommand() as AdoNetProfilerDbCommand) { command.BindByName = true; Assert.True(command.BindByName); Assert.True(((OracleCommand)command.WrappedCommand).BindByName); } using (var command = connection.CreateCommand() as AdoNetProfilerDbCommand) { command.BindByName = false; Assert.False(command.BindByName); Assert.False(((OracleCommand)command.WrappedCommand).BindByName); } } } #endif }
public void ExecuteReader_Tests() { { using (var connection = new TestDbConnection(new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"), new TestProfiler())) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = @"Dummy Query"; command.CommandType = CommandType.Text; var reader = default(DbDataReader); Assert.Throws <SqlException>(() => reader = command.ExecuteReader()); Assert.Null(reader); Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnExecuteReaderStart))); Assert.False(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnReaderFinish))); Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnCommandError))); } } using (var connection = new TestDbConnection(new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"), new TestProfiler())) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = @"SELECT * FROM Orders"; command.CommandType = CommandType.Text; var count = 0; using (var reader = command.ExecuteReader()) { while (reader.Read()) { count++; } } Assert.Equal(830, count); Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnExecuteReaderStart))); Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnReaderFinish))); Assert.False(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnCommandError))); } } } }
public void ExecuteNonQuery_Tests() { { using (var connection = new TestDbConnection(new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"), new TestProfiler())) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = @"Dummy Query"; command.CommandType = CommandType.Text; int?result = null; Assert.Throws <SqlException>(() => result = command.ExecuteNonQuery()); Assert.Null(result); Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnExecuteNonQueryStart))); Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnExecuteNonQueryFinish))); Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnCommandError))); } } using (var connection = new TestDbConnection(new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"), new TestProfiler())) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = @"UPDATE Orders SET EmployeeID = @employeeId WHERE OrderId = @orderId"; command.CommandType = CommandType.Text; command.Parameters.Add(new SqlParameter("employeeId", 5)); command.Parameters.Add(new SqlParameter("orderId", 10248)); var result = command.ExecuteNonQuery(); Assert.Equal(1, result); Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnExecuteNonQueryStart))); Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnExecuteNonQueryFinish))); Assert.False(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnCommandError))); } } } }
public void ExecuteScalar_Tests() { { using (var connection = new TestDbConnection(new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"), new TestProfiler())) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = @"Dummy Query"; command.CommandType = CommandType.Text; object result = null; Assert.Throws <SqlException>(() => result = command.ExecuteScalar()); Assert.Null(result); Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnExecuteScalarStart))); Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnExecuteScalarFinish))); Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnCommandError))); } } using (var connection = new TestDbConnection(new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True"), new TestProfiler())) { connection.Open(); using (var command = connection.CreateCommand()) { command.CommandText = @"SELECT COUNT(1) FROM Orders"; command.CommandType = CommandType.Text; var result = command.ExecuteScalar(); Assert.Equal(830, result); Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnExecuteScalarStart))); Assert.True(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnExecuteScalarFinish))); Assert.False(connection.TestProfiler.PassedEvents.Contains(nameof(IAdoNetProfiler.OnCommandError))); } } } }