Jo Shields a575963da9 Imported Upstream version 3.6.0
Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
2014-08-13 10:39:27 +01:00

67 lines
1.9 KiB
C#

// Copyright (c) Microsoft Corporation. All rights reserved. See License.txt in the project root for license information.
using Moq;
using Xunit;
using Assert = Microsoft.TestCommon.AssertEx;
namespace System.Web.Mvc.Test
{
public class FilePathResultTest
{
[Fact]
public void ConstructorSetsFileNameProperty()
{
// Act
FilePathResult result = new FilePathResult("someFile", "contentType");
// Assert
Assert.Equal("someFile", result.FileName);
}
[Fact]
public void ConstructorThrowsIfFileNameIsEmpty()
{
// Act & assert
Assert.ThrowsArgumentNullOrEmpty(
delegate { new FilePathResult(String.Empty, "contentType"); }, "fileName");
}
[Fact]
public void ConstructorThrowsIfFileNameIsNull()
{
// Act & assert
Assert.ThrowsArgumentNullOrEmpty(
delegate { new FilePathResult(null, "contentType"); }, "fileName");
}
[Fact]
public void WriteFileTransmitsFileToOutputStream()
{
// Arrange
Mock<HttpResponseBase> mockResponse = new Mock<HttpResponseBase>();
mockResponse.Setup(r => r.TransmitFile("someFile")).Verifiable();
FilePathResultHelper helper = new FilePathResultHelper("someFile", "application/octet-stream");
// Act
helper.PublicWriteFile(mockResponse.Object);
// Assert
mockResponse.Verify();
}
private class FilePathResultHelper : FilePathResult
{
public FilePathResultHelper(string fileName, string contentType)
: base(fileName, contentType)
{
}
public void PublicWriteFile(HttpResponseBase response)
{
WriteFile(response);
}
}
}
}