public void ContentDispositionHeaderIsEncodedCorrectlyForUnicodeCharacters() { // Arrange Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>( MockBehavior.Strict ); mockControllerContext .SetupSet(c => c.HttpContext.Response.ContentType = "application/my-type") .Verifiable(); mockControllerContext .Setup( c => c.HttpContext.Response.AddHeader( "Content-Disposition", @"attachment; filename*=UTF-8''ABCXYZabcxyz012789!%40%23$%25%5E&%2A%28%29-%3D_+.:~%CE%94" ) ) .Verifiable(); EmptyFileResult result = new EmptyFileResult("application/my-type") { FileDownloadName = "ABCXYZabcxyz012789!@#$%^&*()-=_+.:~Δ" }; // Act result.ExecuteResult(mockControllerContext.Object); // Assert Assert.True(result.WasWriteFileCalled); mockControllerContext.Verify(); }
public void ContentDispositionHeaderIsEncodedCorrectly() { // See comment in FileResult.cs detailing how the FileDownloadName should be encoded. // Arrange Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>( MockBehavior.Strict ); mockControllerContext .SetupSet(c => c.HttpContext.Response.ContentType = "application/my-type") .Verifiable(); mockControllerContext .Setup( c => c.HttpContext.Response.AddHeader( "Content-Disposition", @"attachment; filename=""some\\file""" ) ) .Verifiable(); EmptyFileResult result = new EmptyFileResult("application/my-type") { FileDownloadName = @"some\file" }; // Act result.ExecuteResult(mockControllerContext.Object); // Assert Assert.True(result.WasWriteFileCalled); mockControllerContext.Verify(); }
public void ExecuteResultSetsContentDispositionIfSpecified() { // Arrange Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>( MockBehavior.Strict ); mockControllerContext .SetupSet(c => c.HttpContext.Response.ContentType = "application/my-type") .Verifiable(); mockControllerContext .Setup( c => c.HttpContext.Response.AddHeader( "Content-Disposition", "attachment; filename=filename.ext" ) ) .Verifiable(); EmptyFileResult result = new EmptyFileResult("application/my-type") { FileDownloadName = "filename.ext" }; // Act result.ExecuteResult(mockControllerContext.Object); // Assert Assert.True(result.WasWriteFileCalled); mockControllerContext.Verify(); }
public void ExecuteResultThrowsIfContextIsNull() { // Arrange FileResult result = new EmptyFileResult(); // Act & assert Assert.ThrowsArgumentNull( delegate { result.ExecuteResult(null); }, "context"); }
public void ExecuteResultThrowsIfContextIsNull() { // Arrange FileResult result = new EmptyFileResult(); // Act & assert ExceptionHelper.ExpectArgumentNullException( delegate { result.ExecuteResult(null); }, "context"); }
public void ExecuteResultDoesNotSetContentDispositionIfNotSpecified() { // Arrange Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict); mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentType, "application/my-type").Verifiable(); EmptyFileResult result = new EmptyFileResult("application/my-type"); // Act result.ExecuteResult(mockControllerContext.Object); // Assert Assert.IsTrue(result.WasWriteFileCalled); mockControllerContext.Verify(); }
public void ExecuteResultDoesNotSetContentDispositionIfNotSpecified() { // Arrange Mock <ControllerContext> mockControllerContext = new Mock <ControllerContext>(); mockControllerContext.SetupSet(c => c.HttpContext.Response.ContentType = "application/my-type").Verifiable(); EmptyFileResult result = new EmptyFileResult("application/my-type"); // Act result.ExecuteResult(mockControllerContext.Object); // Assert Assert.True(result.WasWriteFileCalled); mockControllerContext.Verify(); }
public void ContentDispositionHeaderIsEncodedCorrectlyForUnicodeCharacters() { // Arrange Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict); mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentType, "application/my-type").Verifiable(); mockControllerContext.Expect(c => c.HttpContext.Response.AddHeader("Content-Disposition", @"attachment; filename*=UTF-8''ABCXYZabcxyz012789!%40%23$%25%5E&%2A%28%29-%3D_+.:~%CE%94")).Verifiable(); EmptyFileResult result = new EmptyFileResult("application/my-type") { FileDownloadName = "ABCXYZabcxyz012789!@#$%^&*()-=_+.:~Δ" }; // Act result.ExecuteResult(mockControllerContext.Object); // Assert Assert.IsTrue(result.WasWriteFileCalled); mockControllerContext.Verify(); }
public void ContentDispositionHeaderIsEncodedCorrectly() { // See comment in FileResult.cs detailing how the FileDownloadName should be encoded. // Arrange Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict); mockControllerContext.ExpectSet(c => c.HttpContext.Response.ContentType, "application/my-type").Verifiable(); mockControllerContext.Expect(c => c.HttpContext.Response.AddHeader("Content-Disposition", @"attachment; filename=""some\\file""")).Verifiable(); EmptyFileResult result = new EmptyFileResult("application/my-type") { FileDownloadName = @"some\file" }; // Act result.ExecuteResult(mockControllerContext.Object); // Assert Assert.IsTrue(result.WasWriteFileCalled); mockControllerContext.Verify(); }
public void ExecuteResultThrowsIfContextIsNull() { // Arrange FileResult result = new EmptyFileResult(); // Act & assert Assert.ThrowsArgumentNull( delegate { result.ExecuteResult(null); }, "context"); }
public void ExecuteResultSetsContentDispositionIfSpecified() { // Arrange Mock<ControllerContext> mockControllerContext = new Mock<ControllerContext>(MockBehavior.Strict); mockControllerContext.SetupSet(c => c.HttpContext.Response.ContentType = "application/my-type").Verifiable(); mockControllerContext.Setup(c => c.HttpContext.Response.AddHeader("Content-Disposition", "attachment; filename=filename.ext")).Verifiable(); EmptyFileResult result = new EmptyFileResult("application/my-type") { FileDownloadName = "filename.ext" }; // Act result.ExecuteResult(mockControllerContext.Object); // Assert Assert.True(result.WasWriteFileCalled); mockControllerContext.Verify(); }
public void ExecuteResultThrowsIfContextIsNull() { // Arrange FileResult result = new EmptyFileResult(); // Act & assert ExceptionHelper.ExpectArgumentNullException( delegate { result.ExecuteResult(null); }, "context"); }