public void CanWriteResult_SetsContentType()
        {
            // Arrange
            var formatter = new StreamOutputFormatter();
            var contentType = new MediaTypeHeaderValue("text/plain");
            var context = new OutputFormatterContext();
            context.Object = new MemoryStream();

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

            // Assert
            Assert.True(result);
            Assert.Same(contentType, context.SelectedContentType);
        }
Beispiel #2
0
        public void CanWriteResult_SetsContentType()
        {
            // Arrange
            var formatter   = new StreamOutputFormatter();
            var contentType = new MediaTypeHeaderValue("text/plain");
            var context     = new OutputFormatterContext();

            context.Object = new MemoryStream();

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

            // Assert
            Assert.True(result);
            Assert.Same(contentType, context.SelectedContentType);
        }
Beispiel #3
0
        public void CanWriteResult_OnlyActsOnStreams(Type type)
        {
            // Arrange
            var formatter   = new StreamOutputFormatter();
            var context     = new OutputFormatterContext();
            var contentType = new MediaTypeHeaderValue("text/plain");

            context.Object = type != null?Activator.CreateInstance(type) : null;

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

            // Assert
            Assert.False(result);
            Assert.Null(context.SelectedContentType);
        }
        public void CanWriteResult_OnlyActsOnStreams(Type type)
        {
            // Arrange
            var formatter = new StreamOutputFormatter();
            var context = new OutputFormatterContext();
            var contentType = new MediaTypeHeaderValue("text/plain");

            context.Object = type != null ? Activator.CreateInstance(type) : null;

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

            // Assert
            Assert.False(result);
            Assert.Null(context.SelectedContentType);
        }
Beispiel #5
0
        public void CanWriteResult_OnlyActsOnStreams_IgnoringContentType(Type declaredType, string contentType)
        {
            // Arrange
            var formatter         = new StreamOutputFormatter();
            var contentTypeHeader = contentType == null ? null : new MediaTypeHeaderValue(contentType);
            var formatterContext  = new OutputFormatterContext()
            {
                DeclaredType = declaredType,
                Object       = new SimplePOCO()
            };

            // Act
            var canWrite = formatter.CanWriteResult(formatterContext, contentTypeHeader);

            // Assert
            Assert.False(canWrite);
        }
Beispiel #6
0
        public void CanWriteResult_ReturnsTrue_ForStreams(Type declaredType, string contentType)
        {
            // Arrange
            var formatter         = new StreamOutputFormatter();
            var contentTypeHeader = contentType == null ? null : new MediaTypeHeaderValue(contentType);
            var formatterContext  = new OutputFormatterContext()
            {
                DeclaredType = declaredType,
                Object       = new MemoryStream()
            };

            // Act
            var canWrite = formatter.CanWriteResult(formatterContext, contentTypeHeader);

            // Assert
            Assert.True(canWrite);
        }
        public void CanWriteResult_OnlyActsOnStreams_IgnoringContentType(Type declaredType, string contentType)
        {
            // Arrange
            var formatter = new StreamOutputFormatter();
            var contentTypeHeader = contentType == null ? null : new MediaTypeHeaderValue(contentType);
            var formatterContext = new OutputFormatterContext()
            {
                DeclaredType = declaredType,
                Object = new SimplePOCO()
            };

            // Act
            var canWrite = formatter.CanWriteResult(formatterContext, contentTypeHeader);

            // Assert
            Assert.False(canWrite);
        }
        public void CanWriteResult_ReturnsTrue_ForStreams(Type declaredType, string contentType)
        {
            // Arrange
            var formatter = new StreamOutputFormatter();
            var contentTypeHeader = contentType == null ? null : new MediaTypeHeaderValue(contentType);
            var formatterContext = new OutputFormatterContext()
            {
                DeclaredType = declaredType,
                Object = new MemoryStream()
            };

            // Act
            var canWrite = formatter.CanWriteResult(formatterContext, contentTypeHeader);

            // Assert
            Assert.True(canWrite);
        }