public void PropertyWithDataTypeTextAttributeShouldMakeTheTagATextArea() { var model = new TestViewModel(); var tag = MvcMockHelpers.GetHtmlHelper(model).Input(x => x.Text); tag.TagName().ShouldBe("textarea"); }
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); }
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\" />"); }
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()); }
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); }
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()); }
public void InputOfPropertyShouldBeCheckboxIfPropertyIsABool() { var model = new TestViewModel(); var helper = MvcMockHelpers.GetHtmlHelper(model); var tag = helper.Input(x => x.IsCorrect); tag.Attr("type").ShouldBe("checkbox"); }
public void PropertyOfTypeIntShouldHaveDigitsClass() { var model = new TestViewModel(); var helper = MvcMockHelpers.GetHtmlHelper(model); var tag = helper.Input(x => x.Int); tag.HasClass("digits").ShouldBe(true); }
public void PropertyOfTypeDoubleShouldHaveNumberClass() { var model = new TestViewModel(); var helper = MvcMockHelpers.GetHtmlHelper(model); var tag = helper.Input(x => x.Double); tag.HasClass("number").ShouldBe(true); }
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()); }
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"); }
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"); }
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"); }
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"); }
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()); }
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\" />"); }
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); }
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); }
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); }
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"); }
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); }
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); }
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."); }
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"); }
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"); }
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); }); }
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"); }
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); }
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"); }
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()); }