public void ExecuteUpdateWithOldValuesException () { SqlPoker sql = new SqlPoker (); sql.ConnectionString = "Data Source=fake\\SQLEXPRESS;Initial Catalog=Northwind;User ID=sa"; sql.ProviderName = "System.Data.SqlClient"; CustomSqlDataSourceView view = new CustomSqlDataSourceView (sql, "TestView", null); view.SelectCommandType = SqlDataSourceCommandType.Text; view.SelectCommand = "SELECT * FROM products WHERE ProductID = @ProductID;"; view.UpdateCommandType = SqlDataSourceCommandType.Text; view.UpdateCommand = "UPDATE Table1 SET UserName = @UserName WHERE UserId = @UserId"; view.OldValuesParameterFormatString = "origin_{0}"; view.ConflictDetection = ConflictOptions.CompareAllValues; view.Updating += new SqlDataSourceCommandEventHandler (view_Updating); view.UpdateParameters.Add (new Parameter ("UserName", TypeCode.String, "TestUser")); view.UpdateParameters.Add (new Parameter ("UserId", TypeCode.Int32, "1")); view.Update (null, null, null); }
public void ExecuteUpdate_KeysValuesAndOldValues_CompareAllValues () { SqlPoker sql = new SqlPoker (); sql.ConnectionString = "Data Source=fake\\SQLEXPRESS;Initial Catalog=Northwind;User ID=sa"; sql.ProviderName = "System.Data.SqlClient"; CustomSqlDataSourceView view = new CustomSqlDataSourceView (sql, "TestView", null); IDictionary keys; IDictionary values; IDictionary oldValues; InitializeView (view, out keys, out values, out oldValues); view.ConflictDetection = ConflictOptions.CompareAllValues; view.Update (keys, values, oldValues); Assert.IsNotNull (CustomEventParameterCollection, "ExecuteUpdate_KeysValuesAndOldValues_CompareAllValues"); string [] expectedParams = new string [] { "String:@ProductID=n_10", "String:@Name=n_ColorTV", "String:@Description=n_Beautifull", "String:@origin_ProductID=ov_10", "String:@origin_Name=ov_ColorTV", "String:@origin_Description=ov_Beautifull", }; string [] actualValues = PassedParameters.Split (new string [] { ", " }, StringSplitOptions.RemoveEmptyEntries); Assert.AreEqual (expectedParams.Length, actualValues.Length, "ExecuteDelete_KeysAndOldValues_CompareAllValues2 Params count"); ValidatePassedParams (expectedParams, actualValues, "ExecuteDelete_KeysAndOldValues_CompareAllValues2 expecte '{0}'"); }
public void ExecuteUpdateException () { SqlPoker sql = new SqlPoker (); sql.ConnectionString = "Data Source=fake\\SQLEXPRESS;Initial Catalog=Northwind;User ID=sa"; sql.ProviderName = "System.Data.SqlClient"; CustomSqlDataSourceView view = new CustomSqlDataSourceView (sql, "TestView", null); view.Update (null, null, null); }
public void ExecuteUpdateWithMargeParameters () { SqlPoker sql = new SqlPoker (); sql.ConnectionString = "Data Source=fake\\SQLEXPRESS;Initial Catalog=Northwind;User ID=sa"; sql.ProviderName = "System.Data.SqlClient"; CustomSqlDataSourceView view = new CustomSqlDataSourceView (sql, "TestView", null); view.SelectCommandType = SqlDataSourceCommandType.Text; view.SelectCommand = "SELECT * FROM products WHERE ProductID = @ProductID;"; view.UpdateCommandType = SqlDataSourceCommandType.Text; view.UpdateCommand = "UPDATE Table1 SET UserName = @UserName WHERE UserId = @UserId"; view.OldValuesParameterFormatString = "origin_{0}"; view.ConflictDetection = ConflictOptions.OverwriteChanges; view.Updating += new SqlDataSourceCommandEventHandler (view_Updating); view.UpdateParameters.Add (new Parameter ("UserName", TypeCode.String, "TestUser")); view.UpdateParameters.Add (new Parameter ("UserId", TypeCode.Int32, "1")); Hashtable value = new Hashtable (); value.Add ("UserLName", "TestLName"); view.Update (null, value, null); Assert.IsNotNull (CustomEventParameterCollection, "Update event not fired"); Assert.AreEqual (3, CustomEventParameterCollection.Count, "Parameter count"); Assert.AreEqual ("@UserName", CustomEventParameterCollection[0].ParameterName, "Parameter name#1"); Assert.AreEqual ("TestUser", CustomEventParameterCollection[0].Value, "Parameter value#1"); Assert.AreEqual ("@UserId", CustomEventParameterCollection[1].ParameterName, "Parameter name#2"); Assert.AreEqual (1, CustomEventParameterCollection[1].Value, "Parameter value#2"); Assert.AreEqual ("@UserLName", CustomEventParameterCollection[2].ParameterName, "Parameter name#3"); Assert.AreEqual ("TestLName", CustomEventParameterCollection[2].Value, "Parameter value#3"); }