コード例 #1
0
        public void FormatterMappings_SetFormatMapping_FormatEmpty()
        {
            // Arrange
            var options = new FormatterMappings();
            var format = "";
            var expected = "Value cannot be null or empty." + Environment.NewLine + "Parameter name: format";

            // Act and assert
            var exception = Assert.Throws<ArgumentException>(() => options.SetMediaTypeMappingForFormat(
                format,
                MediaTypeHeaderValue.Parse("application/xml")));
            Assert.Equal(expected, exception.Message);
        }
コード例 #2
0
        public void FormatterMappings_Wildcardformat(string format)
        {
            // Arrange
            var options = new FormatterMappings();
            var expected = string.Format(@"The media type ""{0}"" is not valid. MediaTypes containing wildcards (*) " + 
                "are not allowed in formatter mappings.", format);

            // Act and assert
            var exception = Assert.Throws<ArgumentException>(() => options.SetMediaTypeMappingForFormat(
                "star", 
                MediaTypeHeaderValue.Parse(format)));
            Assert.Equal(expected, exception.Message);
        }
コード例 #3
0
        public void FormatterMappings_SetFormatMapping_DiffSetGetFormat(string setFormat, string contentType, string getFormat)
        {
            // Arrange
            var mediaType = MediaTypeHeaderValue.Parse(contentType);
            var options = new FormatterMappings();
            options.SetMediaTypeMappingForFormat(setFormat, mediaType);

            // Act 
            var returnMediaType = options.GetMediaTypeMappingForFormat(getFormat);

            // Assert
            Assert.Equal(mediaType, returnMediaType);
        }
コード例 #4
0
        public void FormatterMappings_Invalid_Period()
        {
            // Arrange
            var options = new FormatterMappings();
            var format = ".";
            var expected = string.Format(@"The format provided is invalid '{0}'. A format must be a non-empty file-" + 
                "extension, optionally prefixed with a '.' character.", format);

            // Act and assert
            var exception = Assert.Throws<ArgumentException>(() => options.SetMediaTypeMappingForFormat(
                format,
                MediaTypeHeaderValue.Parse("application/xml")));
            Assert.Equal(expected, exception.Message);
        }
コード例 #5
0
ファイル: MvcOptions.cs プロジェクト: notami18/Mvc
 public MvcOptions()
 {
     CacheProfiles = new Dictionary<string, CacheProfile>(StringComparer.OrdinalIgnoreCase);
     Conventions = new List<IApplicationModelConvention>();
     Filters = new List<IFilterMetadata>();
     FormatterMappings = new FormatterMappings();
     InputFormatters = new List<IInputFormatter>();
     OutputFormatters = new List<IOutputFormatter>();
     ModelBinders = new List<IModelBinder>();
     ModelMetadataDetailsProviders = new List<IMetadataDetailsProvider>();
     ModelValidatorProviders = new List<IModelValidatorProvider>();
     ValidationExcludeFilters = new List<IExcludeTypeValidationFilter>();
     ValueProviderFactories = new List<IValueProviderFactory>();
 }
コード例 #6
0
        public void FormatterMappings_Wildcardformat(string format)
        {
            // Arrange
            var options  = new FormatterMappings();
            var expected = string.Format(@"The media type ""{0}"" is not valid. MediaTypes containing wildcards (*) " +
                                         "are not allowed in formatter mappings.", format);

            // Act and assert
            var exception = Assert.Throws <ArgumentException>(() => options.SetMediaTypeMappingForFormat(
                                                                  "star",
                                                                  MediaTypeHeaderValue.Parse(format)));

            Assert.Equal(expected, exception.Message);
        }
コード例 #7
0
        public void FormatterMappings_SetFormatMapping_DiffSetGetFormat(string setFormat, string contentType, string getFormat)
        {
            // Arrange
            var mediaType = MediaTypeHeaderValue.Parse(contentType);
            var options   = new FormatterMappings();

            options.SetMediaTypeMappingForFormat(setFormat, mediaType);

            // Act
            var returnMediaType = options.GetMediaTypeMappingForFormat(getFormat);

            // Assert
            Assert.Equal(mediaType, returnMediaType);
        }
コード例 #8
0
        public void FormatterMappings_SetFormatMapping_FormatEmpty()
        {
            // Arrange
            var options  = new FormatterMappings();
            var format   = "";
            var expected = "Value cannot be null or empty." + Environment.NewLine + "Parameter name: format";

            // Act and assert
            var exception = Assert.Throws <ArgumentException>(() => options.SetMediaTypeMappingForFormat(
                                                                  format,
                                                                  MediaTypeHeaderValue.Parse("application/xml")));

            Assert.Equal(expected, exception.Message);
        }
コード例 #9
0
ファイル: MvcOptions.cs プロジェクト: phinq19/git_example
 public MvcOptions()
 {
     CacheProfiles                 = new Dictionary <string, CacheProfile>(StringComparer.OrdinalIgnoreCase);
     Conventions                   = new List <IApplicationModelConvention>();
     Filters                       = new FilterCollection();
     FormatterMappings             = new FormatterMappings();
     InputFormatters               = new FormatterCollection <IInputFormatter>();
     OutputFormatters              = new FormatterCollection <IOutputFormatter>();
     ModelBinders                  = new List <IModelBinder>();
     ModelBindingMessageProvider   = new ModelBindingMessageProvider();
     ModelMetadataDetailsProviders = new List <IMetadataDetailsProvider>();
     ModelValidatorProviders       = new List <IModelValidatorProvider>();
     ValueProviderFactories        = new List <IValueProviderFactory>();
 }
コード例 #10
0
 public MvcOptions()
 {
     Conventions            = new List <IApplicationModelConvention>();
     ModelBinders           = new List <ModelBinderDescriptor>();
     ViewEngines            = new List <ViewEngineDescriptor>();
     ValueProviderFactories = new List <ValueProviderFactoryDescriptor>();
     OutputFormatters       = new List <OutputFormatterDescriptor>();
     InputFormatters        = new List <InputFormatterDescriptor>();
     Filters                       = new List <IFilter>();
     FormatterMappings             = new FormatterMappings();
     ValidationExcludeFilters      = new List <ExcludeValidationDescriptor>();
     ModelMetadataDetailsProviders = new List <IMetadataDetailsProvider>();
     ModelValidatorProviders       = new List <ModelValidatorProviderDescriptor>();
     CacheProfiles                 = new Dictionary <string, CacheProfile>(StringComparer.OrdinalIgnoreCase);
 }
コード例 #11
0
        public void FormatterMappings_Invalid_Period()
        {
            // Arrange
            var options  = new FormatterMappings();
            var format   = ".";
            var expected = string.Format(@"The format provided is invalid '{0}'. A format must be a non-empty file-" +
                                         "extension, optionally prefixed with a '.' character.", format);

            // Act and assert
            var exception = Assert.Throws <ArgumentException>(() => options.SetMediaTypeMappingForFormat(
                                                                  format,
                                                                  MediaTypeHeaderValue.Parse("application/xml")));

            Assert.Equal(expected, exception.Message);
        }
コード例 #12
0
ファイル: MvcOptions.cs プロジェクト: AndersBillLinden/Mvc
 public MvcOptions()
 {
     Conventions = new List<IApplicationModelConvention>();
     ModelBinders = new List<ModelBinderDescriptor>();
     ViewEngines = new List<ViewEngineDescriptor>();
     ValueProviderFactories = new List<ValueProviderFactoryDescriptor>();
     OutputFormatters = new List<OutputFormatterDescriptor>();
     InputFormatters = new List<InputFormatterDescriptor>();
     Filters = new List<IFilter>();
     FormatterMappings = new FormatterMappings();
     ValidationExcludeFilters = new List<ExcludeValidationDescriptor>();
     ModelMetadataDetailsProviders = new List<IMetadataDetailsProvider>();
     ModelValidatorProviders = new List<ModelValidatorProviderDescriptor>();
     CacheProfiles = new Dictionary<string, CacheProfile>(StringComparer.OrdinalIgnoreCase);
 }
コード例 #13
0
ファイル: MvcOptions.cs プロジェクト: wahabshah/Mvc
 public MvcOptions()
 {
     Conventions            = new List <IApplicationModelConvention>();
     ModelBinders           = new List <IModelBinder>();
     ViewEngines            = new List <ViewEngineDescriptor>();
     ValueProviderFactories = new List <IValueProviderFactory>();
     OutputFormatters       = new List <IOutputFormatter>();
     InputFormatters        = new List <IInputFormatter>();
     Filters                       = new List <IFilter>();
     FormatterMappings             = new FormatterMappings();
     ValidationExcludeFilters      = new List <IExcludeTypeValidationFilter>();
     ModelMetadataDetailsProviders = new List <IMetadataDetailsProvider>();
     ModelValidatorProviders       = new List <IModelValidatorProvider>();
     ClientModelValidatorProviders = new List <IClientModelValidatorProvider>();
     CacheProfiles                 = new Dictionary <string, CacheProfile>(StringComparer.OrdinalIgnoreCase);
     HtmlHelperOptions             = new HtmlHelperOptions();
     SerializerSettings            = SerializerSettingsProvider.CreateSerializerSettings();
 }
コード例 #14
0
ファイル: MvcOptions.cs プロジェクト: RehanSaeed/Mvc
 public MvcOptions()
 {
     Conventions = new List<IApplicationModelConvention>();
     ModelBinders = new List<IModelBinder>();
     ViewEngines = new List<ViewEngineDescriptor>();
     ValueProviderFactories = new List<IValueProviderFactory>();
     OutputFormatters = new List<IOutputFormatter>();
     InputFormatters = new List<IInputFormatter>();
     Filters = new List<IFilter>();
     FormatterMappings = new FormatterMappings();
     ValidationExcludeFilters = new List<IExcludeTypeValidationFilter>();
     ModelMetadataDetailsProviders = new List<IMetadataDetailsProvider>();
     ModelValidatorProviders = new List<IModelValidatorProvider>();
     ClientModelValidatorProviders = new List<IClientModelValidatorProvider>();
     CacheProfiles = new Dictionary<string, CacheProfile>(StringComparer.OrdinalIgnoreCase);
     HtmlHelperOptions = new HtmlHelperOptions();
     SerializerSettings = SerializerSettingsProvider.CreateSerializerSettings();
 }
コード例 #15
0
        public void FormatterMappings_ClearFormatMapping(string format, bool expected)
        {
            // Arrange
            var options   = new FormatterMappings();
            var mediaType = MediaTypeHeaderValue.Parse("application/xml");

            options.SetMediaTypeMappingForFormat("xml", mediaType);
            mediaType = MediaTypeHeaderValue.Parse("application/json");
            options.SetMediaTypeMappingForFormat("json", mediaType);
            mediaType = MediaTypeHeaderValue.Parse("application/foo");
            options.SetMediaTypeMappingForFormat("foo", mediaType);
            mediaType = MediaTypeHeaderValue.Parse("application/bar");
            options.SetMediaTypeMappingForFormat("bar", mediaType);

            // Act
            var cleared = options.ClearMediaTypeMappingForFormat(format);

            // Assert
            Assert.Equal(expected, cleared);
            Assert.Null(options.GetMediaTypeMappingForFormat(format));
        }
コード例 #16
0
        public void FormatterMappings_ClearFormatMapping(string format, bool expected)
        {
            // Arrange
            var options = new FormatterMappings();
            var mediaType = MediaTypeHeaderValue.Parse("application/xml");
            options.SetMediaTypeMappingForFormat("xml", mediaType);
            mediaType = MediaTypeHeaderValue.Parse("application/json");
            options.SetMediaTypeMappingForFormat("json", mediaType);
            mediaType = MediaTypeHeaderValue.Parse("application/foo");
            options.SetMediaTypeMappingForFormat("foo", mediaType);
            mediaType = MediaTypeHeaderValue.Parse("application/bar");
            options.SetMediaTypeMappingForFormat("bar", mediaType);

            // Act 
            var cleared = options.ClearMediaTypeMappingForFormat(format);

            // Assert
            Assert.Equal(expected, cleared);
            Assert.Null(options.GetMediaTypeMappingForFormat(format));
        }