public void TestSelectByID() { // Arrange var connection = new SqlConnection("server=(local);database=Northwind;integrated security=yes;"); var query = QueryBuilder .Select <Shipper>("dbo.Shippers", new SqlServerDatabaseNamingConvention()) .Where("ShipperID", ComparisonOperator.Equals, 1); var entity = default(Shipper); // Act connection.Open(); var command = connection.CreateCommand(); command.CommandText = query.ToString(); foreach (var condition in query.Where) { command.Parameters.Add(new SqlParameter(query.NamingConvention.GetParameterName(condition.Column), condition.Value)); } using (var dataReader = command.ExecuteReader()) { dataReader.Read(); entity = new Shipper { ShipperID = dataReader.GetInt32(0), CompanyName = dataReader.GetString(1), Phone = dataReader.GetString(2) }; } connection.Dispose(); // Assert Assert.False(entity == null); }
public void BuildDeleteCommandExtensionMethod() { using (var connection = new SqlConnection("server=(local);database=Northwind;integrated security=yes;")) { connection.Open(); var entity = new Shipper { ShipperID = 6 }; var command = QueryBuilder .DeleteFrom(entity, "dbo", "Shippers", "ShipperID") .CreateCommand(connection); File.WriteAllText(@"C:\Temp\CatFactory.Dapper\Queries\DeleteShipper.txt", command.CommandText); var affectedRows = command.ExecuteNonQuery(); Assert.True(affectedRows >= 0); } }