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 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 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 ConstructorSetsContentTypeProperty() { // Act FileResult result = new EmptyFileResult("someContentType"); // Assert Assert.AreEqual("someContentType", result.ContentType); }
public async Task ContentDispositionHeader_IsEncodedCorrectly_ForUnicodeCharacters() { // Arrange var httpContext = new Mock <HttpContext>(); httpContext.SetupSet(c => c.Response.ContentType = "application/my-type").Verifiable(); httpContext .Setup(c => c.Response.Headers.Set( "Content-Disposition", @"attachment; filename*=UTF-8''ABCXYZabcxyz012789!%40%23$%25%5E&%2A%28%29-%3D_+.:~%CE%94")) .Verifiable(); var actionContext = CreateActionContext(httpContext.Object); var result = new EmptyFileResult("application/my-type") { FileDownloadName = "ABCXYZabcxyz012789!@#$%^&*()-=_+.:~Δ" }; // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.True(result.WasWriteFileCalled); httpContext.Verify(); }
public async Task ContentDispositionHeader_IsEncodedCorrectly() { // See comment in FileResult.cs detailing how the FileDownloadName should be encoded. // Arrange var httpContext = new Mock <HttpContext>(); httpContext.SetupSet(c => c.Response.ContentType = "application/my-type").Verifiable(); httpContext .Setup(c => c.Response.Headers.Set("Content-Disposition", @"attachment; filename=""some\\file""")) .Verifiable(); var actionContext = CreateActionContext(httpContext.Object); var result = new EmptyFileResult("application/my-type") { FileDownloadName = @"some\file" }; // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.True(result.WasWriteFileCalled); httpContext.Verify(); }
public void Constructor_SetsContentType() { // Act var result = new EmptyFileResult("text/plain"); // Assert Assert.Equal("text/plain", result.ContentType); }
public void FileDownloadNameProperty() { // Arrange FileResult result = new EmptyFileResult(); // Act & assert MemberHelper.TestStringProperty(result, "FileDownloadName", String.Empty, false /* testDefaultValue */, true /* allowNullAndEmpty */); }
public void ConstructorSetsContentTypeProperty() { // Act FileResult result = new EmptyFileResult("someContentType"); // Assert Assert.Equal("someContentType", result.ContentType); }
public void FileDownloadNameProperty() { // Arrange FileResult result = new EmptyFileResult(); // Act & assert MemberHelper.TestStringProperty(result, "FileDownloadName", String.Empty); }
public void Constructor_SetsContentType() { // Act var result = new EmptyFileResult("text/plain"); // Assert Assert.Equal("text/plain", result.ContentType.ToString()); }
public void ExecuteResultThrowsIfContextIsNull() { // Arrange FileResult result = new EmptyFileResult(); // Act & assert Assert.ThrowsArgumentNull( delegate { result.ExecuteResult(null); }, "context"); }
public Task ExecuteAsync(ActionContext context, EmptyFileResult result) { SetHeadersAndLog( context, result, fileLength: 0L, enableRangeProcessing: true, lastModified: result.LastModified); result.WasWriteFileCalled = true; return(Task.FromResult(0)); }
public void ExecuteResultThrowsIfContextIsNull() { // Arrange FileResult result = new EmptyFileResult(); // Act & assert ExceptionHelper.ExpectArgumentNullException( delegate { result.ExecuteResult(null); }, "context"); }
public async Task ExecuteResultAsync_ThrowsException_IfCannotResolveLoggerFactory() { // Arrange var httpContext = new DefaultHttpContext(); httpContext.RequestServices = new ServiceCollection().BuildServiceProvider(); var actionContext = CreateActionContext(httpContext); var result = new EmptyFileResult("application/my-type"); // Act & Assert await Assert.ThrowsAsync <InvalidOperationException>(() => result.ExecuteResultAsync(actionContext)); }
public async Task SetsAcceptRangeHeader() { // Arrange var httpContext = GetHttpContext(); var actionContext = CreateActionContext(httpContext); var result = new EmptyFileResult("application/my-type"); // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.Equal("bytes", httpContext.Response.Headers[HeaderNames.AcceptRanges]); }
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 ExecuteResultSetsContentDispositionIfSpecified() { // 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=filename.ext")).Verifiable(); EmptyFileResult result = new EmptyFileResult("application/my-type") { FileDownloadName = "filename.ext" }; // Act result.ExecuteResult(mockControllerContext.Object); // Assert Assert.IsTrue(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 async Task ExecuteResultAsync_DoesNotSetContentDisposition_IfNotSpecified() { // Arrange var httpContext = new Mock<HttpContext>(MockBehavior.Strict); httpContext.SetupSet(c => c.Response.ContentType = "application/my-type").Verifiable(); httpContext.Setup(c => c.Response.Body).Returns(Stream.Null); var actionContext = CreateActionContext(httpContext.Object); var result = new EmptyFileResult("application/my-type"); // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.True(result.WasWriteFileCalled); httpContext.Verify(); }
public async Task ExecuteResultAsync_DoesNotSetContentDisposition_IfNotSpecified() { // Arrange var httpContext = new Mock <HttpContext>(MockBehavior.Strict); httpContext.SetupSet(c => c.Response.ContentType = "application/my-type").Verifiable(); httpContext.Setup(c => c.Response.Body).Returns(Stream.Null); var actionContext = CreateActionContext(httpContext.Object); var result = new EmptyFileResult("application/my-type"); // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.True(result.WasWriteFileCalled); httpContext.Verify(); }
public async Task ExecuteResultAsync_SetsContentDisposition_IfSpecified() { // Arrange var httpContext = GetHttpContext(); var actionContext = CreateActionContext(httpContext); var result = new EmptyFileResult("application/my-type") { FileDownloadName = "filename.ext" }; // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.True(result.WasWriteFileCalled); Assert.Equal("application/my-type", httpContext.Response.ContentType); Assert.Equal("attachment; filename=filename.ext; filename*=UTF-8''filename.ext", httpContext.Response.Headers["Content-Disposition"]); }
public async Task ExecuteResultAsync_LogsInformation_IfCanResolveLoggerFactory() { // Arrange var httpContext = new DefaultHttpContext(); var services = new ServiceCollection(); var loggerSink = new TestSink(); services.AddSingleton <ILoggerFactory>(new TestLoggerFactory(loggerSink, true)); httpContext.RequestServices = services.BuildServiceProvider(); var actionContext = CreateActionContext(httpContext); var result = new EmptyFileResult("application/my-type"); // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.Equal(1, loggerSink.Writes.Count); }
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 async Task ContentDispositionHeader_IsEncodedCorrectly_ForUnicodeCharacters() { // Arrange var httpContext = GetHttpContext(); var actionContext = CreateActionContext(httpContext); var result = new EmptyFileResult("application/my-type") { FileDownloadName = "ABCXYZabcxyz012789!@#$%^&*()-=_+.:~Δ" }; // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.True(result.WasWriteFileCalled); Assert.Equal("application/my-type", httpContext.Response.Headers["Content-Type"]); Assert.Equal(@"attachment; filename=""ABCXYZabcxyz012789!@#$%^&*()-=_+.:~_""; filename*=UTF-8''ABCXYZabcxyz012789!%40#$%25^&%2A%28%29-%3D_+.%3A~%CE%94", httpContext.Response.Headers["Content-Disposition"]); }
public async Task ContentDispositionHeader_IsEncodedCorrectly_ForUnicodeCharacters() { // Arrange var httpContext = new DefaultHttpContext(); var actionContext = CreateActionContext(httpContext); var result = new EmptyFileResult("application/my-type") { FileDownloadName = "ABCXYZabcxyz012789!@#$%^&*()-=_+.:~Δ" }; // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.True(result.WasWriteFileCalled); Assert.Equal("application/my-type", httpContext.Response.Headers["Content-Type"]); Assert.Equal(@"attachment; filename=""ABCXYZabcxyz012789!@#$%^&*()-=_+.:~_""; filename*=UTF-8''ABCXYZabcxyz012789!%40#$%25^&%2A%28%29-%3D_+.%3A~%CE%94", httpContext.Response.Headers["Content-Disposition"]); }
public async Task IfUnmodifiedSinceComparison_OnlyUsesWholeSeconds(DateTimeOffset ifUnmodifiedSince, int expectedStatusCode) { // Arrange var httpContext = GetHttpContext(); httpContext.Request.Headers[HeaderNames.IfUnmodifiedSince] = HeaderUtilities.FormatDate(ifUnmodifiedSince); var actionContext = CreateActionContext(httpContext); // Represents 4/9/2018 11:24:22 AM +00:00 // Ticks rounded down to seconds: 636588698620000000 var ticks = 636588698625969382; var result = new EmptyFileResult("application/test") { LastModified = new DateTimeOffset(ticks, TimeSpan.Zero) }; // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.Equal(expectedStatusCode, httpContext.Response.StatusCode); }
public async Task ContentDispositionHeader_IsEncodedCorrectly() { // See comment in FileResult.cs detailing how the FileDownloadName should be encoded. // Arrange var httpContext = GetHttpContext(); var actionContext = CreateActionContext(httpContext); var result = new EmptyFileResult("application/my-type") { FileDownloadName = @"some\file" }; // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.True(result.WasWriteFileCalled); Assert.Equal("application/my-type", httpContext.Response.Headers["Content-Type"]); Assert.Equal(@"attachment; filename=""some\\file""; filename*=UTF-8''some%5Cfile", httpContext.Response.Headers["Content-Disposition"]); }
public async Task ContentDispositionHeader_IsEncodedCorrectly() { // See comment in FileResult.cs detailing how the FileDownloadName should be encoded. // Arrange var httpContext = new DefaultHttpContext(); var actionContext = CreateActionContext(httpContext); var result = new EmptyFileResult("application/my-type") { FileDownloadName = @"some\file" }; // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.True(result.WasWriteFileCalled); Assert.Equal("application/my-type", httpContext.Response.Headers["Content-Type"]); Assert.Equal(@"attachment; filename=""some\\file""; filename*=UTF-8''some%5Cfile", httpContext.Response.Headers["Content-Disposition"]); }
public async Task ExecuteResultAsync_SetsContentDisposition_IfSpecified() { // Arrange var httpContext = new Mock <HttpContext>(MockBehavior.Strict); httpContext.SetupSet(c => c.Response.ContentType = "application/my-type").Verifiable(); httpContext .Setup(c => c.Response.Headers.Set("Content-Disposition", "attachment; filename=filename.ext")) .Verifiable(); var actionContext = CreateActionContext(httpContext.Object); var result = new EmptyFileResult("application/my-type") { FileDownloadName = "filename.ext" }; // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.True(result.WasWriteFileCalled); httpContext.Verify(); }
public async Task ExecuteResultAsync_DoesNotSetContentDisposition_IfNotSpecified() { // Arrange var provider = new ServiceCollection() .AddSingleton <ILoggerFactory>(NullLoggerFactory.Instance) .AddSingleton <EmptyFileResultExecutor>() .BuildServiceProvider(); var httpContext = new DefaultHttpContext(); httpContext.RequestServices = provider; var actionContext = CreateActionContext(httpContext); var result = new EmptyFileResult("application/my-type"); // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.True(result.WasWriteFileCalled); Assert.Equal("application/my-type", httpContext.Response.ContentType); Assert.Equal(Stream.Null, httpContext.Response.Body); }
public Task ExecuteAsync(ActionContext context, EmptyFileResult result) { SetHeadersAndLog(context, result); result.WasWriteFileCalled = true; return Task.FromResult(0); }
public async Task ExecuteResultAsync_SetsContentDisposition_IfSpecified() { // Arrange var httpContext = new DefaultHttpContext(); var actionContext = CreateActionContext(httpContext); var result = new EmptyFileResult("application/my-type") { FileDownloadName = "filename.ext" }; // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.True(result.WasWriteFileCalled); Assert.Equal("application/my-type", httpContext.Response.ContentType); Assert.Equal("attachment; filename=filename.ext; filename*=UTF-8''filename.ext", httpContext.Response.Headers["Content-Disposition"]); }
public async Task ExecuteResultAsync_ThrowsException_IfCannotResolveLoggerFactory() { // Arrange var httpContext = new DefaultHttpContext(); httpContext.RequestServices = new ServiceCollection().BuildServiceProvider(); var actionContext = CreateActionContext(httpContext); var result = new EmptyFileResult("application/my-type"); // Act & Assert await Assert.ThrowsAsync<InvalidOperationException>(() => result.ExecuteResultAsync(actionContext)); }
public async Task ExecuteResultAsync_DoesNotSetContentDisposition_IfNotSpecified() { // Arrange var provider = new ServiceCollection() .AddSingleton<ILoggerFactory>(NullLoggerFactory.Instance) .AddSingleton<EmptyFileResultExecutor>() .BuildServiceProvider(); var httpContext = new DefaultHttpContext(); httpContext.RequestServices = provider; var actionContext = CreateActionContext(httpContext); var result = new EmptyFileResult("application/my-type"); // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.True(result.WasWriteFileCalled); Assert.Equal("application/my-type", httpContext.Response.ContentType); Assert.Equal(Stream.Null, httpContext.Response.Body); }
public Task ExecuteAsync(ActionContext context, EmptyFileResult result) { SetHeadersAndLog(context, result, 0L, true); result.WasWriteFileCalled = true; return(Task.FromResult(0)); }
public async Task ExecuteResultAsync_LogsInformation_IfCanResolveLoggerFactory() { // Arrange var httpContext = new DefaultHttpContext(); var services = new ServiceCollection(); var loggerSink = new TestSink(); services.AddSingleton<ILoggerFactory>(new TestLoggerFactory(loggerSink, true)); httpContext.RequestServices = services.BuildServiceProvider(); var actionContext = CreateActionContext(httpContext); var result = new EmptyFileResult("application/my-type"); // Act await result.ExecuteResultAsync(actionContext); // Assert Assert.Equal(1, loggerSink.Writes.Count); }