Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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();
        }