示例#1
0
		public void Defaults ()
		{
			SqlDataSource ds = new SqlDataSource ();
			SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);

			Assert.IsTrue (sql.CancelSelectOnNullParameter, "A1");
			Assert.IsFalse (sql.CanDelete,"A2");
			Assert.IsFalse (sql.CanInsert,"A3");
			Assert.IsFalse (sql.CanPage,"A4");
			Assert.IsFalse (sql.CanRetrieveTotalRowCount,"A5");
			Assert.IsTrue (sql.CanSort,"A6");
			Assert.IsFalse (sql.CanUpdate,"A7");
			Assert.AreEqual (ConflictOptions.OverwriteChanges, sql.ConflictDetection, "A8");
			Assert.AreEqual ("", sql.DeleteCommand, "A9");
			Assert.AreEqual (SqlDataSourceCommandType.Text, sql.DeleteCommandType, "A10");
			Assert.IsNotNull (sql.DeleteParameters, "A11");
			Assert.AreEqual (0, sql.DeleteParameters.Count, "A12");
			Assert.AreEqual ("", sql.FilterExpression, "A13");
			Assert.IsNotNull (sql.FilterParameters, "A14");
			Assert.AreEqual (0, sql.FilterParameters.Count, "A15");
			Assert.AreEqual ("", sql.InsertCommand, "A16");
			Assert.AreEqual (SqlDataSourceCommandType.Text, sql.InsertCommandType, "A17");
			Assert.IsNotNull (sql.InsertParameters, "A18");
			Assert.AreEqual (0, sql.InsertParameters.Count, "A19");
			Assert.AreEqual ("{0}", sql.OldValuesParameterFormatString, "A20");
			Assert.AreEqual ("", sql.SelectCommand, "A21");
			Assert.AreEqual (SqlDataSourceCommandType.Text, sql.SelectCommandType, "A22");
			Assert.IsNotNull (sql.SelectParameters, "A23");
			Assert.AreEqual (0, sql.SelectParameters.Count, "A24");
			Assert.AreEqual ("", sql.SortParameterName, "A25");
			Assert.AreEqual ("", sql.UpdateCommand, "A26");
			Assert.AreEqual (SqlDataSourceCommandType.Text, sql.UpdateCommandType, "A27");
			Assert.IsNotNull (sql.UpdateParameters, "A28");
			Assert.AreEqual (0, sql.UpdateParameters.Count, "A29");
		}
        public void ParametersAndViewChangedEvent_MatchInsert()
        {
            Hashtable    keys       = null;
            Hashtable    old_values = null;
            Hashtable    new_values = null;
            SqlViewPoker view       = InitializeView(InitViewType.MatchParamsToValues, ConflictOptions.OverwriteChanges, out keys, out old_values, out new_values);

            view.Insert(new_values);

            Assert.IsNotNull(eventsCalled, "Events not raized");
            Assert.AreEqual(3, eventsCalled.Count, "Events Count");
            Assert.AreEqual("InsertParameters_ParametersChanged", eventsCalled [0], "InsertParameters_ParametersChanged");
            Assert.AreEqual("view_Inserting", eventsCalled [1], "view_Inserting");
            string [] expectedParams = new string []
            {
                "String:@ID=n_1001"
            };
            string [] actualValues = ((string)eventsCalled [2]).Split(new string [] { ", " }, StringSplitOptions.RemoveEmptyEntries);
            Assert.AreEqual(expectedParams.Length, actualValues.Length, "ParametersAndViewChangedEvent_MatchInsert Params count");
            ValidatePassedParams(expectedParams, actualValues, "ParametersAndViewChangedEvent_MatchInsert expecte '{0}'");
        }
        public void OldValuesParameterFormatString()
        {
            SqlDataSource ds = new SqlDataSource();

            Assert.AreEqual("{0}", ds.OldValuesParameterFormatString, "A1");

            ds.OldValuesParameterFormatString = "hi {0}";

            SqlViewPoker sql = new SqlViewPoker(ds, "DefaultView", null);

            Assert.AreEqual("{0}", sql.OldValuesParameterFormatString, "A2");

            ds.OldValuesParameterFormatString = "hi {0}";

            Assert.AreEqual("{0}", sql.OldValuesParameterFormatString, "A3");

            ds.OldValuesParameterFormatString  = "{0}";
            sql.OldValuesParameterFormatString = "hi {0}";

            Assert.AreEqual("{0}", ds.OldValuesParameterFormatString, "A4");
        }
        public void SelectCommand_DataSourceViewChanged2()
        {
            SqlDataSource ds   = new SqlDataSource();
            SqlViewPoker  view = new SqlViewPoker(ds, "DefaultView", null);

            view.DataSourceViewChanged += new EventHandler(view_DataSourceViewChanged);

            Assert.AreEqual("", view.SelectCommand);
            view.SelectCommand = null;
            Assert.AreEqual(1, eventsCalled.Count);
            Assert.AreEqual("view_DataSourceViewChanged", eventsCalled [0]);
            Assert.AreEqual("", view.SelectCommand);

            view.SelectCommand = null;
            Assert.AreEqual(2, eventsCalled.Count);
            Assert.AreEqual("view_DataSourceViewChanged", eventsCalled [1]);
            Assert.AreEqual("", view.SelectCommand);

            view.SelectCommand = "";
            Assert.AreEqual(2, eventsCalled.Count);
        }
示例#5
0
        public void ParametersAndViewChangedEvent_Select()
        {
            Hashtable    keys       = null;
            Hashtable    old_values = null;
            Hashtable    new_values = null;
            SqlViewPoker view       = InitializeView(InitViewType.MatchParamsToValues, ConflictOptions.OverwriteChanges, out keys, out old_values, out new_values);

            view.Select(DataSourceSelectArguments.Empty);

            Assert.IsNotNull(eventsCalled, "Events not raized");
            Assert.AreEqual(5, eventsCalled.Count, "Events Count");
            Assert.AreEqual("view_DataSourceViewChanged", eventsCalled [0], "view_DataSourceViewChanged");
            Assert.AreEqual("SelectParameters_ParametersChanged", eventsCalled [1], "SelectParameters_ParametersChanged");
            Assert.AreEqual("System.Web.UI.DataSourceSelectArguments", eventsCalled [2], "DataSourceSelectArguments");
            Assert.AreEqual("view_Selecting", eventsCalled [3], "view_Selecting");
            string [] expectedParams = new string []
            {
                "String:@ID=p_ValueSelect1"
            };
            string [] actualValues = ((string)eventsCalled [4]).Split(new string [] { ", " }, StringSplitOptions.RemoveEmptyEntries);
            Assert.AreEqual(expectedParams.Length, actualValues.Length, "ParametersAndViewChangedEvent_Select Params count");
            ValidatePassedParams(expectedParams, actualValues, "ParametersAndViewChangedEvent_Select expecte '{0}'");
        }
示例#6
0
        public void SqlDataSourceView_DataSourceViewChanged()
        {
            SqlDataSource ds  = new SqlDataSource();
            SqlViewPoker  sql = new SqlViewPoker(ds, "DefaultView", null);

            sql.DataSourceViewChanged += new EventHandler(sql_DataSourceViewChanged);
            sql.DoOnDataSourceViewChanged();
            eventAssert.IsTrue("SqlDataSourceView"); // Assert include counter the first is zero
            /* XXX test parameters */

            sql.CancelSelectOnNullParameter = false;
            eventAssert.IsTrue("SqlDataSourceView");
            sql.ConflictDetection = ConflictOptions.CompareAllValues;
            eventAssert.IsTrue("SqlDataSourceView");
            sql.DeleteCommandType = SqlDataSourceCommandType.Text;
            eventAssert.IsFalse("SqlDataSourceView");
            sql.DeleteCommand = "delete command";
            eventAssert.IsFalse("SqlDataSourceView");
            sql.FilterExpression = "filter expression";
            eventAssert.IsTrue("SqlDataSourceView");
            sql.InsertCommand = "insert command";
            eventAssert.IsFalse("SqlDataSourceView");
            sql.InsertCommandType = SqlDataSourceCommandType.Text;
            eventAssert.IsFalse("SqlDataSourceView");
            sql.OldValuesParameterFormatString = "{1}";
            eventAssert.IsTrue("SqlDataSourceView");
            sql.SelectCommand = "select command";
            eventAssert.IsTrue("SqlDataSourceView");
            sql.SelectCommandType = SqlDataSourceCommandType.Text;
            eventAssert.IsFalse("SqlDataSourceView");
            sql.SortParameterName = "sort parameter";
            eventAssert.IsTrue("SqlDataSourceView");
            sql.UpdateCommand = "update command";
            eventAssert.IsFalse("SqlDataSourceView");
            sql.UpdateCommandType = SqlDataSourceCommandType.Text;
            eventAssert.IsFalse("SqlDataSourceView");
        }
示例#7
0
        public void SelectCommand_DataSourceViewChanged1()
        {
            SqlDataSource ds   = new SqlDataSource();
            SqlViewPoker  view = new SqlViewPoker(ds, "DefaultView", null);

            view.DataSourceViewChanged += new EventHandler(view_DataSourceViewChanged);

            view.SelectCommand = "select 1";
            Assert.AreEqual(1, eventsCalled.Count);
            Assert.AreEqual("view_DataSourceViewChanged", eventsCalled[0]);

            view.SelectCommand = "select 2";
            Assert.AreEqual(2, eventsCalled.Count);
            Assert.AreEqual("view_DataSourceViewChanged", eventsCalled [1]);

            view.SelectCommand = "select 2";
            Assert.AreEqual(2, eventsCalled.Count);

            view.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
            Assert.AreEqual(2, eventsCalled.Count);

            view.SelectCommandType = SqlDataSourceCommandType.Text;
            Assert.AreEqual(2, eventsCalled.Count);
        }
示例#8
0
		public void SelectCommand_DataSourceViewChanged1 ()
		{
			SqlDataSource ds = new SqlDataSource ();
			SqlViewPoker view = new SqlViewPoker (ds, "DefaultView", null);
			view.DataSourceViewChanged+=new EventHandler(view_DataSourceViewChanged);

			view.SelectCommand = "select 1";
			Assert.AreEqual (1, eventsCalled.Count);
			Assert.AreEqual ("view_DataSourceViewChanged", eventsCalled[0]);
			
			view.SelectCommand = "select 2";
			Assert.AreEqual (2, eventsCalled.Count);
			Assert.AreEqual ("view_DataSourceViewChanged", eventsCalled [1]);

			view.SelectCommand = "select 2";
			Assert.AreEqual (2, eventsCalled.Count);

			view.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
			Assert.AreEqual (2, eventsCalled.Count);

			view.SelectCommandType = SqlDataSourceCommandType.Text;
			Assert.AreEqual (2, eventsCalled.Count);
		}
示例#9
0
		public void SelectCommand_DataSourceViewChanged2 ()
		{
			SqlDataSource ds = new SqlDataSource ();
			SqlViewPoker view = new SqlViewPoker (ds, "DefaultView", null);
			view.DataSourceViewChanged += new EventHandler (view_DataSourceViewChanged);

			Assert.AreEqual ("", view.SelectCommand);
			view.SelectCommand = null;
			Assert.AreEqual (1, eventsCalled.Count);
			Assert.AreEqual ("view_DataSourceViewChanged", eventsCalled [0]);
			Assert.AreEqual ("", view.SelectCommand);

			view.SelectCommand = null;
			Assert.AreEqual (2, eventsCalled.Count);
			Assert.AreEqual ("view_DataSourceViewChanged", eventsCalled [1]);
			Assert.AreEqual ("", view.SelectCommand);

			view.SelectCommand = "";
			Assert.AreEqual (2, eventsCalled.Count);
		}
示例#10
0
		public void CancelSelectOnNullParameter ()
		{
			SqlDataSource ds = new SqlDataSource ();

			ds.CancelSelectOnNullParameter = false;

			SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);

			Assert.IsTrue (sql.CancelSelectOnNullParameter, "A1");

			ds.CancelSelectOnNullParameter = true;
			sql.CancelSelectOnNullParameter = false;

			Assert.IsTrue (ds.CancelSelectOnNullParameter, "A2");

			sql.CancelSelectOnNullParameter = false;
			ds.CancelSelectOnNullParameter = true;
			Assert.IsFalse (sql.CancelSelectOnNullParameter, "A3");
		}
示例#11
0
		public void OldValuesParameterFormatString ()
		{
			SqlDataSource ds = new SqlDataSource ();
			
			Assert.AreEqual ("{0}", ds.OldValuesParameterFormatString, "A1");

			ds.OldValuesParameterFormatString = "hi {0}";

			SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);

			Assert.AreEqual ("{0}", sql.OldValuesParameterFormatString, "A2");

			ds.OldValuesParameterFormatString = "hi {0}";

			Assert.AreEqual ("{0}", sql.OldValuesParameterFormatString, "A3");

			ds.OldValuesParameterFormatString = "{0}";
			sql.OldValuesParameterFormatString = "hi {0}";

			Assert.AreEqual ("{0}", ds.OldValuesParameterFormatString, "A4");
		}
示例#12
0
		public void CanSort ()
		{
			SqlDataSource ds = new SqlDataSource ();
			SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);

			sql.SortParameterName = "foo";
			Assert.IsTrue (sql.CanSort, "A1");

			sql.SortParameterName = null;
			Assert.IsTrue (sql.CanSort, "A2");

			sql.SortParameterName = "";
			Assert.IsTrue (sql.CanSort, "A3");

			sql.SortParameterName = "foo";

			ds.DataSourceMode = SqlDataSourceMode.DataReader;
			Assert.IsTrue (sql.CanSort, "A4");

			ds.DataSourceMode = SqlDataSourceMode.DataSet;
			Assert.IsTrue (sql.CanSort, "A5");

			sql.SortParameterName = "";

			ds.DataSourceMode = SqlDataSourceMode.DataReader;
			Assert.IsFalse (sql.CanSort, "A6");

			ds.DataSourceMode = SqlDataSourceMode.DataSet;
			Assert.IsTrue (sql.CanSort, "A7");
		}
示例#13
0
		public void CanUpdate ()
		{
			SqlDataSource ds = new SqlDataSource ();
			SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);

			sql.UpdateCommand = "UPDATE foo";
			Assert.IsTrue (sql.CanUpdate, "A1");

			sql.UpdateCommand = "";
			Assert.IsFalse (sql.CanUpdate, "A2");

			sql.UpdateCommand = null;
			Assert.IsFalse (sql.CanUpdate, "A3");
		}
示例#14
0
		public void CanDelete ()
		{
			SqlDataSource ds = new SqlDataSource ();
			SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);

			sql.DeleteCommand = "DELETE from foo";
			Assert.IsTrue (sql.CanDelete, "A1");

			sql.DeleteCommand = "";
			Assert.IsFalse (sql.CanDelete, "A2");

			sql.DeleteCommand = null;
			Assert.IsFalse (sql.CanDelete, "A3");
		}
示例#15
0
		public void ViewState ()
		{
			SqlDataSource ds = new SqlDataSource ();
			SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);

			/* XXX test parameters */

			sql.CancelSelectOnNullParameter = false;
			sql.ConflictDetection = ConflictOptions.CompareAllValues;
			sql.DeleteCommandType = SqlDataSourceCommandType.Text;
			sql.DeleteCommand = "delete command";
			sql.FilterExpression = "filter expression";
			sql.InsertCommand = "insert command";
			sql.InsertCommandType = SqlDataSourceCommandType.Text;
			sql.OldValuesParameterFormatString = "{1}";
			sql.SelectCommand = "select command";
			sql.SelectCommandType = SqlDataSourceCommandType.Text;
			sql.SortParameterName = "sort parameter";
			sql.UpdateCommand = "update command";
			sql.UpdateCommandType = SqlDataSourceCommandType.Text;

			Assert.IsFalse (sql.CancelSelectOnNullParameter, "A1");
			Assert.AreEqual (ConflictOptions.CompareAllValues, sql.ConflictDetection, "A2");
			Assert.AreEqual ("delete command", sql.DeleteCommand, "A3");
			Assert.AreEqual (SqlDataSourceCommandType.Text, sql.DeleteCommandType, "A4");
			Assert.AreEqual ("filter expression", sql.FilterExpression, "A5");
			Assert.AreEqual ("insert command", sql.InsertCommand, "A6");
			Assert.AreEqual (SqlDataSourceCommandType.Text, sql.InsertCommandType, "A7");
			Assert.AreEqual ("{1}", sql.OldValuesParameterFormatString, "A8");
			Assert.AreEqual ("select command", sql.SelectCommand, "A9");
			Assert.AreEqual (SqlDataSourceCommandType.Text, sql.SelectCommandType, "A10");
			Assert.AreEqual ("sort parameter", sql.SortParameterName, "A11");
			Assert.AreEqual ("update command", sql.UpdateCommand, "A12");
			Assert.AreEqual (SqlDataSourceCommandType.Text, sql.UpdateCommandType, "A13");

			object state = sql.SaveToViewState ();
			Assert.IsNull (state, "ViewState is null");

			sql = new SqlViewPoker (ds, "DefaultView", null);
			sql.LoadFromViewState (state);

			Assert.IsTrue (sql.CancelSelectOnNullParameter, "B1");
			Assert.IsFalse (sql.CanDelete, "B2");
			Assert.IsFalse (sql.CanInsert, "B3");
			Assert.IsFalse (sql.CanPage, "B4");
			Assert.IsFalse (sql.CanRetrieveTotalRowCount, "B5");
			Assert.IsTrue (sql.CanSort, "B6");
			Assert.IsFalse (sql.CanUpdate, "B7");
			Assert.AreEqual (ConflictOptions.OverwriteChanges, sql.ConflictDetection, "B8");
			Assert.AreEqual ("", sql.DeleteCommand, "B9");
			Assert.AreEqual (SqlDataSourceCommandType.Text, sql.DeleteCommandType, "B10");
			Assert.IsNotNull (sql.DeleteParameters, "B11");
			Assert.AreEqual (0, sql.DeleteParameters.Count, "B12");
			Assert.AreEqual ("", sql.FilterExpression, "B13");
			Assert.IsNotNull (sql.FilterParameters, "B14");
			Assert.AreEqual (0, sql.FilterParameters.Count, "B15");
			Assert.AreEqual ("", sql.InsertCommand, "B16");
			Assert.AreEqual (SqlDataSourceCommandType.Text, sql.InsertCommandType, "B17");
			Assert.IsNotNull (sql.InsertParameters, "B18");
			Assert.AreEqual (0, sql.InsertParameters.Count, "B19");
			Assert.AreEqual ("{0}", sql.OldValuesParameterFormatString, "B20");
			Assert.AreEqual ("", sql.SelectCommand, "B21");
			Assert.AreEqual (SqlDataSourceCommandType.Text, sql.SelectCommandType, "B22");
			Assert.IsNotNull (sql.SelectParameters, "B23");
			Assert.AreEqual (0, sql.SelectParameters.Count, "B24");
			Assert.AreEqual ("", sql.SortParameterName, "B25");
			Assert.AreEqual ("", sql.UpdateCommand, "B26");
			Assert.AreEqual (SqlDataSourceCommandType.Text, sql.UpdateCommandType, "B27");
			Assert.IsNotNull (sql.UpdateParameters, "B28");
			Assert.AreEqual (0, sql.UpdateParameters.Count, "B29");
		}
示例#16
0
		public void ViewStateSupport () 
		{
			SqlDataSource ds = new SqlDataSource ();
			SqlViewPoker view = new SqlViewPoker (ds, "DefaultView", null);

			ds.ID = "SqlDataSource1";
			ds.SelectCommand = "Select";

			Parameter p1 = new Parameter ("test", TypeCode.String);

			Assert.IsTrue (((IStateManager) view).IsTrackingViewState, "IsTrackingViewState");
			Assert.IsTrue (((IStateManager) view.FilterParameters).IsTrackingViewState, "FilterParameters.IsTrackingViewState");
			Assert.IsTrue (((IStateManager) view.SelectParameters).IsTrackingViewState, "SelecteParameters.IsTrackingViewState");
			Assert.IsFalse (((IStateManager) view.DeleteParameters).IsTrackingViewState, "DeleteParameters.IsTrackingViewState");
			Assert.IsFalse (((IStateManager) view.InsertParameters).IsTrackingViewState, "InsertParameters.IsTrackingViewState");
			Assert.IsFalse (((IStateManager) view.UpdateParameters).IsTrackingViewState, "UpdateParameters.IsTrackingViewState");

			object state = ((IStateManager) view).SaveViewState ();
			Assert.IsNull (state, "view ViewState not null");

			view.DeleteParameters.Add (p1);
			view.InsertParameters.Add (p1);
			//view.UpdateParameters.Add (p1);

			state = ((IStateManager) view).SaveViewState ();
			Assert.IsNull (state, "view ViewState not null");

			view.FilterParameters.Add (p1);
			//view.SelectParameters.Add (p1);

			state = ((IStateManager) view).SaveViewState ();
			Assert.IsNotNull (state, "view ViewState not null");

			state = ((IStateManager) view.FilterParameters).SaveViewState ();
			Assert.IsNotNull (state, "FilterParamenters ViewState not null");
			state = ((IStateManager) view.SelectParameters).SaveViewState ();
			Assert.IsNull (state, "SelectParameters ViewState not null");

			state = ((IStateManager) view.DeleteParameters).SaveViewState ();
			Assert.IsNotNull (state, "DeleteParameters ViewState not null");
			state = ((IStateManager) view.InsertParameters).SaveViewState ();
			Assert.IsNotNull (state, "InsertParameters ViewState not null");
			state = ((IStateManager) view.UpdateParameters).SaveViewState ();
			Assert.IsNull (state, "UpdateParameters ViewState not null");
		}
示例#17
0
        private static SqlViewPoker InitializeView(InitViewType initType, ConflictOptions conflictDetection, out Hashtable keys, out Hashtable old_value, out Hashtable new_value)
        {
            SqlDataSource ds = new SqlDataSource();

            ds.ConnectionString = "Data Source=fake\\SQLEXPRESS;Initial Catalog=Northwind;User ID=sa";
            ds.ProviderName     = "System.Data.SqlClient";
            SqlViewPoker view = new SqlViewPoker(ds, "DefaultView", null);

            view.ConflictDetection = conflictDetection;
            view.OldValuesParameterFormatString = "oldvalue_{0}";
            view.SelectCommandType = SqlDataSourceCommandType.Text;
            view.InsertCommandType = SqlDataSourceCommandType.Text;
            view.UpdateCommandType = SqlDataSourceCommandType.Text;
            view.DeleteCommandType = SqlDataSourceCommandType.Text;

            view.SelectCommand = "SELECT * FROM Customers WHERE ID = @ID";
            view.InsertCommand = "INSERT INTO Customers (ID) VALUES (@ID)";
            view.UpdateCommand = "UPDATE Customers SET ID = @ID WHERE ID = @oldvalue_ID";
            view.DeleteCommand = "DELETE * FROM Customers WHERE ID = @ID";

            Parameter selectParameter = null;
            Parameter insertParameter = null;
            Parameter updateParameter = null;
            Parameter deleteParameter = null;

            selectParameter = new AlwaysChangingParameter("ID", TypeCode.String, "p_ValueSelect");
            view.SelectParameters.Add(selectParameter);

            switch (initType)
            {
            case InitViewType.MatchParamsToOldValues:
                insertParameter = new AlwaysChangingParameter("oldvalue_ID", TypeCode.String, "p_OldValueInsert");
                view.InsertParameters.Add(insertParameter);
                updateParameter = new AlwaysChangingParameter("oldvalue_ID", TypeCode.String, "p_OldValueUpdate");
                view.UpdateParameters.Add(updateParameter);
                deleteParameter = new AlwaysChangingParameter("oldvalue_ID", TypeCode.String, "p_OldValueDelete");
                view.DeleteParameters.Add(deleteParameter);
                break;

            case InitViewType.MatchParamsToValues:
                insertParameter = new AlwaysChangingParameter("ID", TypeCode.String, "p_ValueInsert");
                view.InsertParameters.Add(insertParameter);
                updateParameter = new AlwaysChangingParameter("ID", TypeCode.String, "p_ValueUpdate");
                view.UpdateParameters.Add(updateParameter);
                deleteParameter = new AlwaysChangingParameter("ID", TypeCode.String, "p_ValueDelete");
                view.DeleteParameters.Add(deleteParameter);
                break;

            case InitViewType.DontMatchParams:
                insertParameter = new AlwaysChangingParameter("OtherValue", TypeCode.String, "p_OtherValueInsert");
                view.InsertParameters.Add(insertParameter);
                updateParameter = new AlwaysChangingParameter("OtherValue", TypeCode.String, "p_OtherValueUpdate");
                view.UpdateParameters.Add(updateParameter);
                deleteParameter = new AlwaysChangingParameter("OtherValue", TypeCode.String, "p_OtherValueDelete");
                view.DeleteParameters.Add(deleteParameter);
                break;
            }

            view.SelectParameters.ParametersChanged += new EventHandler(SelectParameters_ParametersChanged);
            view.InsertParameters.ParametersChanged += new EventHandler(InsertParameters_ParametersChanged);
            view.UpdateParameters.ParametersChanged += new EventHandler(UpdateParameters_ParametersChanged);
            view.DeleteParameters.ParametersChanged += new EventHandler(DeleteParameters_ParametersChanged);

            keys = new Hashtable();
            keys.Add("ID", "k_1001");

            old_value = new Hashtable();
            old_value.Add("ID", "ov_1001");

            new_value = new Hashtable();
            new_value.Add("ID", "n_1001");

            view.DataSourceViewChanged += new EventHandler(view_DataSourceViewChanged);

            view.Selecting += new SqlDataSourceSelectingEventHandler(view_Selecting);
            view.Inserting += new SqlDataSourceCommandEventHandler(view_Inserting);
            view.Updating  += new SqlDataSourceCommandEventHandler(view_Updating);
            view.Deleting  += new SqlDataSourceCommandEventHandler(view_Deleting);
            return(view);
        }
示例#18
0
		private static SqlViewPoker InitializeView (InitViewType initType, ConflictOptions conflictDetection, out Hashtable keys, out Hashtable old_value, out Hashtable new_value) 
		{
			SqlDataSource ds = new SqlDataSource ();
			ds.ConnectionString = "Data Source=fake\\SQLEXPRESS;Initial Catalog=Northwind;User ID=sa";
			ds.ProviderName = "System.Data.SqlClient";
			SqlViewPoker view = new SqlViewPoker (ds, "DefaultView", null);

			view.ConflictDetection = conflictDetection;
			view.OldValuesParameterFormatString = "oldvalue_{0}";
			view.SelectCommandType = SqlDataSourceCommandType.Text;
			view.InsertCommandType = SqlDataSourceCommandType.Text;
			view.UpdateCommandType = SqlDataSourceCommandType.Text;
			view.DeleteCommandType = SqlDataSourceCommandType.Text;

			view.SelectCommand = "SELECT * FROM Customers WHERE ID = @ID";
			view.InsertCommand = "INSERT INTO Customers (ID) VALUES (@ID)";
			view.UpdateCommand = "UPDATE Customers SET ID = @ID WHERE ID = @oldvalue_ID";
			view.DeleteCommand = "DELETE * FROM Customers WHERE ID = @ID";

			Parameter selectParameter = null;
			Parameter insertParameter = null;
			Parameter updateParameter = null;
			Parameter deleteParameter = null;

			selectParameter = new AlwaysChangingParameter ("ID", TypeCode.String, "p_ValueSelect");
			view.SelectParameters.Add (selectParameter);

			switch (initType) {
			case InitViewType.MatchParamsToOldValues:
				insertParameter = new AlwaysChangingParameter ("oldvalue_ID", TypeCode.String, "p_OldValueInsert");
				view.InsertParameters.Add (insertParameter);
				updateParameter = new AlwaysChangingParameter ("oldvalue_ID", TypeCode.String, "p_OldValueUpdate");
				view.UpdateParameters.Add (updateParameter);
				deleteParameter = new AlwaysChangingParameter ("oldvalue_ID", TypeCode.String, "p_OldValueDelete");
				view.DeleteParameters.Add (deleteParameter);
				break;

			case InitViewType.MatchParamsToValues:
				insertParameter = new AlwaysChangingParameter ("ID", TypeCode.String, "p_ValueInsert");
				view.InsertParameters.Add (insertParameter);
				updateParameter = new AlwaysChangingParameter ("ID", TypeCode.String, "p_ValueUpdate");
				view.UpdateParameters.Add (updateParameter);
				deleteParameter = new AlwaysChangingParameter ("ID", TypeCode.String, "p_ValueDelete");
				view.DeleteParameters.Add (deleteParameter);
				break;

			case InitViewType.DontMatchParams:
				insertParameter = new AlwaysChangingParameter ("OtherValue", TypeCode.String, "p_OtherValueInsert");
				view.InsertParameters.Add (insertParameter);
				updateParameter = new AlwaysChangingParameter ("OtherValue", TypeCode.String, "p_OtherValueUpdate");
				view.UpdateParameters.Add (updateParameter);
				deleteParameter = new AlwaysChangingParameter ("OtherValue", TypeCode.String, "p_OtherValueDelete");
				view.DeleteParameters.Add (deleteParameter);
				break;
			}

			view.SelectParameters.ParametersChanged += new EventHandler (SelectParameters_ParametersChanged);
			view.InsertParameters.ParametersChanged += new EventHandler (InsertParameters_ParametersChanged);
			view.UpdateParameters.ParametersChanged += new EventHandler (UpdateParameters_ParametersChanged);
			view.DeleteParameters.ParametersChanged += new EventHandler (DeleteParameters_ParametersChanged);

			keys = new Hashtable ();
			keys.Add ("ID", "k_1001");

			old_value = new Hashtable ();
			old_value.Add ("ID", "ov_1001");

			new_value = new Hashtable ();
			new_value.Add ("ID", "n_1001");

			view.DataSourceViewChanged += new EventHandler (view_DataSourceViewChanged);

			view.Selecting += new SqlDataSourceSelectingEventHandler (view_Selecting);
			view.Inserting += new SqlDataSourceCommandEventHandler (view_Inserting);
			view.Updating += new SqlDataSourceCommandEventHandler (view_Updating);
			view.Deleting += new SqlDataSourceCommandEventHandler (view_Deleting);
			return view;
		}
示例#19
0
		public void CanInsert ()
		{
			SqlDataSource ds = new SqlDataSource ();
			SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);

			sql.InsertCommand = "INSERT into foo";
			Assert.IsTrue (sql.CanInsert, "A1");

			sql.InsertCommand = "";
			Assert.IsFalse (sql.CanInsert, "A2");

			sql.InsertCommand = null;
			Assert.IsFalse (sql.CanInsert, "A3");
		}
示例#20
0
		public void SqlDataSourceView_DataSourceViewChanged ()
		{
			SqlDataSource ds = new SqlDataSource ();
			SqlViewPoker sql = new SqlViewPoker (ds, "DefaultView", null);
			sql.DataSourceViewChanged += new EventHandler (sql_DataSourceViewChanged);
			sql.DoOnDataSourceViewChanged ();
			eventAssert.IsTrue ("SqlDataSourceView"); // Assert include counter the first is zero
			/* XXX test parameters */

			sql.CancelSelectOnNullParameter = false;
			eventAssert.IsTrue ("SqlDataSourceView");
			sql.ConflictDetection = ConflictOptions.CompareAllValues;
			eventAssert.IsTrue ("SqlDataSourceView");
			sql.DeleteCommandType = SqlDataSourceCommandType.Text;
			eventAssert.IsFalse ("SqlDataSourceView");
			sql.DeleteCommand = "delete command";
			eventAssert.IsFalse ("SqlDataSourceView");
			sql.FilterExpression = "filter expression";
			eventAssert.IsTrue ("SqlDataSourceView");
			sql.InsertCommand = "insert command";
			eventAssert.IsFalse ("SqlDataSourceView");
			sql.InsertCommandType = SqlDataSourceCommandType.Text;
			eventAssert.IsFalse ("SqlDataSourceView");
			sql.OldValuesParameterFormatString = "{1}";
			eventAssert.IsTrue ("SqlDataSourceView");
			sql.SelectCommand = "select command";
			eventAssert.IsTrue ("SqlDataSourceView");
			sql.SelectCommandType = SqlDataSourceCommandType.Text;
			eventAssert.IsFalse ("SqlDataSourceView");
			sql.SortParameterName = "sort parameter";
			eventAssert.IsTrue ("SqlDataSourceView");
			sql.UpdateCommand = "update command";
			eventAssert.IsFalse ("SqlDataSourceView");
			sql.UpdateCommandType = SqlDataSourceCommandType.Text;
			eventAssert.IsFalse ("SqlDataSourceView");
		}
示例#21
0
        public void ViewState()
        {
            SqlDataSource ds  = new SqlDataSource();
            SqlViewPoker  sql = new SqlViewPoker(ds, "DefaultView", null);

            /* XXX test parameters */

            sql.CancelSelectOnNullParameter = false;
            sql.ConflictDetection           = ConflictOptions.CompareAllValues;
            sql.DeleteCommandType           = SqlDataSourceCommandType.Text;
            sql.DeleteCommand     = "delete command";
            sql.FilterExpression  = "filter expression";
            sql.InsertCommand     = "insert command";
            sql.InsertCommandType = SqlDataSourceCommandType.Text;
            sql.OldValuesParameterFormatString = "{1}";
            sql.SelectCommand     = "select command";
            sql.SelectCommandType = SqlDataSourceCommandType.Text;
            sql.SortParameterName = "sort parameter";
            sql.UpdateCommand     = "update command";
            sql.UpdateCommandType = SqlDataSourceCommandType.Text;

            Assert.IsFalse(sql.CancelSelectOnNullParameter, "A1");
            Assert.AreEqual(ConflictOptions.CompareAllValues, sql.ConflictDetection, "A2");
            Assert.AreEqual("delete command", sql.DeleteCommand, "A3");
            Assert.AreEqual(SqlDataSourceCommandType.Text, sql.DeleteCommandType, "A4");
            Assert.AreEqual("filter expression", sql.FilterExpression, "A5");
            Assert.AreEqual("insert command", sql.InsertCommand, "A6");
            Assert.AreEqual(SqlDataSourceCommandType.Text, sql.InsertCommandType, "A7");
            Assert.AreEqual("{1}", sql.OldValuesParameterFormatString, "A8");
            Assert.AreEqual("select command", sql.SelectCommand, "A9");
            Assert.AreEqual(SqlDataSourceCommandType.Text, sql.SelectCommandType, "A10");
            Assert.AreEqual("sort parameter", sql.SortParameterName, "A11");
            Assert.AreEqual("update command", sql.UpdateCommand, "A12");
            Assert.AreEqual(SqlDataSourceCommandType.Text, sql.UpdateCommandType, "A13");

            object state = sql.SaveToViewState();

            Assert.IsNull(state, "ViewState is null");

            sql = new SqlViewPoker(ds, "DefaultView", null);
            sql.LoadFromViewState(state);

            Assert.IsTrue(sql.CancelSelectOnNullParameter, "B1");
            Assert.IsFalse(sql.CanDelete, "B2");
            Assert.IsFalse(sql.CanInsert, "B3");
            Assert.IsFalse(sql.CanPage, "B4");
            Assert.IsFalse(sql.CanRetrieveTotalRowCount, "B5");
            Assert.IsTrue(sql.CanSort, "B6");
            Assert.IsFalse(sql.CanUpdate, "B7");
            Assert.AreEqual(ConflictOptions.OverwriteChanges, sql.ConflictDetection, "B8");
            Assert.AreEqual("", sql.DeleteCommand, "B9");
            Assert.AreEqual(SqlDataSourceCommandType.Text, sql.DeleteCommandType, "B10");
            Assert.IsNotNull(sql.DeleteParameters, "B11");
            Assert.AreEqual(0, sql.DeleteParameters.Count, "B12");
            Assert.AreEqual("", sql.FilterExpression, "B13");
            Assert.IsNotNull(sql.FilterParameters, "B14");
            Assert.AreEqual(0, sql.FilterParameters.Count, "B15");
            Assert.AreEqual("", sql.InsertCommand, "B16");
            Assert.AreEqual(SqlDataSourceCommandType.Text, sql.InsertCommandType, "B17");
            Assert.IsNotNull(sql.InsertParameters, "B18");
            Assert.AreEqual(0, sql.InsertParameters.Count, "B19");
            Assert.AreEqual("{0}", sql.OldValuesParameterFormatString, "B20");
            Assert.AreEqual("", sql.SelectCommand, "B21");
            Assert.AreEqual(SqlDataSourceCommandType.Text, sql.SelectCommandType, "B22");
            Assert.IsNotNull(sql.SelectParameters, "B23");
            Assert.AreEqual(0, sql.SelectParameters.Count, "B24");
            Assert.AreEqual("", sql.SortParameterName, "B25");
            Assert.AreEqual("", sql.UpdateCommand, "B26");
            Assert.AreEqual(SqlDataSourceCommandType.Text, sql.UpdateCommandType, "B27");
            Assert.IsNotNull(sql.UpdateParameters, "B28");
            Assert.AreEqual(0, sql.UpdateParameters.Count, "B29");
        }