Exemplo n.º 1
0
        public void TypeStampIsFoundOnPageTest()
        {
            var valueProvider        = MockRepository.GenerateMock <IValueProvider>();
            var propertyNameProvider = MockRepository.GenerateMock <IPropertyNameProvider>();

            propertyNameProvider.Expect(e => e.CreatePropertyName("test", DerivedTypeModelBinderCache.TypeStampFieldName)).Return("foo");
            valueProvider.Expect(b => b.ContainsPrefix("foo"))
            .Return(true);
            valueProvider.Expect(e => e.GetValue("foo")).Return(new ValueProviderResult(new[] { "bar" }, "foo",
                                                                                        CultureInfo.InvariantCulture));


            var typeStampOperator = new TypeStampOperator();

            Assert.That(typeStampOperator.DetectTypeStamp(
                            new ModelBindingContext
            {
                ModelMetadata =
                    new ModelMetadata(new EmptyModelMetadataProvider(), typeof(DerivedTypeModelBinder),
                                      null, typeof(DerivedTypeModelBinderTests), "propertyName"
                                      ),
                ModelName     = "test",
                ValueProvider = valueProvider
            }, propertyNameProvider), Is.EqualTo("bar"));
        }
Exemplo n.º 2
0
        public void TypeStampFormattedReturnIsInvalid()
        {
            var valueProvider        = MockRepository.GenerateMock <IValueProvider>();
            var propertyNameProvider = MockRepository.GenerateMock <IPropertyNameProvider>();

            propertyNameProvider.Expect(e => e.CreatePropertyName("test", DerivedTypeModelBinderCache.TypeStampFieldName)).Return("foo");
            valueProvider.Expect(b => b.ContainsPrefix("foo"))
            .Return(true);
            valueProvider.Expect(e => e.GetValue("foo")).Return(new ValueProviderResult(new DerivedTypeModelBinder(), "foo",
                                                                                        CultureInfo.InvariantCulture));

            var typeStampOperator = new TypeStampOperator();

            Assert.Throws <InvalidOperationException>(() => typeStampOperator.DetectTypeStamp(
                                                          new ModelBindingContext
            {
                ModelMetadata =
                    new ModelMetadata(new EmptyModelMetadataProvider(), typeof(DerivedTypeModelBinder),
                                      null, typeof(DerivedTypeModelBinderTests), "propertyName"
                                      ),
                ModelName     = "test",
                ValueProvider = valueProvider
            }, propertyNameProvider));
        }