Пример #1
0
        public void CanWriteResult_ReturnsTrueForStringTypes(object value, bool useDeclaredTypeAsString, bool expectedCanWriteResult)
        {
            // Arrange
            var formatter = new TextPlainFormatter();
            var typeToUse = useDeclaredTypeAsString ? typeof(string) : typeof(object);
            var formatterContext = new OutputFormatterContext()
            {
                Object = value,
                DeclaredType = typeToUse
            };

            // Act
            var result = formatter.CanWriteResult(formatterContext, null);

            // Assert
            Assert.Equal(expectedCanWriteResult, result);
        }
Пример #2
0
        public void CanWriteResult_ReturnsTrueForStringTypes(object value, bool useDeclaredTypeAsString, bool expectedCanWriteResult)
        {
            // Arrange
            var formatter        = new TextPlainFormatter();
            var typeToUse        = useDeclaredTypeAsString ? typeof(string) : typeof(object);
            var formatterContext = new OutputFormatterContext()
            {
                Object       = value,
                DeclaredType = typeToUse
            };

            // Act
            var result = formatter.CanWriteResult(formatterContext, null);

            // Assert
            Assert.Equal(expectedCanWriteResult, result);
        }
Пример #3
0
        public async Task WriteAsync_DoesNotWriteNullStrings()
        {
            // Arrange
            var formatter = new TextPlainFormatter();
            var formatterContext = new OutputFormatterContext()
            {
                Object = null,
                DeclaredType = typeof(string), 
            };

            var tempMemoryStream = new MemoryStream();
            var mockHttpContext = new Mock<HttpContext>();
            mockHttpContext.SetupGet(o => o.Response.Body)
                           .Returns(tempMemoryStream);
            // Act
            await formatter.WriteResponseBodyAsync(formatterContext);

            // Assert
            Assert.Equal(0, tempMemoryStream.Length);
        }
Пример #4
0
        public async Task WriteAsync_DoesNotWriteNullStrings()
        {
            // Arrange
            var formatter        = new TextPlainFormatter();
            var formatterContext = new OutputFormatterContext()
            {
                Object       = null,
                DeclaredType = typeof(string),
            };

            var tempMemoryStream = new MemoryStream();
            var mockHttpContext  = new Mock <HttpContext>();

            mockHttpContext.SetupGet(o => o.Response.Body)
            .Returns(tempMemoryStream);
            // Act
            await formatter.WriteResponseBodyAsync(formatterContext);

            // Assert
            Assert.Equal(0, tempMemoryStream.Length);
        }