Ejemplo n.º 1
0
        public void CanWriteResult_OnlyActsOnStreams(Type type)
        {
            // Arrange
            var formatter = new StreamOutputFormatter();
            var @object   = type != null?Activator.CreateInstance(type) : null;

            var context = new OutputFormatterWriteContext(
                new DefaultHttpContext(),
                new TestHttpResponseStreamWriterFactory().CreateWriter,
                type,
                @object);

            // Act
            var result = formatter.CanWriteResult(context);

            // Assert
            Assert.False(result);
        }
Ejemplo n.º 2
0
        public void CanWriteResult_OnlyActsOnStreams(Type type)
        {
            // Arrange
            var formatter = new StreamOutputFormatter();
            var @object = type != null ? Activator.CreateInstance(type) : null;

            var context = new OutputFormatterWriteContext(
                new DefaultHttpContext(),
                new TestHttpResponseStreamWriterFactory().CreateWriter,
                type,
                @object);

            // Act
            var result = formatter.CanWriteResult(context);

            // Assert
            Assert.False(result);
        }
Ejemplo n.º 3
0
        public void CanWriteResult_OnlyActsOnStreams_IgnoringContentType(Type type, string contentType)
        {
            // Arrange
            var formatter         = new StreamOutputFormatter();
            var contentTypeHeader = contentType == null ? new StringSegment() : new StringSegment(contentType);

            var context = new OutputFormatterWriteContext(
                new DefaultHttpContext(),
                new TestHttpResponseStreamWriterFactory().CreateWriter,
                type,
                new SimplePOCO())
            {
                ContentType = contentTypeHeader,
            };

            // Act
            var canWrite = formatter.CanWriteResult(context);

            // Assert
            Assert.False(canWrite);
        }
Ejemplo n.º 4
0
        public void CanWriteResult_ReturnsTrue_ForStreams(Type type, string contentType)
        {
            // Arrange
            var formatter         = new StreamOutputFormatter();
            var contentTypeHeader = new StringSegment(contentType);

            var context = new OutputFormatterWriteContext(
                new DefaultHttpContext(),
                new TestHttpResponseStreamWriterFactory().CreateWriter,
                type,
                new MemoryStream())
            {
                ContentType = contentTypeHeader,
            };

            // Act
            var canWrite = formatter.CanWriteResult(context);

            // Assert
            Assert.True(canWrite);
        }
Ejemplo n.º 5
0
        public void CanWriteResult_OnlyActsOnStreams_IgnoringContentType(Type type, string contentType)
        {
            // Arrange
            var formatter = new StreamOutputFormatter();
            var contentTypeHeader = contentType == null ? new StringSegment() : new StringSegment(contentType);

            var context = new OutputFormatterWriteContext(
                new DefaultHttpContext(),
                new TestHttpResponseStreamWriterFactory().CreateWriter,
                type,
                new SimplePOCO())
            {
                ContentType = contentTypeHeader,
            };

            // Act
            var canWrite = formatter.CanWriteResult(context);

            // Assert
            Assert.False(canWrite);
        }
Ejemplo n.º 6
0
        public void CanWriteResult_ReturnsTrue_ForStreams(Type type, string contentType)
        {
            // Arrange
            var formatter = new StreamOutputFormatter();
            var contentTypeHeader = new StringSegment(contentType);

            var context = new OutputFormatterWriteContext(
                new DefaultHttpContext(),
                new TestHttpResponseStreamWriterFactory().CreateWriter,
                type,
                new MemoryStream())
            {
                ContentType = contentTypeHeader,
            };

            // Act
            var canWrite = formatter.CanWriteResult(context);

            // Assert
            Assert.True(canWrite);
        }