Exemplo 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);
        }
Exemplo n.º 2
0
        public void Constructor_SetsContentTypeAndParameters()
        {
            // Arrange
            var path = Path.GetFullPath("helllo.txt");
            var contentType = "text/plain; charset=us-ascii; p1=p1-value";
            var expectedMediaType = MediaTypeHeaderValue.Parse(contentType);

            // Act
            var result = new PhysicalFileResult(path, contentType);

            // Assert
            Assert.Equal(path, result.FileName);
            Assert.Equal(expectedMediaType, result.ContentType);
        }
Exemplo 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 = MediaTypeHeaderValue.Parse(contentType);

            // Act
            var result = new PhysicalFileResult(path, contentType);

            // Assert
            Assert.Equal(path, result.FileName);
            Assert.Equal(expectedMediaType, result.ContentType);
        }
        internal static bool TryGetCachedCompositeFileResult(FileSystemHelper fileSystemHelper, string filesetKey, CompressionType type, string mime, 
            out FileResult result, out DateTime lastWriteTime)
        {
            result = null;
            lastWriteTime = DateTime.Now;

            var filesetPath = fileSystemHelper.GetCurrentCompositeFilePath(type, filesetKey);
            if (System.IO.File.Exists(filesetPath))
            {
                lastWriteTime = System.IO.File.GetLastWriteTime(filesetPath);
                //FilePathResult uses IHttpSendFileFeature which is a native host option for sending static files
                result = new PhysicalFileResult(filesetPath, mime);
                return true;
            }

            return false;
        }
Exemplo n.º 5
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();
        }