public void UpdateTest() { //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("UPDATE [dbo].[Categories]")) { return(0); } if (!c.CommandText.ContainsIgnoreCase("SET [CategoryName] = @CategoryName")) { return(0); } if (!c.CommandText.ContainsIgnoreCase("WHERE ([CategoryName] LIKE @CategoryName1)")) { return(0); } if (c.Parameters.Count != 2) { return(0); } return(1); }; using (var sql = new SqlQueryBuilderContext(ConnectionName)) { var update = sql.CreateUpdateQuery(); update.Table("Categories") .Set("CategoryName").By("Category U") .Where(c => c.Field("CategoryName").Contains("Category")); var v = sql.ExecuteNonQuery(update); Assert.IsTrue(v > 0); } } }
public void CreateUpdateQueryTest() { using (var sql = new SqlQueryBuilderContext(dummyConnectionString)) { var update = sql.CreateUpdateQuery(); update.Table("AA") .Set("A").By(1) .Set("B").By(2) .Set("C").By(3) .Where(f => f.Field("ID").Equals(10)); var priObj = new PrivateObject(sql); var result = priObj.Invoke("Build", update) as QueryInfo; Assert.IsNotNull(result); Assert.IsTrue(result.Query.Contains("UPDATE")); Assert.IsTrue(result.Query.Contains("SET")); Assert.IsTrue(result.Query.Contains("WHERE")); Assert.IsTrue(result.Parameters.Count == 4); Assert.IsTrue(sql.Build(update).Validate().Count == 0); } }