public void ProducesContentAttribute_FormatFilterAttribute_Active() { // Arrange var producesContentAttribute = new ProducesAttribute("application/xml"); var formatFilter = new Mock <IFormatFilter>(); formatFilter .Setup(f => f.GetFormat(It.IsAny <ActionContext>())) .Returns("xml"); var filters = new IFilterMetadata[] { producesContentAttribute, formatFilter.Object }; var resultExecutingContext = CreateResultExecutingContext(filters); var next = new ResultExecutionDelegate( () => Task.FromResult(CreateResultExecutedContext(resultExecutingContext))); // Act producesContentAttribute.OnResultExecuting(resultExecutingContext); // Assert var objectResult = Assert.IsType <ObjectResult>(resultExecutingContext.Result); Assert.Equal(0, objectResult.ContentTypes.Count); }
public void ProducesAttribute_SetsContentType() { // Arrange var mediaType1 = new StringSegment("application/json"); var mediaType2 = new StringSegment("text/json;charset=utf-8"); var producesContentAttribute = new ProducesAttribute("application/json", "text/json;charset=utf-8"); var resultExecutingContext = CreateResultExecutingContext(new IFilterMetadata[] { producesContentAttribute }); var next = new ResultExecutionDelegate( () => Task.FromResult(CreateResultExecutedContext(resultExecutingContext))); // Act producesContentAttribute.OnResultExecuting(resultExecutingContext); // Assert var objectResult = resultExecutingContext.Result as ObjectResult; Assert.Equal(2, objectResult.ContentTypes.Count); MediaTypeAssert.Equal(mediaType1, objectResult.ContentTypes[0]); MediaTypeAssert.Equal(mediaType2, objectResult.ContentTypes[1]); }
/// <inheritdoc /> void IResultFilter.OnResultExecuting(ResultExecutingContext context) => Produces.OnResultExecuting(context);