public void CanWriteResult_ByDefault_ReturnsTrue_IfTheValueIsNull( object value, bool declaredTypeAsString, bool expected, bool useNonNullContentType) { // Arrange var type = declaredTypeAsString ? typeof(string) : typeof(object); var contentType = useNonNullContentType ? new StringSegment("text/plain") : new StringSegment(); var context = new OutputFormatterWriteContext( new DefaultHttpContext(), new TestHttpResponseStreamWriterFactory().CreateWriter, type, value) { ContentType = contentType, }; var formatter = new HttpNoContentOutputFormatter(); // Act var result = formatter.CanWriteResult(context); // Assert Assert.Equal(expected, result); }
public void CanWriteResult_ReturnsTrue_IfReturnValueIsNullAndTreatNullValueAsNoContentIsNotSet( string value, bool treatNullValueAsNoContent, bool expected) { // Arrange var context = new OutputFormatterWriteContext( new DefaultHttpContext(), new TestHttpResponseStreamWriterFactory().CreateWriter, typeof(string), value) { ContentType = new StringSegment("text/plain"), }; var formatter = new HttpNoContentOutputFormatter() { TreatNullValueAsNoContent = treatNullValueAsNoContent }; // Act var result = formatter.CanWriteResult(context); // Assert Assert.Equal(expected, result); }
public void CanWriteResult_ReturnsTrue_IfReturnTypeIsVoidOrTask(Type declaredType) { // Arrange var formatterContext = new OutputFormatterContext() { Object = "Something non null.", DeclaredType = declaredType, ActionContext = null, }; var contetType = MediaTypeHeaderValue.Parse("text/plain"); var formatter = new HttpNoContentOutputFormatter(); // Act var actualCanWriteResult = formatter.CanWriteResult(formatterContext, contetType); // Assert Assert.True(actualCanWriteResult); }
public void CanWriteResult_ReturnsTrue_IfReturnTypeIsVoidOrTask(Type declaredType) { // Arrange var context = new OutputFormatterWriteContext( new DefaultHttpContext(), new TestHttpResponseStreamWriterFactory().CreateWriter, declaredType, "Something non null.") { ContentType = new StringSegment("text/plain"), }; var formatter = new HttpNoContentOutputFormatter(); // Act var result = formatter.CanWriteResult(context); // Assert Assert.True(result); }
public void CanWriteResult_ByDefault_ReturnsTrue_IfTheValueIsNull(object value, bool declaredTypeAsString, bool expectedCanwriteResult, bool useNonNullContentType) { // Arrange var typeToUse = declaredTypeAsString ? typeof(string) : typeof(object); var formatterContext = new OutputFormatterContext() { Object = value, DeclaredType = typeToUse, ActionContext = null, }; var contetType = useNonNullContentType ? MediaTypeHeaderValue.Parse("text/plain") : null; var formatter = new HttpNoContentOutputFormatter(); // Act var actualCanWriteResult = formatter.CanWriteResult(formatterContext, contetType); // Assert Assert.Equal(expectedCanwriteResult, actualCanWriteResult); }
CanWriteResult_ReturnsTrue_IfReturnValueIsNullAndTreatNullValueAsNoContentIsNotSet(string value, bool treatNullValueAsNoContent, bool expectedCanwriteResult) { // Arrange var formatterContext = new OutputFormatterContext() { Object = value, DeclaredType = typeof(string), ActionContext = null, }; var contetType = MediaTypeHeaderValue.Parse("text/plain"); var formatter = new HttpNoContentOutputFormatter() { TreatNullValueAsNoContent = treatNullValueAsNoContent }; // Act var actualCanWriteResult = formatter.CanWriteResult(formatterContext, contetType); // Assert Assert.Equal(expectedCanwriteResult, actualCanWriteResult); }