Example #1
0
		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);
		}
Example #2
0
		public void ExecuteDeleteWithOldValuesException ()
		{
			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.DeleteCommandType = SqlDataSourceCommandType.Text;
			view.DeleteCommand = "DELETE * FROM products WHERE ProductID = @ProductID;";
			view.DeleteParameters.Add (new Parameter ("ProductId", TypeCode.Int32, "15"));
			view.OldValuesParameterFormatString = "origin_{0}";
			view.ConflictDetection = ConflictOptions.CompareAllValues;
			view.Deleting += new SqlDataSourceCommandEventHandler (view_Deleting);
			Hashtable oldvalue = new Hashtable ();
			oldvalue.Add ("ProductID", 10);
			view.Delete (null, null);
		}
Example #3
0
		public void ExecuteDeleteException ()
		{
			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.Delete (null, null);
		}
Example #4
0
		public void ExecuteInsertException ()
		{
			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.Insert (null);
		}
Example #5
0
		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");
		}
Example #6
0
		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}'");
		}
Example #7
0
		private void InitializeView (CustomSqlDataSourceView view, out IDictionary keys, out IDictionary values, out IDictionary oldValues) 
		{
			view.SelectCommandType = SqlDataSourceCommandType.Text;
			view.SelectCommand = "SELECT * FROM products WHERE ProductID = @ProductID;";
			view.SelectParameters.Add (new Parameter ("ProductID", TypeCode.String, "p_10"));
			view.Selecting += new SqlDataSourceSelectingEventHandler (view_Selecting);

			view.DeleteCommandType = SqlDataSourceCommandType.Text;
			view.DeleteCommand = "DELETE * FROM products WHERE ProductID = @ProductID;";
			view.DeleteParameters.Add (new Parameter ("ProductID", TypeCode.String, "p_10"));
			view.Deleting += new SqlDataSourceCommandEventHandler (view_Deleting);

			view.InsertCommandType = SqlDataSourceCommandType.Text;
			view.InsertCommand = "INSERT INTO products (ProductID, Name, Description) VALUES (@ProductID, @Name, @Description)";
			view.InsertParameters.Add (new Parameter ("ProductID", TypeCode.String, "p_15"));
			view.InsertParameters.Add (new Parameter ("Name", TypeCode.String, "p_NewProduct"));
			view.InsertParameters.Add (new Parameter ("Description", TypeCode.String, "p_Description"));
			view.Inserting += new SqlDataSourceCommandEventHandler (view_Inserting);

			view.UpdateCommandType = SqlDataSourceCommandType.Text;
			view.UpdateCommand = "UPDATE products SET Name = @Name, Description = @Description WHERE ProductID = @ProductID";
			view.UpdateParameters.Add (new Parameter ("ProductID", TypeCode.String, "p_15"));
			view.UpdateParameters.Add (new Parameter ("Name", TypeCode.String, "p_UpdatedProduct"));
			view.UpdateParameters.Add (new Parameter ("Description", TypeCode.String, "p_UpdatedDescription"));
			view.Updating += new SqlDataSourceCommandEventHandler (view_Updating);

			view.OldValuesParameterFormatString = "origin_{0}";

			keys = new Hashtable ();
			values = new Hashtable ();
			oldValues = new Hashtable ();

			keys.Add ("ProductID", "k_10");

			values.Add ("ProductID", "n_10");
			values.Add ("Name", "n_ColorTV");
			values.Add ("Description", "n_Beautifull");

			oldValues.Add ("ProductID", "ov_10");
			oldValues.Add ("Name", "ov_ColorTV");
			oldValues.Add ("Description", "ov_Beautifull");			
		}
Example #8
0
		public void ExecuteDelete_KeysAndOldValues_OverwriteChanges () 
		{
			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.OverwriteChanges;

			view.Delete (keys, oldValues);

			Assert.IsNotNull (CustomEventParameterCollection, "KeysAndOldValues_OverwriteChanges");
			Assert.AreEqual ("String:@origin_ProductID=k_10", PassedParameters, "KeysAndOldValues_OverwriteChanges Values");
		}
Example #9
0
		public void ExecuteDeleteWithMergedValues ()
		{
			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.DeleteCommandType = SqlDataSourceCommandType.Text;
			view.DeleteCommand = "DELETE * FROM products WHERE ProductID = @ProductID;";
			view.DeleteParameters.Add (new Parameter ("ProductId", TypeCode.Int32, "15"));
			view.OldValuesParameterFormatString = "origin_{0}";
			view.Deleting += new SqlDataSourceCommandEventHandler (view_Deleting);
			Hashtable value = new Hashtable ();
			value.Add ("Desc", "Description");
			view.Delete (value, null);
			Assert.IsNotNull (CustomEventParameterCollection, "Delete event not fired");
			Assert.AreEqual (2, CustomEventParameterCollection.Count, "Parameter count");
			Assert.AreEqual ("@ProductId", CustomEventParameterCollection[0].ParameterName, "Parameter name#1");
			Assert.AreEqual (15, CustomEventParameterCollection[0].Value, "Parameter value#1");
			Assert.AreEqual ("@origin_Desc", CustomEventParameterCollection[1].ParameterName, "Parameter name#2");
			Assert.AreEqual ("Description", CustomEventParameterCollection[1].Value, "Parameter value#2");
		}
Example #10
0
		public void ExecuteInsertWithCollection ()
		{
			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.InsertCommandType = SqlDataSourceCommandType.Text;
			view.InsertCommand = "INSERT INTO products (UserId, UserName) VALUES ({0},{1})";
			view.InsertParameters.Add (new Parameter ("UserId", TypeCode.Int32, "15"));
			view.InsertParameters.Add (new Parameter ("UserName", TypeCode.String, "newuser"));
			view.OldValuesParameterFormatString = "origin_{0}";
			view.Inserting += new SqlDataSourceCommandEventHandler (view_Inserting);
			Hashtable value = new Hashtable ();
			value.Add ("Description", "TestDescription");
			view.Insert (value);
			Assert.IsNotNull (CustomEventParameterCollection, "Insert event not fired");
			Assert.AreEqual (3, CustomEventParameterCollection.Count, "Parameter count");
			Assert.AreEqual ("@UserId", CustomEventParameterCollection[0].ParameterName, "Parameter name#1");
			Assert.AreEqual (15, CustomEventParameterCollection[0].Value, "Parameter value#1");
			Assert.AreEqual ("@UserName", CustomEventParameterCollection[1].ParameterName, "Parameter name#2");
			Assert.AreEqual ("newuser", CustomEventParameterCollection[1].Value, "Parameter value#2");
			Assert.AreEqual ("@Description", CustomEventParameterCollection[2].ParameterName, "Parameter name#3");
			Assert.AreEqual ("TestDescription", CustomEventParameterCollection[2].Value, "Parameter value#3");
		}
Example #11
0
		public void ExecuteSelect2 () 
		{
			SqlPoker sql = new SqlPoker ();
			sql.ConnectionString = "Data Source=fake\\SQLEXPRESS;Initial Catalog=Northwind;User ID=sa";
			sql.ProviderName = "System.Data.SqlClient";
			sql.DataSourceMode = SqlDataSourceMode.DataReader;
			CustomSqlDataSourceView view = new CustomSqlDataSourceView (sql, "TestView", null);
			view.SelectCommandType = SqlDataSourceCommandType.Text;
			view.SelectCommand = "SELECT * FROM products WHERE ProductID = @ProductID;";
			view.OldValuesParameterFormatString = "origin_{0}";

			view.SelectParameters.Add (new Parameter ("ProductID", TypeCode.Int32, "10"));
			view.Selecting += new SqlDataSourceSelectingEventHandler (view_Selecting);
			view.Select (new DataSourceSelectArguments ());
			Assert.IsNotNull (CustomEventParameterCollection, "Select event not fired");
			Assert.AreEqual (1, CustomEventParameterCollection.Count, "Parameter count");
			Assert.AreEqual ("@ProductID", CustomEventParameterCollection [0].ParameterName, "Parameter name");
			Assert.AreEqual (10, CustomEventParameterCollection [0].Value, "Parameter value");
		}