protected override Task ExecuteAsync( HttpContext httpContext, string path, string contentType, DateTimeOffset?lastModified = null, EntityTagHeaderValue entityTag = null, bool enableRangeProcessing = false) { var fileResult = new PhysicalFileResult(path, contentType) { LastModified = lastModified, EntityTag = entityTag, EnableRangeProcessing = enableRangeProcessing, }; httpContext.RequestServices = CreateServices(); var actionContext = new ActionContext(httpContext, new(), new()); return(fileResult.ExecuteResultAsync(actionContext)); }
public async Task ExecuteResultAsync_CallsSendFileAsync_IfIHttpSendFilePresent() { // Arrange var path = Path.GetFullPath(Path.Combine("TestFiles", "FilePathResultTestFile.txt")); var result = new PhysicalFileResult(path, "text/plain"); var sendFileMock = new Mock <IHttpSendFileFeature>(); sendFileMock .Setup(s => s.SendFileAsync(path, 0, null, CancellationToken.None)) .Returns(Task.FromResult <int>(0)); var httpContext = GetHttpContext(); httpContext.Features.Set(sendFileMock.Object); var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); // Act await result.ExecuteResultAsync(context); // Assert sendFileMock.Verify(); }
public async Task ExecuteResultAsync_CallsSendFileAsync_IfIHttpSendFilePresent() { // Arrange var path = Path.GetFullPath(Path.Combine("TestFiles", "FilePathResultTestFile.txt")); var result = new PhysicalFileResult(path, "text/plain"); var sendFileMock = new Mock<IHttpSendFileFeature>(); sendFileMock .Setup(s => s.SendFileAsync(path, 0, null, CancellationToken.None)) .Returns(Task.FromResult<int>(0)); var httpContext = GetHttpContext(); httpContext.Features.Set(sendFileMock.Object); var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); // Act await result.ExecuteResultAsync(context); // Assert sendFileMock.Verify(); }