예제 #1
0
    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);
    }
예제 #2
0
    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);
    }
예제 #3
0
        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 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);
        }
예제 #5
0
    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);
    }
예제 #6
0
        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);
        }
        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);
        }
예제 #8
0
        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);
        }
            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);
        }