public void BindTriesToCallBasedOnActionWhenFactoryMethodIsEmpty()
        {
            var actionName = "Create";
            var attr       = new CslaBindAttribute {
                Method = ""
            };
            var mockInst = new Mock <IModelInstantiator>();

            mockInst
            .Expect(i => i.CallFactoryMethod(actionName, typeof(MyBO), typeof(MyBO), It.Is <object[]>(arg => arg == null || arg.Length == 0)))
            .Returns(MyBO.NewMyBO)
            .Verifiable();

            var binder = new CslaBindModelBinder(attr, mockInst.Object);

            var controllerContext = GetControllerContext();

            controllerContext.RouteData.Values["action"] = actionName;

            var modelContext = new ModelBindingContext()
            {
                ModelType             = typeof(MyBO),
                ModelName             = "MyBO",
                ValueProvider         = new ValueProviderDictionary(null),
                FallbackToEmptyPrefix = true
            };

            var result = binder.BindModel(controllerContext, modelContext);

            Assert.IsInstanceOfType(result, typeof(MyBO));
            mockInst.Verify();
        }
        public void BindCallsCorrectMethodOnFactoryMethodWithArgument()
        {
            var fMethod = "GetMyBO";
            var attr    = new CslaBindAttribute {
                Method = fMethod, Arguments = "id"
            };
            var mockInst = new Mock <IModelInstantiator>();

            mockInst
            .Expect(i => i.CallFactoryMethod(typeof(MyBO), typeof(MyBO), fMethod, It.Is <object[]>(arg => arg.Length == 1 && (int)arg[0] == 10)))
            .Returns(MyBO.GetMyBO(10))
            .Verifiable();

            var binder = new CslaBindModelBinder(attr, mockInst.Object);

            var modelContext = new ModelBindingContext()
            {
                ModelType     = typeof(MyBO),
                ModelName     = "MyBO",
                ValueProvider = new ValueProviderDictionary(null)
                {
                    { "id", new ValueProviderResult("10", "10", null) }
                },
                FallbackToEmptyPrefix = true
            };

            var result = binder.BindModel(null, modelContext);

            Assert.IsInstanceOfType(result, typeof(MyBO));
            mockInst.Verify();
        }