Renamed PhysicalFileProviderResult and VirtualFileProviderResult to PhysicalFileResult and VirtualFileResult respectively
This commit is contained in:
parent
130d94eb7e
commit
eef6c3883a
|
|
@ -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.
|
||||
|
||||
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
|
||||
/// using mechanisms provided by the host.
|
||||
/// </summary>
|
||||
public class PhysicalFileProviderResult : FileResult
|
||||
public class PhysicalFileResult : FileResult
|
||||
{
|
||||
private const int DefaultBufferSize = 0x1000;
|
||||
private string _fileName;
|
||||
|
||||
/// <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"/>.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
public PhysicalFileProviderResult(string fileName, string contentType)
|
||||
public PhysicalFileResult(string fileName, string contentType)
|
||||
: this(fileName, new MediaTypeHeaderValue(contentType))
|
||||
{
|
||||
if (fileName == null)
|
||||
|
|
@ -41,12 +41,12 @@ namespace Microsoft.AspNet.Mvc
|
|||
}
|
||||
|
||||
/// <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"/>.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
public PhysicalFileProviderResult(string fileName, MediaTypeHeaderValue contentType)
|
||||
public PhysicalFileResult(string fileName, MediaTypeHeaderValue contentType)
|
||||
: base(contentType)
|
||||
{
|
||||
if (fileName == null)
|
||||
|
|
@ -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
|
||||
/// using mechanisms provided by the host.
|
||||
/// </summary>
|
||||
public class VirtualFileProviderResult : FileResult
|
||||
public class VirtualFileResult : FileResult
|
||||
{
|
||||
private const int DefaultBufferSize = 0x1000;
|
||||
private string _fileName;
|
||||
|
||||
/// <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"/>.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
public VirtualFileProviderResult(string fileName, string contentType)
|
||||
public VirtualFileResult(string fileName, string contentType)
|
||||
: this(fileName, new MediaTypeHeaderValue(contentType))
|
||||
{
|
||||
if (fileName == null)
|
||||
|
|
@ -44,13 +44,13 @@ namespace Microsoft.AspNet.Mvc
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="VirtualFileProviderResult"/> instance with
|
||||
/// Creates a new <see cref="VirtualFileResult"/> instance with
|
||||
/// the provided <paramref name="fileName"/> and the
|
||||
/// provided <paramref name="contentType"/>.
|
||||
/// </summary>
|
||||
/// <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>
|
||||
public VirtualFileProviderResult(string fileName, MediaTypeHeaderValue contentType)
|
||||
public VirtualFileResult(string fileName, MediaTypeHeaderValue contentType)
|
||||
: base(contentType)
|
||||
{
|
||||
if (fileName == null)
|
||||
|
|
@ -878,9 +878,9 @@ namespace Microsoft.AspNet.Mvc
|
|||
/// </summary>
|
||||
/// <param name="virtualPath">The virtual path of the file to be returned.</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]
|
||||
public virtual VirtualFileProviderResult File(string virtualPath, string contentType)
|
||||
public virtual VirtualFileResult File(string virtualPath, string contentType)
|
||||
{
|
||||
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="contentType">The Content-Type of the file.</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]
|
||||
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>
|
||||
|
|
@ -906,9 +906,9 @@ namespace Microsoft.AspNet.Mvc
|
|||
/// </summary>
|
||||
/// <param name="physicalPath">The physical path of the file to be returned.</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]
|
||||
public virtual PhysicalFileProviderResult PhysicalFile(string physicalPath, string contentType)
|
||||
public virtual PhysicalFileResult PhysicalFile(string physicalPath, string contentType)
|
||||
{
|
||||
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="contentType">The Content-Type of the file.</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]
|
||||
public virtual PhysicalFileProviderResult PhysicalFile(
|
||||
public virtual PhysicalFileResult PhysicalFile(
|
||||
string physicalPath,
|
||||
string contentType,
|
||||
string fileDownloadName)
|
||||
{
|
||||
return new PhysicalFileProviderResult(physicalPath, contentType) { FileDownloadName = fileDownloadName };
|
||||
return new PhysicalFileResult(physicalPath, contentType) { FileDownloadName = fileDownloadName };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ using Xunit;
|
|||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public class PhysicalFileProviderResultTest
|
||||
public class PhysicalFileResultTest
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_SetsFileName()
|
||||
|
|
@ -24,7 +24,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var path = Path.GetFullPath("helllo.txt");
|
||||
|
||||
// Act
|
||||
var result = new PhysicalFileProviderResult(path, "text/plain");
|
||||
var result = new PhysicalFileResult(path, "text/plain");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(path, result.FileName);
|
||||
|
|
@ -35,7 +35,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
// Arrange
|
||||
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();
|
||||
httpContext.Response.Body = new MemoryStream();
|
||||
var context = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());
|
||||
|
|
@ -55,7 +55,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
// Arrange
|
||||
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>();
|
||||
sendFileMock
|
||||
.Setup(s => s.SendFileAsync(path, 0, null, CancellationToken.None))
|
||||
|
|
@ -78,7 +78,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
// Arrange
|
||||
var expectedContentType = "text/foo; charset=us-ascii";
|
||||
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
|
||||
};
|
||||
|
|
@ -101,7 +101,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
// Arrange
|
||||
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();
|
||||
httpContext.Response.Body = new MemoryStream();
|
||||
|
|
@ -134,7 +134,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
public async Task ExecuteAsync_ThrowsFileNotFound_ForNonRootedPaths(string path)
|
||||
{
|
||||
// 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 expectedMessage = "Could not find file: " + path;
|
||||
|
||||
|
|
@ -158,7 +158,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
public void ExecuteAsync_ThrowsDirectoryNotFound_IfItCanNotFindTheDirectory_ForRootPaths(string path)
|
||||
{
|
||||
// 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());
|
||||
|
||||
// Act & Assert
|
||||
|
|
@ -171,21 +171,21 @@ namespace Microsoft.AspNet.Mvc
|
|||
public void ExecuteAsync_ThrowsFileNotFound_WhenFileDoesNotExist_ForRootPaths(string path)
|
||||
{
|
||||
// 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());
|
||||
|
||||
// Act & Assert
|
||||
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)
|
||||
{
|
||||
}
|
||||
|
||||
public TestPhysicalFileProviderResult(string filePath, MediaTypeHeaderValue contentType)
|
||||
public TestPhysicalFileResult(string filePath, MediaTypeHeaderValue contentType)
|
||||
: base(filePath, contentType)
|
||||
{
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ using Xunit;
|
|||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public class VirtualFileProviderResultTest
|
||||
public class VirtualFileResultTest
|
||||
{
|
||||
[Fact]
|
||||
public void Constructor_SetsFileName()
|
||||
|
|
@ -27,7 +27,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var path = Path.GetFullPath("helllo.txt");
|
||||
|
||||
// Act
|
||||
var result = new VirtualFileProviderResult(path, "text/plain");
|
||||
var result = new VirtualFileResult(path, "text/plain");
|
||||
|
||||
// Assert
|
||||
Assert.Equal(path, result.FileName);
|
||||
|
|
@ -38,7 +38,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
// Arrange
|
||||
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>();
|
||||
appEnvironment.Setup(app => app.WebRootFileProvider)
|
||||
|
|
@ -66,7 +66,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
// Arrange
|
||||
var path = Path.Combine("TestFiles", "FilePathResultTestFile.txt");
|
||||
var result = new TestVirtualFileProviderResult(path, "text/plain")
|
||||
var result = new TestVirtualFileResult(path, "text/plain")
|
||||
{
|
||||
FileProvider = GetFileProvider(path),
|
||||
};
|
||||
|
|
@ -90,7 +90,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
// Arrange
|
||||
var path = Path.Combine("TestFiles", "FilePathResultTestFile.txt");
|
||||
var result = new TestVirtualFileProviderResult(path, "text/plain")
|
||||
var result = new TestVirtualFileResult(path, "text/plain")
|
||||
{
|
||||
FileProvider = GetFileProvider(path),
|
||||
};
|
||||
|
|
@ -116,7 +116,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
// Arrange
|
||||
var expectedContentType = "text/foo; charset=us-ascii";
|
||||
var result = new TestVirtualFileProviderResult(
|
||||
var result = new TestVirtualFileResult(
|
||||
"FilePathResultTestFile_ASCII.txt", MediaTypeHeaderValue.Parse(expectedContentType))
|
||||
{
|
||||
FileProvider = GetFileProvider("FilePathResultTestFile_ASCII.txt"),
|
||||
|
|
@ -142,7 +142,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
// Arrange
|
||||
var path = Path.Combine("TestFiles", "FilePathResultTestFile.txt");
|
||||
var result = new TestVirtualFileProviderResult(path, "text/plain")
|
||||
var result = new TestVirtualFileResult(path, "text/plain")
|
||||
{
|
||||
FileProvider = GetFileProvider(path),
|
||||
};
|
||||
|
|
@ -171,7 +171,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
public async Task ExecuteResultAsync_ReturnsFiles_ForDifferentPaths(string path)
|
||||
{
|
||||
// Arrange
|
||||
var result = new TestVirtualFileProviderResult(path, "text/plain")
|
||||
var result = new TestVirtualFileResult(path, "text/plain")
|
||||
{
|
||||
FileProvider = GetFileProvider(path),
|
||||
};
|
||||
|
|
@ -207,7 +207,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
var nonDiskFileProvider = new Mock<IFileProvider>();
|
||||
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
|
||||
};
|
||||
|
|
@ -243,7 +243,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
// Arrange
|
||||
// Point the IFileProvider root to a different subfolder
|
||||
var fileProvider = new PhysicalFileProvider(Path.GetFullPath("./Properties"));
|
||||
var filePathResult = new VirtualFileProviderResult(path, "text/plain")
|
||||
var filePathResult = new VirtualFileResult(path, "text/plain")
|
||||
{
|
||||
FileProvider = fileProvider,
|
||||
};
|
||||
|
|
@ -275,7 +275,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
// Arrange
|
||||
// Point the IFileProvider root to a different subfolder
|
||||
var fileProvider = new PhysicalFileProvider(Path.GetFullPath("./Properties"));
|
||||
var filePathResult = new VirtualFileProviderResult(path, "text/plain")
|
||||
var filePathResult = new VirtualFileResult(path, "text/plain")
|
||||
{
|
||||
FileProvider = fileProvider,
|
||||
};
|
||||
|
|
@ -297,14 +297,14 @@ namespace Microsoft.AspNet.Mvc
|
|||
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)
|
||||
{
|
||||
}
|
||||
|
||||
public TestVirtualFileProviderResult(string filePath, MediaTypeHeaderValue contentType)
|
||||
public TestVirtualFileResult(string filePath, MediaTypeHeaderValue contentType)
|
||||
: base(filePath, contentType)
|
||||
{
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ namespace FilesWebSite
|
|||
{
|
||||
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"),
|
||||
FileDownloadName = "downloadName.txt"
|
||||
|
|
|
|||
Loading…
Reference in New Issue