public void Constructor_SetsMediaType()
        {
            Action <Stream, HttpContent, TransportContext> streamAction = new MockStreamAction().Action;
            PushStreamContent content = new PushStreamContent(streamAction, MediaTypeConstants.TextXmlMediaType);

            Assert.Equal(MediaTypeConstants.TextXmlMediaType, content.Headers.ContentType);
        }
        public void Constructor_SetsMediaType()
        {
            MockStreamAction  streamAction = new MockStreamAction();
            PushStreamContent content      = new PushStreamContent(streamAction.Action, MediaTypeConstants.TextXmlMediaType);

            Assert.Equal(MediaTypeConstants.TextXmlMediaType, content.Headers.ContentType);
        }
        public void Constructor_SetsDefaultMediaType()
        {
            Action <Stream, HttpContent, TransportContext> streamAction = new MockStreamAction().Action;
            PushStreamContent content = new PushStreamContent(streamAction);

            Assert.Equal(MediaTypeConstants.ApplicationOctetStreamMediaType, content.Headers.ContentType);
        }
        public Task SerializeToStreamAsync_CallsAction()
        {
            // Arrange
            MemoryStream outputStream = new MemoryStream();
            MockStreamAction streamAction = new MockStreamAction(close: true);
            PushStreamContent content = new PushStreamContent((Action<Stream, HttpContent, TransportContext>)streamAction.Action);

            // Act
            return content.CopyToAsync(outputStream).ContinueWith(
                copyTask =>
                {
                    // Assert
                    Assert.Equal(TaskStatus.RanToCompletion, copyTask.Status);
                    Assert.True(streamAction.WasInvoked);
                    Assert.Same(content, streamAction.Content);
                    Assert.IsType<PushStreamContent.CompleteTaskOnCloseStream>(streamAction.OutputStream);
#if NETFX_CORE
                    // In portable libraries, we expect the dispose to be called because we passed close: true above
                    // on netfx45, we let the HttpContent call close on the stream.
                    // CompleteTaskOnCloseStream for this reason does not dispose the innerStream when close is called
                    Assert.False(outputStream.CanRead);
#else
                    Assert.True(outputStream.CanRead);
#endif

                });
        }
        public void Constructor_SetsDefaultMediaType()
        {
            MockStreamAction  streamAction = new MockStreamAction();
            PushStreamContent content      = new PushStreamContent(streamAction.Action);

            Assert.Equal(MediaTypeConstants.ApplicationOctetStreamMediaType, content.Headers.ContentType);
        }
Пример #6
0
        public Task SerializeToStreamAsync_CallsAction()
        {
            // Arrange
            MemoryStream      outputStream = new MemoryStream();
            MockStreamAction  streamAction = new MockStreamAction(close: true);
            PushStreamContent content      = new PushStreamContent((Action <Stream, HttpContent, TransportContext>)streamAction.Action);

            // Act
            return(content.CopyToAsync(outputStream).ContinueWith(
                       copyTask =>
            {
                // Assert
                Assert.Equal(TaskStatus.RanToCompletion, copyTask.Status);
                Assert.True(streamAction.WasInvoked);
                Assert.Same(content, streamAction.Content);
                Assert.IsType <PushStreamContent.CompleteTaskOnCloseStream>(streamAction.OutputStream);
#if NETFX_CORE
                // In portable libraries, we expect the dispose to be called because we passed close: true above
                // on netfx45, we let the HttpContent call close on the stream.
                // CompleteTaskOnCloseStream for this reason does not dispose the innerStream when close is called
                Assert.False(outputStream.CanRead);
#else
                Assert.True(outputStream.CanRead);
#endif
            }));
        }
        public async Task SerializeToStreamAsync_CompletesTaskOnActionException()
        {
            // Arrange
            MemoryStream      outputStream = new MemoryStream();
            MockStreamAction  streamAction = new MockStreamAction(throwException: true);
            PushStreamContent content      = new PushStreamContent((Action <Stream, HttpContent, TransportContext>)streamAction.Action);

            // Act & Assert
            await Assert.ThrowsAsync <ApplicationException>(() => content.CopyToAsync(outputStream));

            Assert.True(streamAction.WasInvoked);
            Assert.IsType <PushStreamContent.CompleteTaskOnCloseStream>(streamAction.OutputStream);
            Assert.True(outputStream.CanRead);
        }
        public async Task SerializeToStreamAsync_CallsAction()
        {
            // Arrange
            MemoryStream      outputStream = new MemoryStream();
            MockStreamAction  streamAction = new MockStreamAction(close: true);
            PushStreamContent content      = new PushStreamContent((Action <Stream, HttpContent, TransportContext>)streamAction.Action);

            // Act
            await content.CopyToAsync(outputStream);

            // Assert
            Assert.True(streamAction.WasInvoked);
            Assert.Same(content, streamAction.Content);
            Assert.IsType <PushStreamContent.CompleteTaskOnCloseStream>(streamAction.OutputStream);

            // We don't close the underlying stream
            Assert.True(outputStream.CanRead);
        }
        public Task SerializeToStreamAsync_CompletesTaskOnActionException()
        {
            // Arrange
            MemoryStream      outputStream = new MemoryStream();
            MockStreamAction  streamAction = new MockStreamAction(throwException: true);
            PushStreamContent content      = new PushStreamContent(streamAction.Action);

            // Act
            return(content.CopyToAsync(outputStream).ContinueWith(
                       copyTask =>
            {
                // Assert
                Assert.Equal(TaskStatus.Faulted, copyTask.Status);
                Assert.IsType <ApplicationException>(copyTask.Exception.GetBaseException());
                Assert.True(streamAction.WasInvoked);
                Assert.IsType <PushStreamContent.CompleteTaskOnCloseStream>(streamAction.OutputStream);
                Assert.True(outputStream.CanRead);
            }));
        }
        public Task SerializeToStreamAsync_CallsAction()
        {
            // Arrange
            MemoryStream      outputStream = new MemoryStream();
            MockStreamAction  streamAction = new MockStreamAction(close: true);
            PushStreamContent content      = new PushStreamContent(streamAction.Action);

            // Act
            return(content.CopyToAsync(outputStream).ContinueWith(
                       copyTask =>
            {
                // Assert
                Assert.Equal(TaskStatus.RanToCompletion, copyTask.Status);
                Assert.True(streamAction.WasInvoked);
                Assert.Same(content, streamAction.Content);
                Assert.IsType <PushStreamContent.CompleteTaskOnCloseStream>(streamAction.OutputStream);
                Assert.True(outputStream.CanRead);
            }));
        }
        public Task SerializeToStreamAsync_CompletesTaskOnActionException()
        {
            // Arrange
            MemoryStream outputStream = new MemoryStream();
            MockStreamAction streamAction = new MockStreamAction(throwException: true);
            PushStreamContent content = new PushStreamContent(streamAction.Action);

            // Act
            return content.CopyToAsync(outputStream).ContinueWith(
                copyTask =>
                {
                    // Assert
                    Assert.Equal(TaskStatus.Faulted, copyTask.Status);
                    Assert.IsType<ApplicationException>(copyTask.Exception.GetBaseException());
                    Assert.True(streamAction.WasInvoked);
                    Assert.IsType<PushStreamContent.CompleteTaskOnCloseStream>(streamAction.OutputStream);
                    Assert.True(outputStream.CanRead);
                });
        }
        public Task SerializeToStreamAsync_CallsAction()
        {
            // Arrange
            MemoryStream outputStream = new MemoryStream();
            MockStreamAction streamAction = new MockStreamAction(close: true);
            PushStreamContent content = new PushStreamContent(streamAction.Action);

            // Act
            return content.CopyToAsync(outputStream).ContinueWith(
                copyTask =>
                {
                    // Assert
                    Assert.Equal(TaskStatus.RanToCompletion, copyTask.Status);
                    Assert.True(streamAction.WasInvoked);
                    Assert.Same(content, streamAction.Content);
                    Assert.IsType<PushStreamContent.CompleteTaskOnCloseStream>(streamAction.OutputStream);
                    Assert.True(outputStream.CanRead);
                });
        }
 public void Constructor_SetsMediaType()
 {
     MockStreamAction streamAction = new MockStreamAction();
     PushStreamContent content = new PushStreamContent(streamAction.Action, MediaTypeConstants.TextXmlMediaType);
     Assert.Equal(MediaTypeConstants.TextXmlMediaType, content.Headers.ContentType);
 }
 public void Constructor_SetsDefaultMediaType()
 {
     MockStreamAction streamAction = new MockStreamAction();
     PushStreamContent content = new PushStreamContent(streamAction.Action);
     Assert.Equal(MediaTypeConstants.ApplicationOctetStreamMediaType, content.Headers.ContentType);
 }
 public void Constructor_SetsMediaType()
 {
     Action<Stream, HttpContent, TransportContext> streamAction = new MockStreamAction().Action;
     PushStreamContent content = new PushStreamContent(streamAction, MediaTypeConstants.TextXmlMediaType);
     Assert.Equal(MediaTypeConstants.TextXmlMediaType, content.Headers.ContentType);
 }
 public void Constructor_SetsDefaultMediaType()
 {
     Action<Stream, HttpContent, TransportContext> streamAction = new MockStreamAction().Action;
     PushStreamContent content = new PushStreamContent(streamAction);
     Assert.Equal(MediaTypeConstants.ApplicationOctetStreamMediaType, content.Headers.ContentType);
 }