Пример #1
0
        public void DataBind_Default()
        {
            var ctrl = new Mock <System.Web.UI.WebControls.ListControl>();

            ctrl.SetupAllProperties();
            EnumHelper.DataBind(ctrl.Object, typeof(TestEnum));
            var itemData = (List <EnumItemData>)ctrl.Object.DataSource;

            Assert.IsNotNull(itemData);
            Assert.AreEqual("ID", ctrl.Object.DataValueField);
            Assert.AreEqual("DisplayValue", ctrl.Object.DataTextField);
            Assert.AreEqual(2, itemData.Count);
        }
Пример #2
0
        public void DataBind_RemoveFirstRecord()
        {
            var ctrl = new Mock <System.Web.UI.WebControls.ListControl>();

            ctrl.SetupAllProperties();
            EnumHelper.DataBind(ctrl.Object, typeof(TestEnum), EnumHelper.EnumDropdownBindingType.RemoveFirstRecord);
            var itemData = (List <EnumItemData>)ctrl.Object.DataSource;

            Assert.IsNotNull(itemData);
            Assert.AreEqual("ID", ctrl.Object.DataValueField);
            Assert.AreEqual("DisplayValue", ctrl.Object.DataTextField);
            Assert.AreEqual(1, itemData.Count);
            Assert.AreEqual("TestValue2", itemData[0].DisplayValue);
        }
Пример #3
0
        public void DataBind_AddEmptyFirstRecord_WithText()
        {
            var ctrl = new Mock <System.Web.UI.WebControls.ListControl>();

            ctrl.SetupAllProperties();
            string firstRecordValue = Guid.NewGuid().ToString();

            EnumHelper.DataBind(ctrl.Object, typeof(TestEnum), EnumHelper.EnumDropdownBindingType.AddEmptyFirstRecord, firstRecordValue);
            var itemData = (List <EnumItemData>)ctrl.Object.DataSource;

            Assert.IsNotNull(itemData);
            Assert.AreEqual("ID", ctrl.Object.DataValueField);
            Assert.AreEqual("DisplayValue", ctrl.Object.DataTextField);
            Assert.AreEqual(3, itemData.Count);
            Assert.AreEqual(firstRecordValue, itemData[0].DisplayValue);
            Assert.AreEqual("Test Value 1", itemData[1].DisplayValue);
            Assert.AreEqual("TestValue2", itemData[2].DisplayValue);
        }