Exemplo n.º 1
0
        public void Should_only_bind_from_Form_by_default()
        {
            _context.HttpContext.Request.QueryString["cust.Id"] = "5";

            var binder = new CastleBindAttribute();
            var customer = (Customer)binder.BindModel(_context, CreateContext("cust", typeof(Customer)));

            Assert.That(customer, Is.Null);
        }
Exemplo n.º 2
0
        public void Should_be_configurable_to_bind_from_other_sources()
        {
            _context.HttpContext.Request.QueryString["cust.Id"] = "5";

            var binder = new CastleBindAttribute(RequestStore.QueryString);
            var customer = (Customer)binder.BindModel(_context, CreateContext("cust", typeof(Customer)));

            Assert.That(customer.Id, Is.EqualTo(5));
        }
Exemplo n.º 3
0
        public void Should_bind_using_parameter_name()
        {
            _context.HttpContext.Request.Form["cust.Id"] = "5";
            _context.HttpContext.Request.Form["cust.Name"] = "Jeremy";

            var binder = new CastleBindAttribute();
            object value = binder.BindModel(_context, CreateContext("cust", typeof(Customer)));
            var customer = value as Customer;

            Assert.That(customer, Is.Not.Null);
            Assert.That(customer.Name, Is.EqualTo("Jeremy"));
            Assert.That(customer.Id, Is.EqualTo(5));
        }
Exemplo n.º 4
0
        public void When_the_controller_implements_ICastleBindingContainer_and_the_binder_is_already_set_then_it_should_be_used()
        {
            var castleBinder = new DataBinder();
            var controller = new CastleBindableController {Binder = castleBinder};

            _context = CreateControllerContext(controller);
            _context.HttpContext.Request.Form["cust.Id"] = "Fail";

            var binder = new CastleBindAttribute();
            binder.BindModel(_context, CreateContext("cust", typeof(Customer)));

            Assert.That(controller.Binder, Is.SameAs(castleBinder));
            Assert.That(castleBinder.ErrorList["Id"], Is.Not.Null);
        }
Exemplo n.º 5
0
        public void Should_return_null_when_unable_to_find_model_name()
        {
            var binder = new CastleBindAttribute();
            object value = binder.BindModel(_context, CreateContext("cust", typeof(Customer)));
            var customer = value as Customer;

            Assert.That(customer, Is.Null);
        }
Exemplo n.º 6
0
        public void When_the_controller_implements_ICastleBindingContainer_then_the_binder_should_be_made_accessible_to_the_controller()
        {
            var controller = new CastleBindableController();
            _context = CreateControllerContext(controller);

            var binder = new CastleBindAttribute();
            binder.BindModel(_context, CreateContext("cust", typeof(Customer)));

            Assert.That(controller.Binder, Is.Not.Null);
        }