Renamed PhysicalFileProviderResult and VirtualFileProviderResult to PhysicalFileResult and VirtualFileResult respectively

This commit is contained in:
Kiran Challa 2015-10-01 10:24:34 -07:00
parent 130d94eb7e
commit eef6c3883a
6 changed files with 48 additions and 48 deletions

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -16,18 +16,18 @@ namespace Microsoft.AspNet.Mvc
/// A <see cref="FileResult"/> on execution will write a file from disk to the response /// A <see cref="FileResult"/> on execution will write a file from disk to the response
/// using mechanisms provided by the host. /// using mechanisms provided by the host.
/// </summary> /// </summary>
public class PhysicalFileProviderResult : FileResult public class PhysicalFileResult : FileResult
{ {
private const int DefaultBufferSize = 0x1000; private const int DefaultBufferSize = 0x1000;
private string _fileName; private string _fileName;
/// <summary> /// <summary>
/// Creates a new <see cref="PhysicalFileProviderResult"/> instance with /// Creates a new <see cref="PhysicalFileResult"/> instance with
/// the provided <paramref name="fileName"/> and the provided <paramref name="contentType"/>. /// the provided <paramref name="fileName"/> and the provided <paramref name="contentType"/>.
/// </summary> /// </summary>
/// <param name="fileName">The path to the file. The path must be an absolute path.</param> /// <param name="fileName">The path to the file. The path must be an absolute path.</param>
/// <param name="contentType">The Content-Type header of the response.</param> /// <param name="contentType">The Content-Type header of the response.</param>
public PhysicalFileProviderResult(string fileName, string contentType) public PhysicalFileResult(string fileName, string contentType)
: this(fileName, new MediaTypeHeaderValue(contentType)) : this(fileName, new MediaTypeHeaderValue(contentType))
{ {
if (fileName == null) if (fileName == null)
@ -41,12 +41,12 @@ namespace Microsoft.AspNet.Mvc
} }
/// <summary> /// <summary>
/// Creates a new <see cref="PhysicalFileProviderResult"/> instance with /// Creates a new <see cref="PhysicalFileResult"/> instance with
/// the provided <paramref name="fileName"/> and the provided <paramref name="contentType"/>. /// the provided <paramref name="fileName"/> and the provided <paramref name="contentType"/>.
/// </summary> /// </summary>
/// <param name="fileName">The path to the file. The path must be an absolute path.</param> /// <param name="fileName">The path to the file. The path must be an absolute path.</param>
/// <param name="contentType">The Content-Type header of the response.</param> /// <param name="contentType">The Content-Type header of the response.</param>
public PhysicalFileProviderResult(string fileName, MediaTypeHeaderValue contentType) public PhysicalFileResult(string fileName, MediaTypeHeaderValue contentType)
: base(contentType) : base(contentType)
{ {
if (fileName == null) if (fileName == null)

View File

@ -19,18 +19,18 @@ namespace Microsoft.AspNet.Mvc
/// A <see cref="FileResult" /> that on execution writes the file specified using a virtual path to the response /// A <see cref="FileResult" /> that on execution writes the file specified using a virtual path to the response
/// using mechanisms provided by the host. /// using mechanisms provided by the host.
/// </summary> /// </summary>
public class VirtualFileProviderResult : FileResult public class VirtualFileResult : FileResult
{ {
private const int DefaultBufferSize = 0x1000; private const int DefaultBufferSize = 0x1000;
private string _fileName; private string _fileName;
/// <summary> /// <summary>
/// Creates a new <see cref="VirtualFileProviderResult"/> instance with the provided <paramref name="fileName"/> /// Creates a new <see cref="VirtualFileResult"/> instance with the provided <paramref name="fileName"/>
/// and the provided <paramref name="contentType"/>. /// and the provided <paramref name="contentType"/>.
/// </summary> /// </summary>
/// <param name="fileName">The path to the file. The path must be relative/virtual.</param> /// <param name="fileName">The path to the file. The path must be relative/virtual.</param>
/// <param name="contentType">The Content-Type header of the response.</param> /// <param name="contentType">The Content-Type header of the response.</param>
public VirtualFileProviderResult(string fileName, string contentType) public VirtualFileResult(string fileName, string contentType)
: this(fileName, new MediaTypeHeaderValue(contentType)) : this(fileName, new MediaTypeHeaderValue(contentType))
{ {
if (fileName == null) if (fileName == null)
@ -44,13 +44,13 @@ namespace Microsoft.AspNet.Mvc
} }
/// <summary> /// <summary>
/// Creates a new <see cref="VirtualFileProviderResult"/> instance with /// Creates a new <see cref="VirtualFileResult"/> instance with
/// the provided <paramref name="fileName"/> and the /// the provided <paramref name="fileName"/> and the
/// provided <paramref name="contentType"/>. /// provided <paramref name="contentType"/>.
/// </summary> /// </summary>
/// <param name="fileName">The path to the file. The path must be relative/virtual.</param> /// <param name="fileName">The path to the file. The path must be relative/virtual.</param>
/// <param name="contentType">The Content-Type header of the response.</param> /// <param name="contentType">The Content-Type header of the response.</param>
public VirtualFileProviderResult(string fileName, MediaTypeHeaderValue contentType) public VirtualFileResult(string fileName, MediaTypeHeaderValue contentType)
: base(contentType) : base(contentType)
{ {
if (fileName == null) if (fileName == null)

View File

@ -878,9 +878,9 @@ namespace Microsoft.AspNet.Mvc
/// </summary> /// </summary>
/// <param name="virtualPath">The virtual path of the file to be returned.</param> /// <param name="virtualPath">The virtual path of the file to be returned.</param>
/// <param name="contentType">The Content-Type of the file.</param> /// <param name="contentType">The Content-Type of the file.</param>
/// <returns>The created <see cref="VirtualFileProviderResult"/> for the response.</returns> /// <returns>The created <see cref="VirtualFileResult"/> for the response.</returns>
[NonAction] [NonAction]
public virtual VirtualFileProviderResult File(string virtualPath, string contentType) public virtual VirtualFileResult File(string virtualPath, string contentType)
{ {
return File(virtualPath, contentType, fileDownloadName: null); return File(virtualPath, contentType, fileDownloadName: null);
} }
@ -893,11 +893,11 @@ namespace Microsoft.AspNet.Mvc
/// <param name="virtualPath">The virtual path of the file to be returned.</param> /// <param name="virtualPath">The virtual path of the file to be returned.</param>
/// <param name="contentType">The Content-Type of the file.</param> /// <param name="contentType">The Content-Type of the file.</param>
/// <param name="fileDownloadName">The suggested file name.</param> /// <param name="fileDownloadName">The suggested file name.</param>
/// <returns>The created <see cref="VirtualFileProviderResult"/> for the response.</returns> /// <returns>The created <see cref="VirtualFileResult"/> for the response.</returns>
[NonAction] [NonAction]
public virtual VirtualFileProviderResult File(string virtualPath, string contentType, string fileDownloadName) public virtual VirtualFileResult File(string virtualPath, string contentType, string fileDownloadName)
{ {
return new VirtualFileProviderResult(virtualPath, contentType) { FileDownloadName = fileDownloadName }; return new VirtualFileResult(virtualPath, contentType) { FileDownloadName = fileDownloadName };
} }
/// <summary> /// <summary>
@ -906,9 +906,9 @@ namespace Microsoft.AspNet.Mvc
/// </summary> /// </summary>
/// <param name="physicalPath">The physical path of the file to be returned.</param> /// <param name="physicalPath">The physical path of the file to be returned.</param>
/// <param name="contentType">The Content-Type of the file.</param> /// <param name="contentType">The Content-Type of the file.</param>
/// <returns>The created <see cref="PhysicalFileProviderResult"/> for the response.</returns> /// <returns>The created <see cref="PhysicalFileResult"/> for the response.</returns>
[NonAction] [NonAction]
public virtual PhysicalFileProviderResult PhysicalFile(string physicalPath, string contentType) public virtual PhysicalFileResult PhysicalFile(string physicalPath, string contentType)
{ {
return PhysicalFile(physicalPath, contentType, fileDownloadName: null); return PhysicalFile(physicalPath, contentType, fileDownloadName: null);
} }
@ -921,14 +921,14 @@ namespace Microsoft.AspNet.Mvc
/// <param name="physicalPath">The physical path of the file to be returned.</param> /// <param name="physicalPath">The physical path of the file to be returned.</param>
/// <param name="contentType">The Content-Type of the file.</param> /// <param name="contentType">The Content-Type of the file.</param>
/// <param name="fileDownloadName">The suggested file name.</param> /// <param name="fileDownloadName">The suggested file name.</param>
/// <returns>The created <see cref="PhysicalFileProviderResult"/> for the response.</returns> /// <returns>The created <see cref="PhysicalFileResult"/> for the response.</returns>
[NonAction] [NonAction]
public virtual PhysicalFileProviderResult PhysicalFile( public virtual PhysicalFileResult PhysicalFile(
string physicalPath, string physicalPath,
string contentType, string contentType,
string fileDownloadName) string fileDownloadName)
{ {
return new PhysicalFileProviderResult(physicalPath, contentType) { FileDownloadName = fileDownloadName }; return new PhysicalFileResult(physicalPath, contentType) { FileDownloadName = fileDownloadName };
} }
/// <summary> /// <summary>

View File

@ -15,7 +15,7 @@ using Xunit;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
public class PhysicalFileProviderResultTest public class PhysicalFileResultTest
{ {
[Fact] [Fact]
public void Constructor_SetsFileName() public void Constructor_SetsFileName()
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Mvc
var path = Path.GetFullPath("helllo.txt"); var path = Path.GetFullPath("helllo.txt");
// Act // Act
var result = new PhysicalFileProviderResult(path, "text/plain"); var result = new PhysicalFileResult(path, "text/plain");
// Assert // Assert
Assert.Equal(path, result.FileName); Assert.Equal(path, result.FileName);
@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Mvc
{ {
// Arrange // Arrange
var path = Path.GetFullPath(Path.Combine("TestFiles", "FilePathResultTestFile.txt")); var path = Path.GetFullPath(Path.Combine("TestFiles", "FilePathResultTestFile.txt"));
var result = new TestPhysicalFileProviderResult(path, "text/plain"); var result = new TestPhysicalFileResult(path, "text/plain");
var httpContext = new DefaultHttpContext(); var httpContext = new DefaultHttpContext();
httpContext.Response.Body = new MemoryStream(); httpContext.Response.Body = new MemoryStream();
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor()); var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Mvc
{ {
// Arrange // Arrange
var path = Path.GetFullPath(Path.Combine("TestFiles", "FilePathResultTestFile.txt")); var path = Path.GetFullPath(Path.Combine("TestFiles", "FilePathResultTestFile.txt"));
var result = new PhysicalFileProviderResult(path, "text/plain"); var result = new PhysicalFileResult(path, "text/plain");
var sendFileMock = new Mock<IHttpSendFileFeature>(); var sendFileMock = new Mock<IHttpSendFileFeature>();
sendFileMock sendFileMock
.Setup(s => s.SendFileAsync(path, 0, null, CancellationToken.None)) .Setup(s => s.SendFileAsync(path, 0, null, CancellationToken.None))
@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Mvc
// Arrange // Arrange
var expectedContentType = "text/foo; charset=us-ascii"; var expectedContentType = "text/foo; charset=us-ascii";
var path = Path.GetFullPath(Path.Combine(".", "TestFiles", "FilePathResultTestFile_ASCII.txt")); var path = Path.GetFullPath(Path.Combine(".", "TestFiles", "FilePathResultTestFile_ASCII.txt"));
var result = new TestPhysicalFileProviderResult(path, MediaTypeHeaderValue.Parse(expectedContentType)) var result = new TestPhysicalFileResult(path, MediaTypeHeaderValue.Parse(expectedContentType))
{ {
IsAscii = true IsAscii = true
}; };
@ -101,7 +101,7 @@ namespace Microsoft.AspNet.Mvc
{ {
// Arrange // Arrange
var path = Path.GetFullPath(Path.Combine(".", "TestFiles", "FilePathResultTestFile.txt")); var path = Path.GetFullPath(Path.Combine(".", "TestFiles", "FilePathResultTestFile.txt"));
var result = new TestPhysicalFileProviderResult(path, "text/plain"); var result = new TestPhysicalFileResult(path, "text/plain");
var httpContext = new DefaultHttpContext(); var httpContext = new DefaultHttpContext();
httpContext.Response.Body = new MemoryStream(); httpContext.Response.Body = new MemoryStream();
@ -134,7 +134,7 @@ namespace Microsoft.AspNet.Mvc
public async Task ExecuteAsync_ThrowsFileNotFound_ForNonRootedPaths(string path) public async Task ExecuteAsync_ThrowsFileNotFound_ForNonRootedPaths(string path)
{ {
// Arrange // Arrange
var result = new TestPhysicalFileProviderResult(path, "text/plain"); var result = new TestPhysicalFileResult(path, "text/plain");
var context = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()); var context = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
var expectedMessage = "Could not find file: " + path; var expectedMessage = "Could not find file: " + path;
@ -158,7 +158,7 @@ namespace Microsoft.AspNet.Mvc
public void ExecuteAsync_ThrowsDirectoryNotFound_IfItCanNotFindTheDirectory_ForRootPaths(string path) public void ExecuteAsync_ThrowsDirectoryNotFound_IfItCanNotFindTheDirectory_ForRootPaths(string path)
{ {
// Arrange // Arrange
var result = new TestPhysicalFileProviderResult(path, "text/plain"); var result = new TestPhysicalFileResult(path, "text/plain");
var context = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()); var context = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
// Act & Assert // Act & Assert
@ -171,21 +171,21 @@ namespace Microsoft.AspNet.Mvc
public void ExecuteAsync_ThrowsFileNotFound_WhenFileDoesNotExist_ForRootPaths(string path) public void ExecuteAsync_ThrowsFileNotFound_WhenFileDoesNotExist_ForRootPaths(string path)
{ {
// Arrange // Arrange
var result = new TestPhysicalFileProviderResult(path, "text/plain"); var result = new TestPhysicalFileResult(path, "text/plain");
var context = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor()); var context = new ActionContext(new DefaultHttpContext(), new RouteData(), new ActionDescriptor());
// Act & Assert // Act & Assert
Assert.ThrowsAsync<FileNotFoundException>(() => result.ExecuteResultAsync(context)); Assert.ThrowsAsync<FileNotFoundException>(() => result.ExecuteResultAsync(context));
} }
private class TestPhysicalFileProviderResult : PhysicalFileProviderResult private class TestPhysicalFileResult : PhysicalFileResult
{ {
public TestPhysicalFileProviderResult(string filePath, string contentType) public TestPhysicalFileResult(string filePath, string contentType)
: base(filePath, contentType) : base(filePath, contentType)
{ {
} }
public TestPhysicalFileProviderResult(string filePath, MediaTypeHeaderValue contentType) public TestPhysicalFileResult(string filePath, MediaTypeHeaderValue contentType)
: base(filePath, contentType) : base(filePath, contentType)
{ {
} }

View File

@ -18,7 +18,7 @@ using Xunit;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
public class VirtualFileProviderResultTest public class VirtualFileResultTest
{ {
[Fact] [Fact]
public void Constructor_SetsFileName() public void Constructor_SetsFileName()
@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Mvc
var path = Path.GetFullPath("helllo.txt"); var path = Path.GetFullPath("helllo.txt");
// Act // Act
var result = new VirtualFileProviderResult(path, "text/plain"); var result = new VirtualFileResult(path, "text/plain");
// Assert // Assert
Assert.Equal(path, result.FileName); Assert.Equal(path, result.FileName);
@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Mvc
{ {
// Arrange // Arrange
var path = Path.Combine("TestFiles", "FilePathResultTestFile.txt"); var path = Path.Combine("TestFiles", "FilePathResultTestFile.txt");
var result = new TestVirtualFileProviderResult(path, "text/plain"); var result = new TestVirtualFileResult(path, "text/plain");
var appEnvironment = new Mock<IHostingEnvironment>(); var appEnvironment = new Mock<IHostingEnvironment>();
appEnvironment.Setup(app => app.WebRootFileProvider) appEnvironment.Setup(app => app.WebRootFileProvider)
@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Mvc
{ {
// Arrange // Arrange
var path = Path.Combine("TestFiles", "FilePathResultTestFile.txt"); var path = Path.Combine("TestFiles", "FilePathResultTestFile.txt");
var result = new TestVirtualFileProviderResult(path, "text/plain") var result = new TestVirtualFileResult(path, "text/plain")
{ {
FileProvider = GetFileProvider(path), FileProvider = GetFileProvider(path),
}; };
@ -90,7 +90,7 @@ namespace Microsoft.AspNet.Mvc
{ {
// Arrange // Arrange
var path = Path.Combine("TestFiles", "FilePathResultTestFile.txt"); var path = Path.Combine("TestFiles", "FilePathResultTestFile.txt");
var result = new TestVirtualFileProviderResult(path, "text/plain") var result = new TestVirtualFileResult(path, "text/plain")
{ {
FileProvider = GetFileProvider(path), FileProvider = GetFileProvider(path),
}; };
@ -116,7 +116,7 @@ namespace Microsoft.AspNet.Mvc
{ {
// Arrange // Arrange
var expectedContentType = "text/foo; charset=us-ascii"; var expectedContentType = "text/foo; charset=us-ascii";
var result = new TestVirtualFileProviderResult( var result = new TestVirtualFileResult(
"FilePathResultTestFile_ASCII.txt", MediaTypeHeaderValue.Parse(expectedContentType)) "FilePathResultTestFile_ASCII.txt", MediaTypeHeaderValue.Parse(expectedContentType))
{ {
FileProvider = GetFileProvider("FilePathResultTestFile_ASCII.txt"), FileProvider = GetFileProvider("FilePathResultTestFile_ASCII.txt"),
@ -142,7 +142,7 @@ namespace Microsoft.AspNet.Mvc
{ {
// Arrange // Arrange
var path = Path.Combine("TestFiles", "FilePathResultTestFile.txt"); var path = Path.Combine("TestFiles", "FilePathResultTestFile.txt");
var result = new TestVirtualFileProviderResult(path, "text/plain") var result = new TestVirtualFileResult(path, "text/plain")
{ {
FileProvider = GetFileProvider(path), FileProvider = GetFileProvider(path),
}; };
@ -171,7 +171,7 @@ namespace Microsoft.AspNet.Mvc
public async Task ExecuteResultAsync_ReturnsFiles_ForDifferentPaths(string path) public async Task ExecuteResultAsync_ReturnsFiles_ForDifferentPaths(string path)
{ {
// Arrange // Arrange
var result = new TestVirtualFileProviderResult(path, "text/plain") var result = new TestVirtualFileResult(path, "text/plain")
{ {
FileProvider = GetFileProvider(path), FileProvider = GetFileProvider(path),
}; };
@ -207,7 +207,7 @@ namespace Microsoft.AspNet.Mvc
var nonDiskFileProvider = new Mock<IFileProvider>(); var nonDiskFileProvider = new Mock<IFileProvider>();
nonDiskFileProvider.Setup(fp => fp.GetFileInfo(It.IsAny<string>())).Returns(nonDiskFileInfo.Object); nonDiskFileProvider.Setup(fp => fp.GetFileInfo(It.IsAny<string>())).Returns(nonDiskFileInfo.Object);
var filePathResult = new VirtualFileProviderResult("/SampleEmbeddedFile.txt", "text/plain") var filePathResult = new VirtualFileResult("/SampleEmbeddedFile.txt", "text/plain")
{ {
FileProvider = nonDiskFileProvider.Object FileProvider = nonDiskFileProvider.Object
}; };
@ -243,7 +243,7 @@ namespace Microsoft.AspNet.Mvc
// Arrange // Arrange
// Point the IFileProvider root to a different subfolder // Point the IFileProvider root to a different subfolder
var fileProvider = new PhysicalFileProvider(Path.GetFullPath("./Properties")); var fileProvider = new PhysicalFileProvider(Path.GetFullPath("./Properties"));
var filePathResult = new VirtualFileProviderResult(path, "text/plain") var filePathResult = new VirtualFileResult(path, "text/plain")
{ {
FileProvider = fileProvider, FileProvider = fileProvider,
}; };
@ -275,7 +275,7 @@ namespace Microsoft.AspNet.Mvc
// Arrange // Arrange
// Point the IFileProvider root to a different subfolder // Point the IFileProvider root to a different subfolder
var fileProvider = new PhysicalFileProvider(Path.GetFullPath("./Properties")); var fileProvider = new PhysicalFileProvider(Path.GetFullPath("./Properties"));
var filePathResult = new VirtualFileProviderResult(path, "text/plain") var filePathResult = new VirtualFileResult(path, "text/plain")
{ {
FileProvider = fileProvider, FileProvider = fileProvider,
}; };
@ -297,14 +297,14 @@ namespace Microsoft.AspNet.Mvc
return fileProvider.Object; return fileProvider.Object;
} }
private class TestVirtualFileProviderResult : VirtualFileProviderResult private class TestVirtualFileResult : VirtualFileResult
{ {
public TestVirtualFileProviderResult(string filePath, string contentType) public TestVirtualFileResult(string filePath, string contentType)
: base(filePath, contentType) : base(filePath, contentType)
{ {
} }
public TestVirtualFileProviderResult(string filePath, MediaTypeHeaderValue contentType) public TestVirtualFileResult(string filePath, MediaTypeHeaderValue contentType)
: base(filePath, contentType) : base(filePath, contentType)
{ {
} }

View File

@ -11,7 +11,7 @@ namespace FilesWebSite
{ {
public IActionResult DownloadFileWithFileName() public IActionResult DownloadFileWithFileName()
{ {
return new VirtualFileProviderResult("/Greetings.txt", "text/plain") return new VirtualFileResult("/Greetings.txt", "text/plain")
{ {
FileProvider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, "FilesWebSite.EmbeddedResources"), FileProvider = new EmbeddedFileProvider(GetType().GetTypeInfo().Assembly, "FilesWebSite.EmbeddedResources"),
FileDownloadName = "downloadName.txt" FileDownloadName = "downloadName.txt"