예제 #1
0
        public void Create_WhenBindingSourceIsFromHeader_NoInnerBinderAvailable_ReturnsNull()
        {
            // Arrange
            var provider = new HeaderModelBinderProvider();
            var context  = GetTestModelBinderProviderContext(typeof(string));

            context.OnCreatingBinder(modelMetadata => null);
            context.BindingInfo.BindingSource = BindingSource.Header;

            // Act
            var result = provider.GetBinder(context);

            // Assert
            Assert.Null(result);
        }
        public void Create_WhenModelTypeIsUnsupportedType_ReturnsNull(Type modelType)
        {
            // Arrange
            var provider = new HeaderModelBinderProvider();

            var context = new TestModelBinderProviderContext(modelType);

            context.BindingInfo.BindingSource = BindingSource.Header;

            // Act
            var result = provider.GetBinder(context);

            // Assert
            Assert.Null(result);
        }
        public void Create_WhenBindingSourceIsFromHeader_ReturnsBinder()
        {
            // Arrange
            var provider = new HeaderModelBinderProvider();

            var context = new TestModelBinderProviderContext(typeof(string));

            context.BindingInfo.BindingSource = BindingSource.Header;

            // Act
            var result = provider.GetBinder(context);

            // Assert
            Assert.IsType <HeaderModelBinder>(result);
        }
        public void Create_WhenBindingSourceIsNotFromHeader_ReturnsNull(BindingSource source)
        {
            // Arrange
            var provider = new HeaderModelBinderProvider();

            var context = new TestModelBinderProviderContext(typeof(string));

            context.BindingInfo.BindingSource = source;

            // Act
            var result = provider.GetBinder(context);

            // Assert
            Assert.Null(result);
        }
예제 #5
0
        public void Create_WhenBindingSourceIsNotFromHeader_ReturnsNull(BindingSource source)
        {
            // Arrange
            var provider   = new HeaderModelBinderProvider();
            var testBinder = Mock.Of <IModelBinder>();
            var context    = GetTestModelBinderProviderContext(typeof(string));

            context.OnCreatingBinder(modelMetadata => testBinder);
            context.BindingInfo.BindingSource = source;

            // Act
            var result = provider.GetBinder(context);

            // Assert
            Assert.Null(result);
        }
예제 #6
0
        public void Create_WhenBindingSourceIsFromHeader_ReturnsNull_ForNonSimpleModelType(Type modelType)
        {
            // Arrange
            var provider   = new HeaderModelBinderProvider();
            var testBinder = Mock.Of <IModelBinder>();
            var context    = GetTestModelBinderProviderContext(modelType);

            context.OnCreatingBinder(modelMetadata => testBinder);
            context.BindingInfo.BindingSource = BindingSource.Header;

            // Act
            var result = provider.GetBinder(context);

            // Assert
            Assert.Null(result);
        }
예제 #7
0
        public void Create_WhenBindingSourceIsFromHeader_ReturnsNull_ForNonStringTypes_And_CompatVersion_2_0(
            Type modelType)
        {
            // Arrange
            var provider = new HeaderModelBinderProvider();
            var context  = GetTestModelBinderProviderContext(
                modelType,
                allowBindingHeaderValuesToNonStringModelTypes: false);

            context.BindingInfo.BindingSource = BindingSource.Header;

            // Act
            var result = provider.GetBinder(context);

            // Assert
            Assert.Null(result);
        }
예제 #8
0
        public void Create_WhenBindingSourceIsFromHeader_ReturnsBinder_ForNullableSimpleTypes(Type modelType)
        {
            // Arrange
            var provider   = new HeaderModelBinderProvider();
            var testBinder = Mock.Of <IModelBinder>();
            var context    = GetTestModelBinderProviderContext(modelType);

            context.OnCreatingBinder(modelMetadata => testBinder);
            context.BindingInfo.BindingSource = BindingSource.Header;

            // Act
            var result = provider.GetBinder(context);

            // Assert
            var headerModelBinder = Assert.IsType <HeaderModelBinder>(result);

            Assert.Same(testBinder, headerModelBinder.InnerModelBinder);
        }