Exemplo n.º 1
0
 protected override void setupContext()
 {
     matchingBinder = MockRepository.GenerateStub <IModelBinder>();
     matchingBinder.Stub(x => x.Matches(_type)).Return(true);
     matchingBinder.Stub(x => x.Bind(_type, data)).Throw(new Exception("fake message"));
     binders.Add(matchingBinder);
 }
Exemplo n.º 2
0
        protected override void setupContext()
        {
            binder1        = MockRepository.GenerateMock <IModelBinder>();
            binder2        = MockRepository.GenerateMock <IModelBinder>();
            matchingBinder = MockRepository.GenerateMock <IModelBinder>();

            binder1.Stub(x => x.Matches(typeof(BinderTarget))).Return(false);
            binder2.Stub(x => x.Matches(typeof(BinderTarget))).Return(false);
            matchingBinder.Stub(x => x.Matches(typeof(BinderTarget))).Return(true);

            expectedResult = new BinderTarget();

            binders.Add(binder1);
            binders.Add(binder2);
            binders.Add(matchingBinder);

            matchingBinder.Stub(x => x.Bind(typeof(BinderTarget), data)).Return(expectedResult);
        }
        public void should_throw_fubu_exception_2201()
        {
            matchingBinder = MockRepository.GenerateStub <IModelBinder>();
            matchingBinder.Stub(x => x.Matches(_type)).Return(true);
            matchingBinder.Stub(x => x.Bind(_type, null)).IgnoreArguments().Throw(new Exception("fake message"));



            var exception = Exception <FubuException> .ShouldBeThrownBy(() =>
            {
                BindingScenario <BinderTarget> .Build(x =>
                {
                    x.Registry.Add(matchingBinder);
                });
            });

            exception.ShouldNotBeNull().Message.ShouldEqual(
                "FubuCore Error 2201:  \nFatal error while binding model of type {0}.  See inner exception"
                .ToFormat(_type.AssemblyQualifiedName));
        }
        public void should_resolve_the_requested_model_with_the_first_binder_that_matches()
        {
            binder1 = MockRepository.GenerateMock <IModelBinder>();
            binder2 = MockRepository.GenerateMock <IModelBinder>();

            binder1.Stub(x => x.Matches(typeof(BinderTarget))).Return(false);
            binder2.Stub(x => x.Matches(typeof(BinderTarget))).Return(false);

            expectedResult = new BinderTarget();

            matchingBinder = new StubBinder(expectedResult);

            BindingScenario <BinderTarget> .Build(x =>
            {
                x.Registry.Add(binder1);
                x.Registry.Add(binder2);
                x.Registry.Add(matchingBinder);
            }).ShouldBeTheSameAs(expectedResult);
        }
        public void SetUp()
        {
            Init();
            _returnValue = "ReturnedValue";
            _defaultValue = "DefaultValue";
            _returnInt = 1;

            _defaultBinder = MockRepository.GenerateMock<IModelBinder>();
            _defaultBinder.Stub(m => m.BindModel(null, null)).IgnoreArguments().Return(_defaultValue);

            _binders = new Collection<IFilteredModelBinder>
                           {
                               new TestFilteredModelBinder(ModelType, _returnValue),
                               new TestFilteredModelBinder(typeof(int), _returnInt),
                           };
            _filteredBinder = new FilteredModelBinder(_binders, _defaultBinder);
        }