public void ApplyModelToPage_TextBox()
        {
            TestParticipantClass  testPart = new TestParticipantClass();
            WFObjectValueProvider provider = new WFObjectValueProvider(testPart, "");
            Page    testPage  = new Page();
            TextBox FirstName = new TextBox()
            {
                ID = "FirstName"
            };

            testPage.Controls.Add(FirstName);

            //Apply null value (since it is a property initial state should be null)
            WebControlUtilities.ApplyModelToPage(testPage, provider);

            Assert.AreEqual("", ((TextBox)testPage.FindControl("FirstName")).Text);

            testPart.FirstName = "John";

            WebControlUtilities.ApplyModelToPage(testPage, provider);

            Assert.AreEqual("John", ((TextBox)testPage.FindControl("FirstName")).Text);

            testPart.FirstName = "";

            WebControlUtilities.ApplyModelToPage(testPage, provider);

            Assert.AreEqual("", ((TextBox)testPage.FindControl("FirstName")).Text);
        }
        public void ApplyModelTopage_CheckBox()
        {
            TestParticipantClass  testPart = new TestParticipantClass();
            WFObjectValueProvider provider = new WFObjectValueProvider(testPart, "");
            Page     testPage      = new Page();
            CheckBox AcceptedRules = new CheckBox()
            {
                ID = "AcceptedRules"
            };

            testPage.Controls.Add(AcceptedRules);

            WebControlUtilities.ApplyModelToPage(testPage, provider);

            Assert.IsFalse(AcceptedRules.Checked);

            testPart.AcceptedRules = false;
            WebControlUtilities.ApplyModelToPage(testPage, provider);

            Assert.IsFalse(AcceptedRules.Checked);

            testPart.AcceptedRules = true;
            WebControlUtilities.ApplyModelToPage(testPage, provider);

            Assert.IsTrue(AcceptedRules.Checked);
        }
        public void ApplyModelToPage_DropDownList()
        {
            //Test applying a string property to ListBox
            TestParticipantClass  testPart = new TestParticipantClass();
            WFObjectValueProvider provider = new WFObjectValueProvider(testPart, "");
            Page         testPage          = new Page();
            DropDownList FirstName         = new DropDownList()
            {
                ID = "FirstName"
            };

            testPage.Controls.Add(FirstName);

            //null property value to empty listbox
            WebControlUtilities.ApplyModelToPage(testPage, provider);

            //null property value to listbox with empty item, but other selected
            FirstName.Items.Add(new ListItem("John", "1")
            {
                Selected = true
            });
            FirstName.Items.Add(new ListItem("Mark", "2"));
            FirstName.Items.Add(new ListItem("Joe", "3"));
            FirstName.Items.Add(new ListItem("Select a Name", ""));

            WebControlUtilities.ApplyModelToPage(testPage, provider);

            Assert.AreEqual(3, FirstName.SelectedIndex);

            //specific value

            testPart.FirstName = "2"; //go by value, not by text

            WebControlUtilities.ApplyModelToPage(testPage, provider);

            Assert.AreEqual(1, FirstName.SelectedIndex);

            testPart.FirstName = "NonExistantValue";

            WebControlUtilities.ApplyModelToPage(testPage, provider);

            //different from listbox. This should have the first item in the list selected
            //because a dropdownlist even though set to "-1" cannot have "no item selected"

            Assert.AreEqual(0, FirstName.SelectedIndex);
        }
        public void ApplyModelToPage_IWFControlValue()
        {
            TestParticipantClass  testPart = new TestParticipantClass();
            WFObjectValueProvider provider = new WFObjectValueProvider(testPart, "");
            Page testPage = new Page();
            TestControlValueControl testControl = new TestControlValueControl()
            {
                ID = "FirstName"
            };

            testPage.Controls.Add(testControl);

            WebControlUtilities.ApplyModelToPage(testPage, provider);

            Assert.AreEqual("", testControl.ControlValue);

            testPart.FirstName = "Sam";

            WebControlUtilities.ApplyModelToPage(testPage, provider);

            Assert.AreEqual("Sam", testControl.ControlValue);
        }
        public void ApplyModelToPage_ListBox()
        {
            //Test applying a string property to ListBox
            TestParticipantClass  testPart = new TestParticipantClass();
            WFObjectValueProvider provider = new WFObjectValueProvider(testPart, "");
            Page    testPage  = new Page();
            ListBox FirstName = new ListBox()
            {
                ID = "FirstName"
            };

            testPage.Controls.Add(FirstName);

            //null property value to empty listbox
            WebControlUtilities.ApplyModelToPage(testPage, provider);

            //null property value to listbox with empty item, but other selected
            FirstName.Items.Add(new ListItem("John", "1")
            {
                Selected = true
            });
            FirstName.Items.Add(new ListItem("Mark", "2"));
            FirstName.Items.Add(new ListItem("Joe", "3"));
            FirstName.Items.Add(new ListItem("Select a Name", ""));

            WebControlUtilities.ApplyModelToPage(testPage, provider);

            Assert.AreEqual(3, FirstName.SelectedIndex);

            //specific value

            testPart.FirstName = "2"; //go by value, not by text

            WebControlUtilities.ApplyModelToPage(testPage, provider);

            Assert.AreEqual(1, FirstName.SelectedIndex);

            testPart.FirstName = "NonExistantValue";

            WebControlUtilities.ApplyModelToPage(testPage, provider);

            Assert.AreEqual(-1, FirstName.SelectedIndex);

            //test multiple values

            testPage.Controls.Remove(FirstName);

            testPart.LuckyNumbers = new int[] { 1, 3 };

            ListBox LuckyNumbers = new ListBox();

            LuckyNumbers.Items.Add(new ListItem("1", "1"));
            LuckyNumbers.Items.Add(new ListItem("2", "2"));
            LuckyNumbers.Items.Add(new ListItem("3", "3"));
            LuckyNumbers.Items.Add(new ListItem("4", "4"));
            LuckyNumbers.Items.Add(new ListItem("5", "5"));

            //multiple values while in single mode
            LuckyNumbers.SelectionMode = ListSelectionMode.Single;
            LuckyNumbers.ID            = "LuckyNumbers";
            testPage.Controls.Add(LuckyNumbers);

            WebControlUtilities.ApplyModelToPage(testPage, provider);
            //because we are in single mode, the array shouldn't be enumerated
            //returns "System.Int32[]..."
            Assert.AreEqual(-1, LuckyNumbers.SelectedIndex);

            //now change to multiple mode. Both items in the array should be selected.
            //No other items should be selected.
            LuckyNumbers.SelectionMode = ListSelectionMode.Multiple;

            WebControlUtilities.ApplyModelToPage(testPage, provider);

            foreach (ListItem li in LuckyNumbers.Items)
            {
                if (!li.Selected && testPart.LuckyNumbers.Contains(int.Parse(li.Value)))
                {
                    Assert.Fail("Item " + li.Value + " should be selected.");
                }
                else if (li.Selected && !testPart.LuckyNumbers.Contains(int.Parse(li.Value)))
                {
                    Assert.Fail("Item " + li.Value + " should not be selected.");
                }
            }
        }
Beispiel #6
0
        public void UpdateModel_ValueConversionTests()
        {
            ConversionModel       cm       = new ConversionModel();
            WFObjectValueProvider provider = new WFObjectValueProvider(cm, "");
            DestinationModel      dm       = new DestinationModel();

            dm.stringToNullableBoolean  = true;
            dm.stringToNullableDateTime = DateTime.Parse("1/1/2001");
            dm.stringToNullableDouble   = 0.5d;
            dm.stringToNullableInt      = 5;

            WFPageUtilities.UpdateModel(provider, dm, "", null, null);

            Assert.AreEqual(10, dm.stringToShort);
            Assert.AreEqual(10, dm.stringToInt);
            Assert.AreEqual(10, dm.stringToLong);
            Assert.AreEqual(10.1m, dm.stringToDecimal);
            Assert.AreEqual(10.2f, dm.stringToFloat);
            Assert.AreEqual(10, dm.intToShort);
            Assert.AreEqual(10, dm.intToLong);
            Assert.AreEqual(10, dm.intToFloat);
            Assert.AreEqual(default(DateTime), dm.blankToDateTime);
            Assert.AreEqual(default(DateTime), dm.nullToDateTime);
            Assert.AreEqual(default(int), dm.nullToInt);
            Assert.AreEqual(default(int), dm.blankToInt);

            Assert.AreEqual(DateTime.Parse("1/1/2001").ToString(), dm.dateToString);
            Assert.AreEqual(DateTime.Parse("1/1/2002"), dm.stringToDate);

            // Test null =================================
            Assert.IsNull(dm.stringToNullableBoolean);
            Assert.IsNull(dm.stringToNullableDateTime);
            Assert.IsNull(dm.stringToNullableDouble);
            Assert.IsNull(dm.stringToNullableInt);

            // Test "" ===================================
            cm.stringToNullableBoolean  = "";
            cm.stringToNullableDateTime = "";
            cm.stringToNullableDouble   = "";
            cm.stringToNullableInt      = "";

            dm.stringToNullableBoolean  = true;
            dm.stringToNullableDateTime = DateTime.Parse("1/1/2001");
            dm.stringToNullableDouble   = 0.5d;
            dm.stringToNullableInt      = 5;

            WFPageUtilities.UpdateModel(provider, dm, "", null, null);
            Assert.IsNull(dm.stringToNullableBoolean);
            Assert.IsNull(dm.stringToNullableDateTime);
            Assert.IsNull(dm.stringToNullableDouble);
            Assert.IsNull(dm.stringToNullableInt);

            // Test "null" ===============================
            cm.stringToNullableBoolean  = "null";
            cm.stringToNullableDateTime = "null";
            cm.stringToNullableDouble   = "null";
            cm.stringToNullableInt      = "null";

            dm.stringToNullableBoolean  = true;
            dm.stringToNullableDateTime = DateTime.Parse("1/1/2001");
            dm.stringToNullableDouble   = 0.5d;
            dm.stringToNullableInt      = 5;
            WFPageUtilities.UpdateModel(provider, dm, "", null, null);
            Assert.IsNull(dm.stringToNullableBoolean);
            Assert.IsNull(dm.stringToNullableDateTime);
            Assert.IsNull(dm.stringToNullableDouble);
            Assert.IsNull(dm.stringToNullableInt);

            // Test values (except bool)
            cm.stringToNullableDateTime = "1/1/2015";
            cm.stringToNullableDouble   = "0.7";
            cm.stringToNullableInt      = "77";

            dm.stringToNullableDateTime = DateTime.Parse("1/1/2001");
            dm.stringToNullableDouble   = 0.5d;
            dm.stringToNullableInt      = 5;
            WFPageUtilities.UpdateModel(provider, dm, "", null, null);
            Assert.IsTrue(dm.stringToNullableDateTime.HasValue);
            Assert.IsTrue(dm.stringToNullableDouble.HasValue);
            Assert.IsTrue(dm.stringToNullableInt.HasValue);
            Assert.AreEqual(DateTime.Parse("1/1/2015"), dm.stringToNullableDateTime.Value);
            Assert.AreEqual(Double.Parse("0.7"), dm.stringToNullableDouble.Value);
            Assert.AreEqual(Int32.Parse("77"), dm.stringToNullableInt.Value);

            string[] trueValues = { "true", "true,false", "on" };
            foreach (string s in trueValues)
            {
                // truthy values test
                cm.stringToNullableBoolean = s;
                dm.stringToNullableBoolean = null;
                WFPageUtilities.UpdateModel(provider, dm, "", null, null);
                Assert.IsTrue(dm.stringToNullableBoolean.HasValue && dm.stringToNullableBoolean.Value);
            }
        }
Beispiel #7
0
        public static void ApplyModelToPage(Control pageControl, object Model, string prefix)
        {
            WFObjectValueProvider provider = new WFObjectValueProvider(Model, prefix);

            ApplyModelToPage(pageControl, provider);
        }