本文整理汇总了C#中TestableController.File方法的典型用法代码示例。如果您正苦于以下问题:C# TestableController.File方法的具体用法?C# TestableController.File怎么用?C# TestableController.File使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TestableController
的用法示例。
在下文中一共展示了TestableController.File方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: File_WithPathAndFileDownloadName
public void File_WithPathAndFileDownloadName()
{
// Arrange
var controller = new TestableController();
var path = Path.GetFullPath("somepath");
// Act
var result = controller.File(path, "application/pdf", "someDownloadName");
// Assert
Assert.NotNull(result);
Assert.Equal(path, result.FileName);
Assert.Equal("application/pdf", result.ContentType.ToString());
Assert.Equal("someDownloadName", result.FileDownloadName);
}
示例2: File_WithStreamAndFileDownloadName
public void File_WithStreamAndFileDownloadName()
{
// Arrange
var mockHttpContext = new Mock<DefaultHttpContext>();
mockHttpContext.Setup(x => x.Response.OnResponseCompleted(It.IsAny<Action<object>>(), It.IsAny<object>()));
var controller = new TestableController()
{
ActionContext = new ActionContext(mockHttpContext.Object, new RouteData(), new ActionDescriptor())
};
var fileStream = Stream.Null;
// Act
var result = controller.File(fileStream, "application/pdf", "someDownloadName");
// Assert
Assert.NotNull(result);
Assert.Same(fileStream, result.FileStream);
Assert.Equal("application/pdf", result.ContentType.ToString());
Assert.Equal("someDownloadName", result.FileDownloadName);
mockHttpContext.Verify(
x => x.Response.OnResponseCompleted(It.IsAny<Action<object>>(), It.IsAny<object>()),
Times.Once());
}
示例3: File_WithContentsAndFileDownloadName
public void File_WithContentsAndFileDownloadName()
{
// Arrange
var controller = new TestableController();
var fileContents = new byte[0];
// Act
var result = controller.File(fileContents, "application/pdf", "someDownloadName");
// Assert
Assert.NotNull(result);
Assert.Same(fileContents, result.FileContents);
Assert.Equal("application/pdf", result.ContentType.ToString());
Assert.Equal("someDownloadName", result.FileDownloadName);
}
示例4: File_WithStream
public void File_WithStream()
{
// Arrange
var mockHttpContext = new Mock<DefaultHttpContext>();
mockHttpContext.Setup(x => x.Response.RegisterForDispose(It.IsAny<IDisposable>()));
var controller = new TestableController()
{
ActionContext = new ActionContext(mockHttpContext.Object, new RouteData(), new ActionDescriptor())
};
var fileStream = Stream.Null;
// Act
var result = controller.File(fileStream, "application/pdf");
// Assert
Assert.NotNull(result);
Assert.Same(fileStream, result.FileStream);
Assert.Equal("application/pdf", result.ContentType.ToString());
Assert.Equal(string.Empty, result.FileDownloadName);
}
示例5: File_WithStreamAndFileDownloadName
public void File_WithStreamAndFileDownloadName()
{
// Arrange
var mockHttpContext = new Mock<HttpContext>();
mockHttpContext.Setup(x => x.Response.RegisterForDispose(It.IsAny<IDisposable>()));
var controller = new TestableController();
controller.ControllerContext.HttpContext = mockHttpContext.Object;
var fileStream = Stream.Null;
// Act
var result = controller.File(fileStream, "application/pdf", "someDownloadName");
// Assert
Assert.NotNull(result);
Assert.Same(fileStream, result.FileStream);
Assert.Equal("application/pdf", result.ContentType.ToString());
Assert.Equal("someDownloadName", result.FileDownloadName);
mockHttpContext.Verify(
x => x.Response.RegisterForDispose(It.IsAny<IDisposable>()),
Times.Once());
}
示例6: File_WithPath
public void File_WithPath()
{
// Arrange
var controller = new TestableController();
var path = Path.GetFullPath("somepath");
// Act
var result = controller.File(path, "someContentType");
// Assert
Assert.NotNull(result);
Assert.Equal(path, result.FileName);
Assert.Equal("someContentType", result.ContentType);
Assert.Equal(string.Empty, result.FileDownloadName);
}
示例7: File_WithContents
public void File_WithContents()
{
// Arrange
var controller = new TestableController();
var fileContents = new byte[0];
// Act
var result = controller.File(fileContents, "someContentType");
// Assert
Assert.NotNull(result);
Assert.Same(fileContents, result.FileContents);
Assert.Equal("someContentType", result.ContentType);
Assert.Equal(string.Empty, result.FileDownloadName);
}