public void ProducesResponseTypeAttribute_SetsContentType() { // Arrange var mediaType1 = new StringSegment("application/json"); var mediaType2 = new StringSegment("text/json;charset=utf-8"); var producesContentAttribute = new ProducesResponseTypeAttribute(typeof(void), StatusCodes.Status200OK, "application/json", "text/json;charset=utf-8"); // Assert Assert.Equal(2, producesContentAttribute.ContentTypes.Count); MediaTypeAssert.Equal(mediaType1, producesContentAttribute.ContentTypes[0]); MediaTypeAssert.Equal(mediaType2, producesContentAttribute.ContentTypes[1]); }
public void Constructor_SetsContentTypeAndParameters() { // Arrange var stream = Stream.Null; var contentType = "text/plain; charset=us-ascii; p1=p1-value"; var expectedMediaType = contentType; // Act var result = new FileStreamResult(stream, contentType); // Assert Assert.Equal(stream, result.FileStream); MediaTypeAssert.Equal(expectedMediaType, result.ContentType); }
public void Constructor_SetsContentTypeAndParameters() { // Arrange var fileContents = new byte[0]; var contentType = "text/plain; charset=us-ascii; p1=p1-value"; var expectedMediaType = contentType; // Act var result = new FileContentResult(fileContents, contentType); // Assert Assert.Same(fileContents, result.FileContents); MediaTypeAssert.Equal(expectedMediaType, result.ContentType); }
public void Constructor_SetsContentTypeAndParameters() { // Arrange var path = Path.GetFullPath("helllo.txt"); var contentType = "text/plain; charset=us-ascii; p1=p1-value"; var expectedMediaType = contentType; // Act var result = new TestVirtualFileResult(path, contentType); // Assert Assert.Equal(path, result.FileName); MediaTypeAssert.Equal(expectedMediaType, result.ContentType); }
public async Task ViewComponentResult_SetsContentTypeHeader( string contentType, string expectedContentType) { // Arrange var methodInfo = typeof(TextViewComponent).GetMethod(nameof(TextViewComponent.Invoke)); var descriptor = new ViewComponentDescriptor() { FullName = "Full.Name.Text", ShortName = "Text", TypeInfo = typeof(TextViewComponent).GetTypeInfo(), MethodInfo = methodInfo, Parameters = methodInfo.GetParameters(), }; var actionContext = CreateActionContext(descriptor); var contentTypeBeforeViewResultExecution = contentType?.ToString(); var viewComponentResult = new ViewComponentResult() { Arguments = new { name = "World!" }, ViewComponentName = "Text", ContentType = contentType, TempData = _tempDataDictionary, }; // Act await viewComponentResult.ExecuteResultAsync(actionContext); // Assert var resultContentType = actionContext.HttpContext.Response.ContentType; MediaTypeAssert.Equal(expectedContentType, resultContentType); // Check if the original instance provided by the user has not changed. // Since we do not have access to the new instance created within the view executor, // check if at least the content is the same. var contentTypeAfterViewResultExecution = contentType?.ToString(); MediaTypeAssert.Equal(contentTypeBeforeViewResultExecution, contentTypeAfterViewResultExecution); }
public async Task ContentResult_ExecuteResultAsync_Response_NullContent_SetsContentTypeAndEncoding() { // Arrange var contentResult = new ContentResult { Content = null, ContentType = new MediaTypeHeaderValue("text/plain") { Encoding = Encoding.Unicode }.ToString() }; var httpContext = GetHttpContext(); var actionContext = GetActionContext(httpContext); // Act await contentResult.ExecuteResultAsync(actionContext); // Assert MediaTypeAssert.Equal("text/plain; charset=utf-16", httpContext.Response.ContentType); }
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]); }
public void Constructor_SetsLastModifiedAndEtag() { // Arrange var stream = Stream.Null; var contentType = "text/plain"; var expectedMediaType = contentType; var lastModified = new DateTimeOffset(); var entityTag = new EntityTagHeaderValue("\"Etag\""); // Act var result = new FileStreamResult(stream, contentType) { LastModified = lastModified, EntityTag = entityTag, }; // Assert Assert.Equal(lastModified, result.LastModified); Assert.Equal(entityTag, result.EntityTag); MediaTypeAssert.Equal(expectedMediaType, result.ContentType); }