private void Initialize( Mock <HttpContext> httpContext, string format = null, FormatSource?place = null) { // Setup options on mock service provider MockOptions = new MvcOptions(); MockFormatterMappingOptions = new MvcFormatterMappingOptions(); // Set up default output formatters. MockOptions.OutputFormatters.Add(new HttpNoContentOutputFormatter()); MockOptions.OutputFormatters.Add(new StringOutputFormatter()); MockOptions.OutputFormatters.Add(new JsonOutputFormatter()); // Set up default mapping for json extensions to content type MockFormatterMappingOptions.FormatterMappings.SetMediaTypeMappingForFormat( "json", MediaTypeHeaderValue.Parse("application/json")); var mvcOptions = new Mock <IOptions <MvcFormatterMappingOptions> >(); mvcOptions.Setup(o => o.Options).Returns(MockFormatterMappingOptions); IOptions = mvcOptions.Object; // Setup MVC services on mock service provider MockActionContext = CreateMockActionContext(httpContext, format, place); var scopedInstance = new Mock <IScopedInstance <ActionContext> >(); scopedInstance.Setup(s => s.Value).Returns(MockActionContext); ScopedInstance = scopedInstance.Object; }
private void Initialize( Mock<HttpContext> httpContext, string format = null, FormatSource? place = null) { // Setup options on mock service provider MockOptions = new MvcOptions(); MockFormatterMappingOptions = new MvcFormatterMappingOptions(); // Set up default output formatters. MockOptions.OutputFormatters.Add(new HttpNoContentOutputFormatter()); MockOptions.OutputFormatters.Add(new StringOutputFormatter()); MockOptions.OutputFormatters.Add(new JsonOutputFormatter()); // Set up default mapping for json extensions to content type MockFormatterMappingOptions.FormatterMappings.SetMediaTypeMappingForFormat( "json", MediaTypeHeaderValue.Parse("application/json")); var mvcOptions = new Mock<IOptions<MvcFormatterMappingOptions>>(); mvcOptions.Setup(o => o.Options).Returns(MockFormatterMappingOptions); IOptions = mvcOptions.Object; // Setup MVC services on mock service provider MockActionContext = CreateMockActionContext(httpContext, format, place); var scopedInstance = new Mock<IScopedInstance<ActionContext>>(); scopedInstance.Setup(s => s.Value).Returns(MockActionContext); ScopedInstance = scopedInstance.Object; }