コード例 #1
0
        public void PropertyWithDataTypeTextAttributeShouldMakeTheTagATextArea()
        {
            var model = new TestViewModel();
            var tag   = MvcMockHelpers.GetHtmlHelper(model).Input(x => x.Text);

            tag.TagName().ShouldBe("textarea");
        }
コード例 #2
0
        public void Test2()
        {
            var model = new LoopViewModel()
            {
                Address = "My Address"
            };

            for (int j = 0; j < 1000; j++)
            {
                model.LoopItems.Add(new LoopViewModel.LoopItem()
                {
                    Name = "MyName:" + j
                });
            }

            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var sw     = Stopwatch.StartNew();

            foreach (var loop in helper.Loop(x => x.LoopItems))
            {
                loop.Input(x => x.Name);
                loop.Display(x => x.Name);

                foreach (var loopItem in loop.Loop(x => x.NestedLoopItems))
                {
                    loopItem.Input(x => x.Age);
                }
            }
            sw.Stop();
            Console.WriteLine(sw.ElapsedMilliseconds);
        }
コード例 #3
0
        public void ProfileWithNesteds()
        {
            HtmlConventionFactory.Add(new DefaultHtmlConventions());
            HtmlConventionFactory.Add(new DataAnnotationHtmlConventions());

            var model = new ProfileViewModel()
            {
                Name = "Test"
            };
            var helper = MvcMockHelpers.GetHtmlHelper(model);

            using (helper.Profile(new ProfileTest1()))
            {
                var tag = helper.Input(x => x.Name);
                tag.ToHtmlString().ShouldBe("<profile>Test</profile>");

                using (helper.Profile(new ProfileTest2()))
                {
                    var tag3 = helper.Input(x => x.Name);
                    tag3.ToHtmlString().ShouldBe("<profilenested>Test</profilenested>");
                }

                var tag2 = helper.Input(x => x.Name);
                tag2.ToHtmlString().ShouldBe("<profile>Test</profile>");
            }

            var tag1 = helper.Input(x => x.Name);

            tag1.ToHtmlString().ShouldBe("<input type=\"text\" value=\"Test\" id=\"Name\" name=\"Name\" />");
        }
コード例 #4
0
        public void RenderTagConditionally2()
        {
            var selectListItems = new List <SelectListItem>()
            {
                new SelectListItem()
                {
                    Text = "testtext", Value = "testvalue"
                }
            };
            var model = new TestViewModel()
            {
                CombinationType = new CombinationType()
                {
                    Items    = selectListItems,
                    IsSingle = true,
                    Name     = "Text",
                    Value    = "Value"
                },
                Dropdown = selectListItems
            };
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.CombinationType);

            Assert.AreEqual("<div>Text<input type=\"hidden\" id=\"CombinationType\" name=\"CombinationType\" value=\"Value\" /></div>", tag.ToHtmlString());
        }
コード例 #5
0
        public void InputOfListSelectItemListPropertyShouldGenerateSelectTagWithClientSelectedOptionStillSelectedIfError()
        {
            var model = new TestViewModel()
            {
                Dropdown = new List <SelectListItem>()
                {
                    new SelectListItem()
                    {
                        Text = "Text1", Value = "Value1"
                    },
                    new SelectListItem()
                    {
                        Text = "Text2", Value = "Value2", Selected = true
                    }
                }
            };

            var helper = MvcMockHelpers.GetHtmlHelper(model);

            helper.ViewContext.SetError("Dropdown", "Value1");

            var tag = helper.Input(x => x.Dropdown);

            tag.Children[0].HasAttr("selected").ShouldBe(true);
            tag.Children[1].HasAttr("selected").ShouldBe(false);
        }
コード例 #6
0
        public void InputOfBoolPropertyWhosValueIsFalseShouldGiveAttrValueOfTrue()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.IsCorrect);

            tag.Attr("value").ShouldBe(true.ToString());
        }
コード例 #7
0
        public void InputOfPropertyShouldBeCheckboxIfPropertyIsABool()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.IsCorrect);

            tag.Attr("type").ShouldBe("checkbox");
        }
コード例 #8
0
        public void PropertyOfTypeIntShouldHaveDigitsClass()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.Int);

            tag.HasClass("digits").ShouldBe(true);
        }
コード例 #9
0
        public void PropertyOfTypeDoubleShouldHaveNumberClass()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.Double);

            tag.HasClass("number").ShouldBe(true);
        }
コード例 #10
0
        public void InputOfBoolPropertyShouldGenerateHiddenInputWithTheSameName()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.IsCorrect);

            tag.Next.TagName().ShouldBe(tag.TagName());
        }
コード例 #11
0
        public void PropertyWithDataTypePasswordAttributeShouldHaveTheTypePassword()
        {
            var model = new TestViewModel();
            var tag   = MvcMockHelpers.GetHtmlHelper(model).Input(x => x.Password);

            tag.TagName().ShouldBe("input");
            tag.Attr("type").ShouldBe("password");
        }
コード例 #12
0
        public void PropertyWithHiddenInputAttributeShouldMakeTheTypeHidden()
        {
            var model = new TestViewModel();
            var tag   = MvcMockHelpers.GetHtmlHelper(model).Input(x => x.Hidden);

            tag.TagName().ShouldBe("input");
            tag.Attr("type").ShouldBe("hidden");
        }
コード例 #13
0
        public void AllDisplaysShouldHaveIdWithDisplaySuffix()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);

            var tag = helper.Display(x => x.Name);

            tag.Attr("id").ShouldBe("Name_Display");
        }
コード例 #14
0
        public void AllLabelsShouldHaveIdWithLabelSuffix()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);

            var tag = helper.Label(x => x.Name);

            tag.Attr("id").ShouldBe("Name_Label");
        }
コード例 #15
0
        public void InputOfBoolPropertyShouldGenerateHiddenInputWithValueOfFalse()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.IsCorrect);

            tag.Next.Attr("type").ShouldBe("hidden");
            tag.Next.Attr("value").ShouldBe(false.ToString());
        }
コード例 #16
0
        public void SubmitButtonShouldHaveNoIdTag()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);

            var tag = helper.Submit("test").AddClass("testclass");

            tag.ToString().ShouldBe("<input type=\"submit\" value=\"test\" class=\"testclass\" />");
        }
コード例 #17
0
        public void CallingBuildShouldRunTheConventionsAsIfItWasAnotherType()
        {
            var model  = new ReusingViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.AnimalId);

            tag.TagName().ShouldBe("select");
            Console.WriteLine(tag);
        }
コード例 #18
0
        public void PropertyWithNotEmptyFluentValidationDefinedShouldHaveRequiredClass()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);

            helper.ViewContext.HttpContext.Items[TagGenerator.FORMINPUTTYPE] = typeof(TestInputModel);
            var tag = helper.Input(x => x.Name);

            tag.HasClass("required").ShouldBe(true);
        }
コード例 #19
0
        public void PropertyWithNumber()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);

            helper.ViewContext.HttpContext.Items[TagGenerator.FORMINPUTTYPE] = typeof(TestInputModel);
            var tag = helper.Input(x => x.NameWithNumber2);

            tag.HasAttr("maxlength").ShouldBe(true);
        }
コード例 #20
0
        public void AllInputsShouldHaveIdAndName()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);

            var tag = helper.Input(x => x.Name);

            tag.Attr("name").ShouldBe("Name");
            tag.Attr("id").ShouldBe("Name");
        }
コード例 #21
0
        public void LabelOfPropertyShouldByDefaultUseSpanTag()
        {
            var model = new TestViewModel();
            Expression <Func <TestViewModel, object> > expression = x => x.Name;
            var tag  = MvcMockHelpers.GetHtmlHelper(model).Label(expression);
            var name = expression.GetMemberExpression(false).Member.Name;

            tag.TagName().ShouldBe("label");
            tag.Text().ShouldBe(name);
        }
コード例 #22
0
        public void InputOfPropertyShouldBeTheModelValueIfThereIsNoError()
        {
            var model = new TestViewModel()
            {
                Name = "Test"
            };
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.Name);

            tag.Attr("value").ShouldBe(model.Name);
        }
コード例 #23
0
        public void PropertyWithNotEmptyFluentValidationDefinedShouldHaveUnObtrusiveDataAttributesWithDefaultMessage()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);

            helper.ViewContext.UnobtrusiveJavaScriptEnabled = true;
            helper.ViewContext.HttpContext.Items[TagGenerator.FORMINPUTTYPE] = typeof(TestInputModel);
            var tag = helper.Input(x => x.CreditCard);

            tag.Attr("data-val-required").ShouldBe("'Credit Card' should not be empty.");
        }
コード例 #24
0
        public void FindNestedNamesWithWhen()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);

            var finder = new FluentValidatorFinder(_dep.Object);
            var vals   = finder.FindValidators(RequestData.BuildRequestData(helper.ViewContext, ReflectionHelper.GetAccessor <TestViewModel>(x => x.Nested1.ReallyLongName), typeof(TestInputModel)));

            vals.Count().ShouldBe(1);
            vals.First().DisplayName.ShouldBe("ReallyLongLongNameWhen");
        }
コード例 #25
0
        public void InputOfBoolPropertyWhosValueIsFalseShouldBeCheckedIfErrorOnModelAndChecked()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);

            helper.ViewContext.SetError("IsCorrect", "True,False");

            var tag = helper.Input(x => x.IsCorrect);

            tag.Attr("checked").ShouldBe("true");
        }
コード例 #26
0
        public void PropertyInViewModelButNotInInputModel()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);

            helper.ViewContext.HttpContext.Items[TagGenerator.FORMINPUTTYPE] = typeof(TestInputModel);
            Assert.DoesNotThrow(() =>
            {
                var tag = helper.Input(x => x.NotInInputModel);
            });
        }
コード例 #27
0
        public void InputOfListSelectItemListPropertyShouldGenerateSelectTag()
        {
            var model = new TestViewModel()
            {
                Dropdown = new List <SelectListItem>()
            };
            var helper = MvcMockHelpers.GetHtmlHelper(model);
            var tag    = helper.Input(x => x.Dropdown);

            tag.TagName().ShouldBe("select");
        }
コード例 #28
0
        public void DisplayOfPropertyShouldByDefaultUseSpanTag()
        {
            var model = new TestViewModel()
            {
                Name = "Test"
            };
            var tag = MvcMockHelpers.GetHtmlHelper(model).Display(x => x.Name);

            tag.TagName().ShouldBe("span");
            tag.Text().ShouldBe(model.Name);
        }
コード例 #29
0
        public void PropertyWithEqualFluentValidationShouldHaveDataAttributeValEqualTo()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);

            helper.ViewContext.HttpContext.Items[TagGenerator.FORMINPUTTYPE] = typeof(TestInputModel);
            var tag = helper.Input(x => x.PasswordConfirm);

            tag.Data("val-equalto").ShouldBe("'Password Confirm' should be equal to 'Password'.");
            tag.Data("val-equalto-other").ShouldBe("*.Password");
        }
コード例 #30
0
        public void PropertyWithLengthFluentValidationDefinedShouldHaveMaxLengthAttribute()
        {
            var model  = new TestViewModel();
            var helper = MvcMockHelpers.GetHtmlHelper(model);

            helper.ViewContext.HttpContext.Items[TagGenerator.FORMINPUTTYPE] = typeof(TestInputModel);
            var tag = helper.Input(x => x.Name);

            tag.HasAttr("maxlength").ShouldBe(true);
            tag.Attr("maxlength").ShouldBe(TestInputValidator.NAME_MAXLENGTH.ToString());
        }