public void CreateInsertQueryTest() { using (var sql = new SqlQueryBuilderContext(dummyConnectionString)) { var insert = sql.CreateInsertQuery(); insert.Into("AA") .Values("F1").By(1) .Values("F2").By(2) .Values("F3").By(3); var priObj = new PrivateObject(sql); var result = priObj.Invoke("Build", insert) as QueryInfo; Assert.IsNotNull(result); Assert.IsTrue(result.Query.Contains("INSERT INTO")); Assert.IsTrue(result.Query.Contains("VALUES")); Assert.IsTrue(result.Parameters.Count == 3); Assert.IsTrue(sql.Build(insert).Validate().Count == 0); } }
public void InsertTest() { using (ShimsContext.Create()) { //Verify the ExecuteNonQuery will call SqlCommand.ExecuteNonQuery System.Data.SqlClient.Fakes.ShimSqlCommand.AllInstances.ExecuteNonQuery = c => { if (!c.CommandText.StartsWithIgnoreCase("INSERT INTO")) { return(0); } if (!c.CommandText.ContainsIgnoreCase("[dbo].[Categories]([CategoryName])")) { return(0); } if (!c.CommandText.ContainsIgnoreCase("VALUES (@CategoryName)")) { return(0); } if (c.Parameters.Count != 1) { return(0); } return(1); }; using (var sql = new SqlQueryBuilderContext(ConnectionName)) { var insert = sql.CreateInsertQuery(); insert.Into("Categories") .Values("CategoryName").By("Category 1"); var v = sql.ExecuteNonQuery(insert); Assert.IsTrue(v > 0); } } }