Exemplo n.º 1
0
 public TestMvcOptions()
 {
     Options = new MvcOptions();
     MvcCoreMvcOptionsSetup.ConfigureMvc(Options);
     MvcDataAnnotationsMvcOptionsSetup.ConfigureMvc(Options);
     MvcJsonMvcOptionsSetup.ConfigureMvc(Options, SerializerSettingsProvider.CreateSerializerSettings());
 }
Exemplo n.º 2
0
        public TestMvcOptions()
        {
            Value = new MvcOptions();
            var optionsSetup = new MvcCoreMvcOptionsSetup(new TestHttpRequestStreamReaderFactory());

            optionsSetup.Configure(Value);

            var collection = new ServiceCollection().AddOptions();

            collection.AddSingleton <ICompositeMetadataDetailsProvider, DefaultCompositeMetadataDetailsProvider>();
            collection.AddSingleton <IModelMetadataProvider, DefaultModelMetadataProvider>();
            collection.AddSingleton <IValidationAttributeAdapterProvider, ValidationAttributeAdapterProvider>();
            MvcDataAnnotationsMvcOptionsSetup.ConfigureMvc(
                Value,
                collection.BuildServiceProvider());

            var loggerFactory      = new LoggerFactory();
            var serializerSettings = SerializerSettingsProvider.CreateSerializerSettings();

            MvcJsonMvcOptionsSetup.ConfigureMvc(
                Value,
                serializerSettings,
                loggerFactory,
                ArrayPool <char> .Shared,
                new DefaultObjectPoolProvider());
        }
 public JsonPatchInputFormatter(ILogger logger)
     : this(
         logger,
         SerializerSettingsProvider.CreateSerializerSettings(),
         ArrayPool <char> .Shared,
         new DefaultObjectPoolProvider())
 {
 }
Exemplo n.º 4
0
        public TestMvcOptions()
        {
            Value = new MvcOptions();
            MvcCoreMvcOptionsSetup.ConfigureMvc(Value);
            var collection = new ServiceCollection().AddOptions();

            MvcDataAnnotationsMvcOptionsSetup.ConfigureMvc(
                Value,
                collection.BuildServiceProvider());
            MvcJsonMvcOptionsSetup.ConfigureMvc(Value, SerializerSettingsProvider.CreateSerializerSettings());
        }
Exemplo n.º 5
0
 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();
 }
Exemplo n.º 6
0
        public void When_Formatting_A_Representation_With_HalPlusJson_Then_Json_Is_Returned()
        {
            // ARRANGE
            var serializerSettings = SerializerSettingsProvider.CreateSerializerSettings();
            var mediaFormatter     = new JsonHalMediaTypeOutputFormatter(serializerSettings, ArrayPool <char> .Shared);

            using (var stream = new MemoryStream())
            {
                using (var textWritter = new StreamWriter(stream))
                {
                    // ACT
                    mediaFormatter.WriteObject(textWritter, resource);
                    textWritter.Flush();

                    // ASSERT
                    stream.Seek(0, SeekOrigin.Begin);
                    var serialisedResult = new StreamReader(stream).ReadToEnd();
                    Assert.NotEmpty(serialisedResult);
                }
            }
        }
Exemplo n.º 7
0
        public void ConfigureServices(IServiceCollection services)
        {
            var connectionString = Configuration["Data:DefaultConnection:ConnectionString"];

            services.AddLogging();
            services.AddSwaggerGen();
            services.ConfigureSwaggerDocument(opts => {
                opts.SingleApiVersion(new Info
                {
                    Version        = "v1",
                    Title          = "Beers",
                    TermsOfService = "None"
                });
            });
            services.AddMvc(options =>
            {
                options.OutputFormatters.Add(new XmlHalMediaTypeOutputFormatter());
                options.OutputFormatters.Add(new JsonHalMediaTypeOutputFormatter(SerializerSettingsProvider.CreateSerializerSettings(), ArrayPool <char> .Shared));
            });
            services.AddEntityFramework()
            .AddSqlServer()
            .AddDbContext <BeerDbContext>(opt => opt.UseSqlServer(connectionString));
            services.AddTransient <IRepository, BeerRepository>();
        }
        public async Task ChangesTo_DefaultSerializerSettings_AfterSerialization_NoEffect()
        {
            // Arrange
            var person = new User()
            {
                Name = "John", Age = 35
            };
            var expectedOutput = JsonConvert.SerializeObject(
                person,
                SerializerSettingsProvider.CreateSerializerSettings());

            var jsonFormatter = new JsonOutputFormatter();

            // This will create a serializer - which gets cached.
            var outputFormatterContext1 = GetOutputFormatterContext(person, typeof(User));
            await jsonFormatter.WriteResponseBodyAsync(outputFormatterContext1, Encoding.UTF8);

            // These changes should have no effect.
            jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            jsonFormatter.SerializerSettings.Formatting       = Formatting.Indented;

            var outputFormatterContext2 = GetOutputFormatterContext(person, typeof(User));

            // Act
            await jsonFormatter.WriteResponseBodyAsync(outputFormatterContext2, Encoding.UTF8);

            // Assert
            var body = outputFormatterContext2.HttpContext.Response.Body;

            Assert.NotNull(body);
            body.Position = 0;

            var content = new StreamReader(body, Encoding.UTF8).ReadToEnd();

            Assert.Equal(expectedOutput, content);
        }
Exemplo n.º 9
0
 public JsonOutputFormatter()
     : this(SerializerSettingsProvider.CreateSerializerSettings())
 {
 }
Exemplo n.º 10
0
 public JsonOutputFormatter()
     : this(SerializerSettingsProvider.CreateSerializerSettings(), ArrayPool <char> .Shared)
 {
 }
Exemplo n.º 11
0
 public JsonInputFormatter(ILogger logger)
     : this(logger, SerializerSettingsProvider.CreateSerializerSettings(), ArrayPool <char> .Shared)
 {
 }
Exemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of <see cref="JsonInputFormatter"/>.
 /// </summary>
 /// <param name="logger">The <see cref="ILogger"/>.</param>
 public JsonInputFormatter(ILogger logger)
     : this(logger, SerializerSettingsProvider.CreateSerializerSettings())
 {
 }