Esempio n. 1
0
        public void Constructor_SetsFileName()
        {
            // Arrange
            var path = Path.GetFullPath("helllo.txt");

            // Act
            var result = new PhysicalFileResult(path, "text/plain");

            // Assert
            Assert.Equal(path, result.FileName);
        }
        public void Constructor_SetsFileName()
        {
            // Arrange
            var path = Path.GetFullPath("helllo.txt");

            // Act
            var result = new PhysicalFileResult(path, "text/plain");

            // Assert
            Assert.Equal(path, result.FileName);
        }
Esempio n. 3
0
        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 PhysicalFileResult(path, contentType);

            // Assert
            Assert.Equal(path, result.FileName);
            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 PhysicalFileResult(path, contentType);

            // Assert
            Assert.Equal(path, result.FileName);
            MediaTypeAssert.Equal(expectedMediaType, result.ContentType);
        }
Esempio n. 5
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));
        }
        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();
        }
Esempio n. 7
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();
        }