Ejemplo n.º 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());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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());
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 7
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;
        }
        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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
        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 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);
        }
        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);
        }