public void matches_negative_with_no_overrides_for_this_accessor() { theOverrides.Add <OverrideTarget>(x => x.Age, new ElementTagOverride <SimpleBuilder>("C1", "P1")); var request = ElementRequest.For <OverrideTarget>(x => x.Name); thePolicy.Matches(request).ShouldBeFalse(); }
public void adds_the_rangelength_data_attribute_for_range_length_rule() { var theRequest = ElementRequest.For(new TargetWithRangeLength(), x => x.Value); var values = tagFor(theRequest).Data("rangelength").As <IDictionary <string, object> >(); values["min"].ShouldEqual(5); values["max"].ShouldEqual(10); }
public void SetUp() { theStrategy = new CssValidationAnnotationStrategy(); theTag = new HtmlTag("input"); theRequest = ElementRequest.For <CssTarget>(x => x.Name); theRequest.ReplaceTag(theTag); }
public void the_stars_completely_align_and_we_have_a_positive_match() { theOverrides.Add <OverrideTarget>(x => x.Age, new ElementTagOverride <SimpleBuilder>("C1", "P1")); var request = ElementRequest.For <OverrideTarget>(x => x.Age); thePolicy.Matches(request).ShouldBeTrue(); }
public void matches_negative_with_an_override_for_the_accessor_but_the_wrong_profile() { theOverrides.Add <OverrideTarget>(x => x.Age, new ElementTagOverride <SimpleBuilder>("C1", "Wrong")); var request = ElementRequest.For <OverrideTarget>(x => x.Age); thePolicy.Matches(request).ShouldBeFalse(); }
public void SetUp() { theLocalizedHeaderForTheProperty = LocalizationManager.GetHeader <LabelTarget>(x => x.Name); theElementRequest = ElementRequest.For <LabelTarget>(new LabelTarget(), x => x.Name); theElementRequest.ElementId = "Name"; theLabelTag = new LabelBuilder().Build(theElementRequest); }
public void build_label() { var request = ElementRequest.For <Address>(x => x.Address1); request.ElementId = "Address1Id"; new DefaultLabelBuilder().Build(request) .ToString() .ShouldEqual("<label for=\"Address1Id\">Address 1</label>"); }
public void build_with_true() { var request = ElementRequest.For <BooleanTarget>(x => x.Accredited); request.Model = new BooleanTarget { Accredited = true }; builder.Build(request).ToString().ShouldEqual("<input type=\"checkbox\" checked=\"true\" />"); }
protected override void beforeEach() { theElementRequest = ElementRequest.For <Address>(new Address(), x => x.Address1); MockFor <IElementNamingConvention>().Stub( x => x.GetName(theElementRequest.HolderType(), theElementRequest.Accessor)) .Return("the element name"); ClassUnderTest.Activate(theElementRequest); }
public void modify_adds_the_class_to_the_current_tag() { var request = ElementRequest.For <AttributeTarget>(x => x.Decorated); request.ReplaceTag(new HtmlTag("div")); theModifier.Modify(request); request.CurrentTag.HasClass("fizz").ShouldBeTrue(); }
public void get_the_builder() { theOverrides.Add <OverrideTarget>(x => x.Age, new ElementTagOverride <SimpleBuilder>("C1", "P1")); theOverrides.Add <OverrideTarget>(x => x.Name, new ElementTagOverride <ComplexBuilder>("C1", "P1")); var request = ElementRequest.For <OverrideTarget>(x => x.Age); var request2 = ElementRequest.For <OverrideTarget>(x => x.Name); thePolicy.BuilderFor(request).ShouldBeOfType <SimpleBuilder>(); thePolicy.BuilderFor(request2).ShouldBeOfType <ComplexBuilder>(); }
public void SetUp() { theRule = new RequiredFieldRule(); theElementRequest = ElementRequest.For <FieldValidationModifierTarget>(x => x.Name); theMatchingStrategy = MockRepository.GenerateStub <IValidationAnnotationStrategy>(); theOtherStrategy = MockRepository.GenerateStub <IValidationAnnotationStrategy>(); theMatchingStrategy.Stub(x => x.Matches(theRule)).Return(true); theOtherStrategy.Stub(x => x.Matches(theRule)).Return(false); theModifier = new FieldValidationModifier(new[] { theMatchingStrategy, theOtherStrategy }); theModifier.ModifyFor(theRule, theElementRequest); }
public void modify_request() { var modifier = new AddClassModifier("fizz"); var request = ElementRequest.For <Address>(x => x.Address1); request.ReplaceTag(new HtmlTag("div")); request.ReplaceTag(new HtmlTag("div")); modifier.Modify(request); request.CurrentTag.HasClass("fizz").ShouldBeTrue(); request.OriginalTag.HasClass("fizz").ShouldBeFalse(); }
public void SetUp() { theRequest = ElementRequest.For <FieldValidationModifierTarget>(x => x.Name); theModifier = new FieldValidationElementModifier(); theFieldModifier = MockRepository.GenerateStub <IFieldValidationModifier>(); theRequest.ReplaceTag(new HtmlTag("input")); theServices = new InMemoryServiceLocator(); theServices.Add(ValidationGraph.BasicGraph()); theServices.Add(theFieldModifier); theRequest.Attach(theServices); }
public void SetUp() { theRequest = ElementRequest.For <Address>(x => x.Address1); theAddress = new Address { Address1 = "22 Cherry Tree Lane" }; var services = new InMemoryServiceLocator(); services.Add(new Stringifier()); theRequest.Attach(services); theRequest.Model = theAddress; }
public void get_access_rights() { var services = MockRepository.GenerateMock <IServiceLocator>(); var rightsService = MockRepository.GenerateMock <IFieldAccessService>(); services.Stub(x => x.GetInstance <IFieldAccessService>()).Return(rightsService); var theModel = new Model1(); var request = ElementRequest.For <Model1>(theModel, x => x.Child.Name, services); rightsService.Stub(x => x.RightsFor(request)).Return(AccessRight.ReadOnly); request.AccessRights().ShouldEqual(AccessRight.ReadOnly); }
public void Holder_type_with_a_model_and_service_locator() { var services = MockRepository.GenerateMock <IServiceLocator>(); var theModel = new Model1(); var request = ElementRequest.For <Model1>(theModel, x => x.Child.Name, services); var resolver = MockRepository.GenerateMock <ITypeResolver>(); services.Stub(x => x.GetInstance <ITypeResolver>()).Return(resolver); resolver.Stub(x => x.ResolveType(theModel)).Return(GetType()); request.HolderType().ShouldEqual(GetType()); }
public HtmlTag get_target_Category_Profile(OverrideRequest request) { var elemRequest = ElementRequest.For <OverrideTarget>(x => x.Name); if (request.Category == ElementConstants.Display) { return(_generator.DisplayFor(elemRequest, request.Profile)); } if (request.Category == ElementConstants.Label) { return(_generator.LabelFor(elemRequest, request.Profile)); } return(_generator.InputFor(elemRequest, request.Profile)); }
public void SetUp() { theModifier = new RemoteValidationElementModifier(); theTag = new HtmlTag("input"); theRequest = ElementRequest.For <RemoteTarget>(x => x.Username); theRequest.ReplaceTag(theTag); theRemoteGraph = new RemoteRuleGraph(); theRemoteRule = theRemoteGraph.RegisterRule(theRequest.Accessor, new UniqueUsernameRule()); theUrls = new StubUrlRegistry(); theServices = new InMemoryServiceLocator(); theServices.Add(theRemoteGraph); theServices.Add(theUrls); theRequest.Attach(theServices); }
public static HtmlTag FormFor(this ISuperGlueView view, object input) { var stringInput = input as string; if (stringInput != null) { return(FormFor(view, stringInput)); } var request = ElementRequest.For(input, x => x); request.Attach(x => view.Environment.Resolve(x)); return(view .Environment .GetHtmlConventionSettings() .ConventionLibrary .TagLibrary .PlanFor(request, category: "Form") .Build(request)); }
public void StringValue_delegates_to_Stringifier() { var stringifier = new Stringifier(); stringifier.AddStrategy(new StringifierStrategy { Matches = r => true, StringFunction = r => "*" + r.RawValue + "*" }); var services = new InMemoryServiceLocator(); services.Add(stringifier); services.Add <IDisplayFormatter>(new DisplayFormatter(services, stringifier)); var request = ElementRequest.For <Model1>(new Model1 { Child = new Model2 { Name = "Little Lindsey" } }, x => x.Child.Name); request.Attach(services); request.StringValue().ShouldEqual("*Little Lindsey*"); }
private AccessRight RightsFor <T>(T model, Expression <Func <T, object> > expression) { var request = ElementRequest.For(model, expression); return(_service.RightsFor(request)); }
public void no_date_for_other_types() { new DateElementModifier().Matches(ElementRequest.For <DateElementTarget>(x => x.NoDate)).ShouldBeFalse(); }
public void adds_the_date_css_class_for_DateTime() { tagFor(ElementRequest.For <DateElementTarget>(x => x.Date)).HasClass("date").ShouldBeTrue(); }
public void matches_negative() { theModifier.Matches(ElementRequest.For <AttributeTarget>(x => x.NotDecorated)).ShouldBeFalse(); }
public void matches_positive() { theModifier.Matches(ElementRequest.For <AttributeTarget>(x => x.Decorated)).ShouldBeTrue(); }
public void Holder_type_with_no_model() { var request = ElementRequest.For <Model1>(null, x => x.Child.Name); request.HolderType().ShouldEqual(typeof(Model1)); }
public void Holder_type_with_a_model_but_no_services() { var request = ElementRequest.For <Model1>(new SubModel1(), x => x.Child.Name); request.HolderType().ShouldEqual(typeof(SubModel1)); }
public void matches_negative_with_no_overrides() { var request = ElementRequest.For <OverrideTarget>(x => x.Name); thePolicy.Matches(request).ShouldBeFalse(); }
public void SetUp() { services = new SelfMockingServiceLocator(); services.Stub <ITypeResolver>(new TypeResolver()); theRequest = ElementRequest.For(new TheModel(), x => x.Name, services); }