public void hash_is_repeatable() { var r1 = RemoteFieldRule.For <RequiredFieldRule>(accessorFor(x => x.Name)); var r2 = RemoteFieldRule.For <RequiredFieldRule>(accessorFor(x => x.Name)); r1.ToHash().ShouldEqual(r2.ToHash()); }
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 equality_check_negative_accessor() { var r1 = RemoteFieldRule.For <RequiredFieldRule>(accessorFor(x => x.Name)); var r2 = RemoteFieldRule.For <RequiredFieldRule>(accessorFor(x => x.Test)); r1.ShouldNotEqual(r2); }
public void equality_check_negative_type() { var accessor = accessorFor(x => x.Name); var r1 = RemoteFieldRule.For <RequiredFieldRule>(accessor); var r2 = RemoteFieldRule.For <EmailFieldRule>(accessor); r1.ShouldNotEqual(r2); }
public void equality_check() { var accessor = accessorFor(x => x.Name); var r1 = RemoteFieldRule.For <RequiredFieldRule>(accessor); var r2 = RemoteFieldRule.For <RequiredFieldRule>(accessor); r1.ShouldEqual(r2); }
public void finds_the_rule_by_the_hash() { var a1 = ReflectionHelper.GetAccessor <RuleGraphModel>(x => x.FirstName); var r1 = new RequiredFieldRule(); theGraph.RegisterRule(a1, r1); var remote = RemoteFieldRule.For(a1, r1); theGraph.RuleFor(remote.ToHash()).ShouldEqual(remote); }
protected override void configure(FubuRegistry registry) { registry.Actions.IncludeType <CreateUserEndpoint>(); registry.Import <FubuMvcValidation>(); theUserService = new UserService(); registry.Services(r => r.SetServiceIfNone <IUserService>(theUserService)); var rule = RemoteFieldRule.For(ReflectionHelper.GetAccessor <CreateUser>(x => x.Username), new UniqueUsernameRule()); theField = new ValidateField { Hash = rule.ToHash(), Value = "joel_arnold" }; theUserService.AddUser(theField.Value); }
protected override void beforeEach() { theValue = "Testing"; theAccessor = ReflectionHelper.GetAccessor <RunnerTarget>(x => x.Name); theTarget = new RunnerTarget(); theContext = ValidationContext.For(theTarget); theRule = new RecordingFieldValidationRule(); theRemoteRule = RemoteFieldRule.For(theAccessor, theRule); MockFor <IValidationTargetResolver>().Stub(x => x.Resolve(theAccessor, theValue)).Return(theTarget); MockFor <IValidator>().Stub(x => x.ContextFor(Arg <object> .Is.Same(theTarget), Arg <Notification> .Is.NotNull)).Return(theContext); ClassUnderTest.Run(theRemoteRule, theValue); }
public void registers_rules() { var a1 = ReflectionHelper.GetAccessor <RuleGraphModel>(x => x.FirstName); var a2 = ReflectionHelper.GetAccessor <RuleGraphModel>(x => x.LastName); var r1 = new RequiredFieldRule(); var r2 = new MinimumLengthRule(5); theGraph.RegisterRule(a1, r1); theGraph.RegisterRule(a1, r2); theGraph.RegisterRule(a2, r1); theGraph.RulesFor(a1).ShouldHaveTheSameElementsAs(RemoteFieldRule.For(a1, r1), RemoteFieldRule.For(a1, r2)); theGraph.RulesFor(a2).ShouldHaveTheSameElementsAs(RemoteFieldRule.For(a2, r1)); }
protected override void beforeEach() { var theAccessor = ReflectionHelper.GetAccessor <ValidateFieldTarget>(x => x.Name); theGraph = new RemoteRuleGraph(); theGraph.RegisterRule(theAccessor, new RequiredFieldRule()); Services.Inject(theGraph); theRemoteRule = RemoteFieldRule.For(theAccessor, new RequiredFieldRule()); theInputModel = new ValidateField { Hash = theRemoteRule.ToHash(), Value = "Test" }; theNotification = new Notification(); theContinuation = new AjaxContinuation(); MockFor <IRuleRunner>().Stub(x => x.Run(theRemoteRule, theInputModel.Value)).Return(theNotification); MockFor <IAjaxContinuationResolver>().Stub(x => x.Resolve(theNotification)).Return(theContinuation); }