Пример #1
0
        public void Setup_SetsUpModelBinders()
        {
            // Arrange
            var mvcOptions = new MvcOptions();
            var setup1     = new CoreMvcOptionsSetup();
            var setup2     = new MvcOptionsSetup();

            // Act
            setup1.Configure(mvcOptions);
            setup2.Configure(mvcOptions);

            // Assert
            var i = 0;

            Assert.Equal(13, mvcOptions.ModelBinders.Count);
            Assert.IsType(typeof(BinderTypeBasedModelBinder), mvcOptions.ModelBinders[i++]);
            Assert.IsType(typeof(ServicesModelBinder), mvcOptions.ModelBinders[i++]);
            Assert.IsType(typeof(BodyModelBinder), mvcOptions.ModelBinders[i++]);
            Assert.IsType(typeof(HeaderModelBinder), mvcOptions.ModelBinders[i++]);
            Assert.IsType(typeof(TypeConverterModelBinder), mvcOptions.ModelBinders[i++]);
            Assert.IsType(typeof(TypeMatchModelBinder), mvcOptions.ModelBinders[i++]);
            Assert.IsType(typeof(CancellationTokenModelBinder), mvcOptions.ModelBinders[i++]);
            Assert.IsType(typeof(ByteArrayModelBinder), mvcOptions.ModelBinders[i++]);
            Assert.IsType(typeof(FormFileModelBinder), mvcOptions.ModelBinders[i++]);
            Assert.IsType(typeof(FormCollectionModelBinder), mvcOptions.ModelBinders[i++]);
            Assert.IsType(typeof(GenericModelBinder), mvcOptions.ModelBinders[i++]);
            Assert.IsType(typeof(MutableObjectModelBinder), mvcOptions.ModelBinders[i++]);
            Assert.IsType(typeof(ComplexModelDtoModelBinder), mvcOptions.ModelBinders[i++]);
        }
Пример #2
0
        public void Setup_IgnoresAcceptHeaderHavingWildCardMediaAndSubMediaTypes()
        {
            // Arrange
            var mvcOptions = new MvcOptions();
            var setup      = new CoreMvcOptionsSetup();

            // Act
            setup.Configure(mvcOptions);

            // Assert
            Assert.False(mvcOptions.RespectBrowserAcceptHeader);
        }
Пример #3
0
        public void Setup_SetsUpModelValidatorProviders()
        {
            // Arrange
            var mvcOptions = new MvcOptions();
            var setup1     = new CoreMvcOptionsSetup();
            var setup2     = new MvcOptionsSetup();

            // Act
            setup1.Configure(mvcOptions);
            setup2.Configure(mvcOptions);

            // Assert
            Assert.Equal(2, mvcOptions.ModelValidatorProviders.Count);
            Assert.IsType <DefaultModelValidatorProvider>(mvcOptions.ModelValidatorProviders[0]);
            Assert.IsType <DataAnnotationsModelValidatorProvider>(mvcOptions.ModelValidatorProviders[1]);
        }
Пример #4
0
        public void Setup_SetsUpValueProviders()
        {
            // Arrange
            var mvcOptions = new MvcOptions();
            var setup1     = new CoreMvcOptionsSetup();
            var setup2     = new MvcOptionsSetup();

            // Act
            setup1.Configure(mvcOptions);
            setup2.Configure(mvcOptions);

            // Assert
            var valueProviders = mvcOptions.ValueProviderFactories;

            Assert.Equal(3, valueProviders.Count);
            Assert.IsType <RouteValueValueProviderFactory>(valueProviders[0]);
            Assert.IsType <QueryStringValueProviderFactory>(valueProviders[1]);
            Assert.IsType <FormValueProviderFactory>(valueProviders[2]);
        }
Пример #5
0
        public void Setup_SetsUpInputFormatters()
        {
            // Arrange
            var mvcOptions = new MvcOptions();
            var setup1     = new CoreMvcOptionsSetup();
            var setup2     = new MvcOptionsSetup();
            var setup3     = new JsonMvcOptionsSetup(new OptionsManager <MvcJsonOptions>(
                                                         Enumerable.Empty <IConfigureOptions <MvcJsonOptions> >()));

            // Act
            setup1.Configure(mvcOptions);
            setup2.Configure(mvcOptions);
            setup3.Configure(mvcOptions);

            // Assert
            Assert.Equal(2, mvcOptions.InputFormatters.Count);
            Assert.IsType <JsonInputFormatter>(mvcOptions.InputFormatters[0]);
            Assert.IsType <JsonPatchInputFormatter>(mvcOptions.InputFormatters[1]);
        }
Пример #6
0
        public void Setup_SetsUpOutputFormatters()
        {
            // Arrange
            var mvcOptions = new MvcOptions();
            var setup1     = new CoreMvcOptionsSetup();
            var setup2     = new MvcOptionsSetup();
            var setup3     = new JsonMvcOptionsSetup(new OptionsManager <MvcJsonOptions>(
                                                         Enumerable.Empty <IConfigureOptions <MvcJsonOptions> >()));

            // Act
            setup1.Configure(mvcOptions);
            setup2.Configure(mvcOptions);
            setup3.Configure(mvcOptions);

            // Assert
            Assert.Equal(4, mvcOptions.OutputFormatters.Count);
            Assert.IsType <HttpNoContentOutputFormatter>(mvcOptions.OutputFormatters[0]);
            Assert.IsType <StringOutputFormatter>(mvcOptions.OutputFormatters[1]);
            Assert.IsType <StreamOutputFormatter>(mvcOptions.OutputFormatters[2]);
            Assert.IsType <JsonOutputFormatter>(mvcOptions.OutputFormatters[3]);
        }
Пример #7
0
        public void Setup_SetsUpExcludeFromValidationDelegates()
        {
            // Arrange
            var mvcOptions = new MvcOptions();
            var setup1     = new CoreMvcOptionsSetup();
            var setup2     = new MvcOptionsSetup();

            // Act
            setup1.Configure(mvcOptions);
            setup2.Configure(mvcOptions);

            // Assert
            Assert.Equal(8, mvcOptions.ValidationExcludeFilters.Count);
            var i = 0;

            // Verify if the delegates registered by default exclude the given types.
            Assert.IsType(typeof(SimpleTypesExcludeFilter), mvcOptions.ValidationExcludeFilters[i++]);

            Assert.IsType(typeof(DefaultTypeBasedExcludeFilter), mvcOptions.ValidationExcludeFilters[i]);
            var typeFilter
                = Assert.IsType <DefaultTypeBasedExcludeFilter>(mvcOptions.ValidationExcludeFilters[i++]);

            Assert.Equal(typeFilter.ExcludedType, typeof(Type));

            Assert.IsType(typeof(DefaultTypeBasedExcludeFilter), mvcOptions.ValidationExcludeFilters[i]);
            var cancellationTokenFilter
                = Assert.IsType <DefaultTypeBasedExcludeFilter>(mvcOptions.ValidationExcludeFilters[i++]);

            Assert.Equal(cancellationTokenFilter.ExcludedType, typeof(System.Threading.CancellationToken));

            Assert.IsType(typeof(DefaultTypeBasedExcludeFilter), mvcOptions.ValidationExcludeFilters[i]);
            var formFileFilter
                = Assert.IsType <DefaultTypeBasedExcludeFilter>(mvcOptions.ValidationExcludeFilters[i++]);

            Assert.Equal(formFileFilter.ExcludedType, typeof(Http.IFormFile));

            Assert.IsType(
                typeof(DefaultTypeBasedExcludeFilter),
                mvcOptions.ValidationExcludeFilters[i]);
            var formCollectionFilter
                = Assert.IsType <DefaultTypeBasedExcludeFilter>(mvcOptions.ValidationExcludeFilters[i++]);

            Assert.Equal(formCollectionFilter.ExcludedType, typeof(Http.IFormCollection));

            Assert.IsType(typeof(DefaultTypeBasedExcludeFilter), mvcOptions.ValidationExcludeFilters[i]);
            var xObjectFilter
                = Assert.IsType <DefaultTypeBasedExcludeFilter>(mvcOptions.ValidationExcludeFilters[i++]);

            Assert.Equal(xObjectFilter.ExcludedType, typeof(XObject));

            Assert.IsType(typeof(DefaultTypeBasedExcludeFilter), mvcOptions.ValidationExcludeFilters[i]);
            var jTokenFilter
                = Assert.IsType <DefaultTypeBasedExcludeFilter>(mvcOptions.ValidationExcludeFilters[i++]);

            Assert.Equal(jTokenFilter.ExcludedType, typeof(JToken));

            Assert.IsType(typeof(DefaultTypeNameBasedExcludeFilter), mvcOptions.ValidationExcludeFilters[i]);
            var xmlNodeFilter =
                Assert.IsType <DefaultTypeNameBasedExcludeFilter>(mvcOptions.ValidationExcludeFilters[i++]);

            Assert.Equal(xmlNodeFilter.ExcludedTypeName, "System.Xml.XmlNode");
        }