public void ShouldReturnNullForUnregisteredAction()
 {
     var call = new ActionCall(typeof(UnRegisteredAction), ReflectionHelper.GetMethod<UnRegisteredAction>(a => a.Get(new object())));
     var context = new ValidationFailure(call, new Notification(typeof(object)), new object());
     var request = descriptor.DescribeModelFor(context);
     request.ShouldBeNull();
 }
 public void Handle(ValidationFailure context)
 {
     _flash.Flash(context.Notification.AllMessages.Select(m => m.ToString()));
     var continuation = FubuContinuation.RedirectTo<PlaceOrderStart>();
     _request.Set(continuation);
     _handler.Handle();
 }
        public Type DescribeModelFor(ValidationFailure context)
        {
            ActionCall getCall;
            var attributes = context.Target.Method.GetCustomAttributes(false);
            var handler = context.Target.Method.GetCustomAttributes(false).OfType<ValidationHandlerAttribute>().FirstOrDefault();

            if (handler != null)
            {
                getCall = graph
                    .Behaviors
                    .Where(chain => chain.FirstCall() != null && chain.FirstCall().InputType() == handler.InputType)
                    .Select(chain => chain.FirstCall())
                    .FirstOrDefault();
            }
            else
            {
                var targetNamespace = context.Target.HandlerType.Namespace;
                getCall = graph
                    .Behaviors
                    .Where(chain => chain.FirstCall() != null && chain.FirstCall().HandlerType.Namespace == targetNamespace
                        && chain.Route.AllowedHttpMethods.Contains("GET"))
                    .Select(chain => chain.FirstCall())
                    .FirstOrDefault();
            }

            if (getCall == null)
            {
                return null;
            }

            return getCall.InputType();
        }
 public void ShouldGetRequestForViewModel()
 {
     var call = new ActionCall(typeof (RegisterAction),ReflectionHelper.GetMethod<RegisterAction>(a => a.Post(new RegisterViewModel())));
     var context = new ValidationFailure(call, new Notification(typeof(RegisterViewModel)), new RegisterViewModel());
     var request = descriptor.DescribeModelFor(context);
     request.ShouldEqual(typeof (RegisterRequest));
 }
        public bool Matches(ValidationFailure context)
        {
            var type = context.Target.OutputType();
            if(type == null)
            {
                return false;
            }

            return typeof (AjaxContinuation).IsAssignableFrom(type);
        }
 public void SetUp()
 {
     request = new InMemoryFubuRequest();
     handler = MockRepository.GenerateStub<IValidationContinuationHandler>();
     flash = MockRepository.GenerateStub<IFlash>();
     policy = new PlaceOrderValidationFailurePolicy(request, handler, flash);
     var notification = Notification.Invalid();
     var failure = new ValidationFailure(null, notification, null);
     policy.Handle(failure);
 }
        public void Handle(ValidationFailure context)
        {
            var notification = _request.Get<Notification>();
            var modelType = context.InputType();
            var policy = _policies.LastOrDefault(p => p.Matches(context));
            if(policy == null)
            {
                throw new FubuMVCValidationException(1001, notification, "No validation failure policy found for {0}", modelType.FullName);
            }

            policy.Handle(context);
        }
        public Type DescribeModelFor(ValidationFailure context)
        {
            var handlerType = context.Target.HandlerType;

            var getCall = graph
                .Behaviors
                .Where(chain => chain.FirstCall() != null
                                && chain.FirstCall().HandlerType == handlerType
                                && chain.Route.AllowedHttpMethods.Contains("GET"))
                .Select(chain => chain.FirstCall())
                .FirstOrDefault();

            if(getCall == null)
                return null;

            return getCall.InputType();
        }
        public Type DescribeModelFor(ValidationFailure context)
        {
            // Remember, behavior chains can be identified by the input model type
            // The IFubuContinuationModelDescriptor interface is used to describe the input model type of the chain
            // that we want to transfer to

            // we're going to query the BehaviorGraph to find the corresponding GET for the POST
            // obviously, we'd need to make this smarter but this is just a simple example
            var targetNamespace = context.Target.HandlerType.Namespace;
            var getCall = _graph
                .Behaviors
                .Where(chain => chain.FirstCall() != null && chain.FirstCall().HandlerType.Namespace == targetNamespace
                    && chain.Route.AllowedHttpMethods.Contains("GET"))
                .Select(chain => chain.FirstCall())
                .FirstOrDefault();

            if(getCall == null)
            {
                return null;
            }

            return getCall.InputType();
        }
 public FubuContinuation Resolve(ValidationFailure context)
 {
     return _continuationBuilder(_resolver.ModelFor(context));
 }
 public object ModelFor(ValidationFailure context)
 {
     return _converter(context);
 }
 public bool Matches(ValidationFailure context)
 {
     return context.InputType() == typeof (PickupOrder);
 }
 public bool Matches(ValidationFailure context)
 {
     return _predicate(context);
 }
 public void Handle(ValidationFailure context)
 {
     var continuation = _continuationResolver.Resolve(context.Notification);
     _writer.Write(continuation.ToDictionary(), MimeType.Json.ToString());
 }
Ejemplo n.º 15
0
 public bool Equals(ValidationFailure other)
 {
     if (ReferenceEquals(null, other)) return false;
     if (ReferenceEquals(this, other)) return true;
     return Equals(other._target, _target);
 }
 public FubuContinuation Resolve(ValidationFailure context)
 {
     return _continuation;
 }
 public Type DescribeModelFor(ValidationFailure context)
 {
     return _provider.GetDescriptor(context.Target);
 }
 public void Handle(ValidationFailure context)
 {
     var continuation = _continuationResolver.Resolve(context);
     _request.Set(continuation);
     _handler.Handle();
 }