public void ControllerFileStream_InvokedInUnitTests(string content, string contentType, string fileName) { // Arrange var controller = new TestabilityController(); // Act var result = controller.FileStream_Action(content, contentType, fileName); // Assert Assert.NotNull(result); var fileStreamResult = Assert.IsType <FileStreamResult>(result); Assert.Equal(contentType, fileStreamResult.ContentType); Assert.Equal(fileName ?? string.Empty, fileStreamResult.FileDownloadName); if (content == null) { Assert.Null(fileStreamResult.FileStream); } else { using (var stream = new StreamReader(fileStreamResult.FileStream, Encoding.UTF8)) { Assert.Equal(content, stream.ReadToEnd()); } } }
public void ControllerFileStream_InvokedInUnitTests(string content, string contentType, string fileName) { // Arrange var mockHttpContext = new Mock <DefaultHttpContext>(); mockHttpContext.Setup(x => x.Response.OnResponseCompleted(It.IsAny <Action <object> >(), It.IsAny <object>())); var controller = new TestabilityController() { ActionContext = new ActionContext(mockHttpContext.Object, new RouteData(), new ActionDescriptor()) }; // Act var result = controller.FileStream_Action(content, contentType, fileName); // Assert Assert.NotNull(result); var fileStreamResult = Assert.IsType <FileStreamResult>(result); Assert.Equal(contentType, fileStreamResult.ContentType); Assert.Equal(fileName ?? string.Empty, fileStreamResult.FileDownloadName); if (content == null) { Assert.Null(fileStreamResult.FileStream); } else { using (var stream = new StreamReader(fileStreamResult.FileStream, Encoding.UTF8)) { Assert.Equal(content, stream.ReadToEnd()); } } }
public void ControllerFileStream_InvokedInUnitTests() { // Arrange var content = "<html>CreatedBody</html>"; var contentType = "text/html"; var fileName = "Created.html"; var mockHttpContext = new Mock<HttpContext>(); mockHttpContext.Setup(x => x.Response.RegisterForDispose(It.IsAny<IDisposable>())); var controller = new TestabilityController(); controller.ControllerContext.HttpContext = mockHttpContext.Object; // Act var result = controller.FileStream_Action(content, contentType, fileName); // Assert Assert.NotNull(result); var fileStreamResult = Assert.IsType<FileStreamResult>(result); Assert.Equal(contentType, fileStreamResult.ContentType.ToString()); Assert.Equal(fileName ?? string.Empty, fileStreamResult.FileDownloadName); if (content == null) { Assert.Null(fileStreamResult.FileStream); } else { using (var stream = new StreamReader(fileStreamResult.FileStream, Encoding.UTF8)) { Assert.Equal(content, stream.ReadToEnd()); } } }
public void ControllerFileStream_InvokedInUnitTests() { // Arrange var content = "<html>CreatedBody</html>"; var contentType = "text/html"; var fileName = "Created.html"; var mockHttpContext = new Mock<DefaultHttpContext>(); mockHttpContext.Setup(x => x.Response.RegisterForDispose(It.IsAny<IDisposable>())); var controller = new TestabilityController() { ActionContext = new ActionContext(mockHttpContext.Object, new RouteData(), new ActionDescriptor()) }; // Act var result = controller.FileStream_Action(content, contentType, fileName); // Assert Assert.NotNull(result); var fileStreamResult = Assert.IsType<FileStreamResult>(result); Assert.Equal(contentType, fileStreamResult.ContentType.ToString()); Assert.Equal(fileName ?? string.Empty, fileStreamResult.FileDownloadName); if (content == null) { Assert.Null(fileStreamResult.FileStream); } else { using (var stream = new StreamReader(fileStreamResult.FileStream, Encoding.UTF8)) { Assert.Equal(content, stream.ReadToEnd()); } } }