Beispiel #1
0
        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);
        }
Beispiel #2
0
        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());
        }
Beispiel #3
0
        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);
        }
Beispiel #4
0
        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);
        }
        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());
        }
        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);
        }
        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);
        }