public void determine_the_mode_uses_the_last_matching_policy() { var accessor = SingleProperty.Build <ValidationModeTarget>(x => x.Property); var services = new InMemoryServiceLocator(); services.Add(new AccessorRules()); var mode = ValidationMode.Triggered; var p1 = MockRepository.GenerateStub <IValidationModePolicy>(); p1.Stub(x => x.Matches(services, accessor)).Return(true); p1.Stub(x => x.DetermineMode(services, accessor)).Return(ValidationMode.Live); var p2 = MockRepository.GenerateStub <IValidationModePolicy>(); p2.Stub(x => x.Matches(services, accessor)).Return(true); p2.Stub(x => x.DetermineMode(services, accessor)).Return(mode); var node = new ValidationNode(); node.DefaultMode(ValidationMode.Live); node.RegisterPolicy(p1); node.RegisterPolicy(p2); node.As <IValidationNode>().DetermineMode(services, accessor).ShouldEqual(mode); }
public void hash_is_unique_by_rule_model_and_accessor() { var r1 = RemoteFieldRule.For <RequiredFieldRule>(SingleProperty.Build <SomeNamespace.Model>(e => e.Property)); var r2 = RemoteFieldRule.For <RequiredFieldRule>(SingleProperty.Build <OtherNamespace.Model>(e => e.Property)); r1.ToHash().ShouldNotEqual(r2.ToHash()); }
public void singleProperty_can_get_child_accessor() { var expected = ReflectionHelper.GetAccessor <ChildTarget>(c => c.GrandChild.Name); SingleProperty.Build <Target>(t => t.Child.GrandChild). GetChildAccessor <GrandChildTarget>(t => t.Name).ShouldBe(expected); }
public void singleProperty_property_names_contains_single_value() { var propertyNames = SingleProperty.Build <Target>(t => t.Child.GrandChild.Name).PropertyNames; propertyNames.Length.ShouldBe(1); propertyNames.ShouldContain("Name"); }
public void throws_when_targeting_messages_to_an_unknown_accessor() { var rule = FieldEqualityRule.For <FieldEqualityTarget>(x => x.Value1, x => x.Value2); var accessor = SingleProperty.Build <FieldEqualityTarget>(x => x.Other); Exception <ArgumentOutOfRangeException> .ShouldBeThrownBy(() => rule.ReportMessagesFor(accessor)); }
public void build_single_property() { var prop1 = SingleProperty.Build <Target>("Child"); var prop2 = SingleProperty.Build <Target>(x => x.Child); prop1.ShouldBe(prop2); prop1.Name.ShouldBe("Child"); prop1.OwnerType.ShouldBe(typeof(Target)); }
public void GetValueFromSingleProperty() { var target = new Target { Name = "Jeremy" }; var property = SingleProperty.Build <Target>(x => x.Name); property.GetValue(target).ShouldBe("Jeremy"); }
public void route_input_should_substitute_method() { SingleProperty accessor = SingleProperty.Build <SampleViewModel>(x => x.InPath); var viewModel = new SampleViewModel { InPath = "5" }; var routeInput = new RouteParameter(accessor); routeInput.Substitute(viewModel, "test/edit/{InPath}").ShouldEqual("test/edit/5"); }
public void SetValueFromSingleProperty() { var target = new Target { Name = "Jeremy" }; var property = SingleProperty.Build <Target>(x => x.Name); property.SetValue(target, "Justin"); target.Name.ShouldBe("Justin"); }
public void equals_for_a_single_property() { var prop1 = SingleProperty.Build <Target>(x => x.Name); var prop2 = SingleProperty.Build <Target>(x => x.Name); var prop3 = SingleProperty.Build <Target>(x => x.Child); prop1.ShouldBe(prop2); prop1.ShouldNotBe(prop3); prop1.Equals(null).ShouldBeFalse(); prop1.Equals(prop1).ShouldBeTrue(); prop1.ShouldBe(prop1); prop1.Equals((object)null).ShouldBeFalse(); prop1.Equals(42).ShouldBeFalse(); }
public void configure_a_field_equality_rule() { var myToken = StringToken.FromKeyString("MyKeys:MyToken", "Passwords must match"); theRules .Property(x => x.Password) .Matches(x => x.ConfirmPassword) .ReportErrorsOn(x => x.ConfirmPassword) .UseToken(myToken); var rule = theRules.As <IValidationSource>().RulesFor(typeof(ClassValidationRulesTarget)).OfType <FieldEqualityRule>().Single(); rule.Property1.ShouldEqual(SingleProperty.Build <ClassValidationRulesTarget>(x => x.Password)); rule.Property2.ShouldEqual(SingleProperty.Build <ClassValidationRulesTarget>(x => x.ConfirmPassword)); rule.Token.ShouldEqual(myToken); }
public void GetFieldNameFromSingleProperty() { var property = SingleProperty.Build <Target>(x => x.Name); ((object)property.FieldName).ShouldBe("Name"); }
private bool matches(Expression <Func <AccessorRulesValidationModeTarget, object> > expression) { var accessor = SingleProperty.Build(expression); return(new AccessorRulesValidationModePolicy().Matches(services(), accessor)); }
private ValidationMode modeFor(Expression <Func <AccessorRulesValidationModeTarget, object> > expression) { var accessor = SingleProperty.Build(expression); return(new AccessorRulesValidationModePolicy().DetermineMode(services(), accessor)); }
public FakeSubject() : base(SingleProperty.Build <FakeSubject>(m => m.ElementId)) { }
public void singleProperty_property_names_contains_single_value() { SingleProperty.Build <Target>(t => t.Child.GrandChild.Name).PropertyNames. ShouldHaveCount(1).ShouldContain("Name"); }
public SecondSubject() : base(SingleProperty.Build <SecondSubject>(m => m.ElementId)) { }
public void GetNameFromSingleProperty() { var property = SingleProperty.Build <Target>(x => x.Name); property.Name.ShouldBe("Name"); }
private Accessor accessorFor <T>(Expression <Func <T, object> > expression) { return(SingleProperty.Build(expression)); }