public void CreateDeleteQueryTest() { using (var sql = new SqlQueryBuilderContext(dummyConnectionString)) { var delete = sql.CreateDeleteQuery(); delete.From("AA") .Where(f => f.Field("ID").Equals(123)); var priObj = new PrivateObject(sql); var result = priObj.Invoke("Build", delete) as QueryInfo; Assert.IsNotNull(result); Assert.IsTrue(result.Query.Contains("DELETE")); Assert.IsTrue(result.Query.Contains("FROM")); Assert.IsTrue(result.Query.Contains("WHERE")); Assert.IsTrue(result.Parameters.Count == 1); Assert.IsTrue(sql.Build(delete).Validate().Count == 0); } }
public void DeleteTest() { //Insert first InsertTest(); using (ShimsContext.Create()) { //Verify the ExecuteNonQuery will call SqlCommand.ExecuteNonQuery System.Data.SqlClient.Fakes.ShimSqlCommand.AllInstances.ExecuteNonQuery = c => { if (!c.CommandText.StartsWithIgnoreCase("DELETE FROM [dbo].[Categories]")) { return(0); } if (!c.CommandText.ContainsIgnoreCase("WHERE ([CategoryName] LIKE @CategoryName)")) { return(0); } if (c.Parameters.Count != 1) { return(0); } return(1); }; using (var sql = new SqlQueryBuilderContext(ConnectionName)) { var delete = sql.CreateDeleteQuery(); delete.From("Categories") .Where(c => c.Field("CategoryName").Contains("Category")); var v = sql.ExecuteNonQuery(delete); Assert.IsTrue(v > 0); } } }