コード例 #1
0
        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());
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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());
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        public Notification Run(RemoteFieldRule remote, string value)
        {
            var target  = _resolver.Resolve(remote.Accessor, value);
            var context = _validator.ContextFor(target, new Notification(target.GetType()));

            remote.Rule.Validate(remote.Accessor, context);

            return(context.Notification);
        }
コード例 #7
0
ファイル: IRuleRunner.cs プロジェクト: RyanHauert/fubumvc
        public Notification Run(RemoteFieldRule remote, string value)
        {
            var target = _resolver.Resolve(remote.Accessor, value);
            var context = _validator.ContextFor(target, new Notification(target.GetType()));

            remote.Rule.Validate(remote.Accessor, context);

            return context.Notification;
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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));
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        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);
        }