Example #1
0
        public async Task WriteToStreamAsync_WritesDataButDoesNotCloseStream()
        {
            // Arrange
            TFormatter formatter  = CreateFormatter();
            SampleType sampleType = new SampleType {
                Number = 42
            };
            MemoryStream memStream = new MemoryStream();
            HttpContent  content   = new StringContent(String.Empty);

            content.Headers.ContentType = CreateSupportedMediaType();

            // Act
            await formatter.WriteToStreamAsync(typeof(SampleType), sampleType, memStream, content, null);

            // Assert
            Assert.True(memStream.CanRead);

            byte[] actualSampleTypeByteRepresentation = memStream.ToArray();
            Assert.NotEmpty(actualSampleTypeByteRepresentation);
        }
        public Task WriteToStreamAsync_WritesDataButDoesNotCloseStream()
        {
            // Arrange
            TFormatter formatter  = new TFormatter();
            SampleType sampleType = new SampleType {
                Number = 42
            };
            MemoryStream       memStream      = new MemoryStream();
            HttpContentHeaders contentHeaders = FormattingUtilities.CreateEmptyContentHeaders();

            // Act
            return(formatter.WriteToStreamAsync(typeof(SampleType), sampleType, memStream, contentHeaders, null).ContinueWith(
                       writeTask =>
            {
                // Assert
                Assert.Equal(TaskStatus.RanToCompletion, writeTask.Status);
                Assert.True(memStream.CanRead);

                byte[] actualSampleTypeByteRepresentation = memStream.ToArray();
                Assert.Equal(ExpectedSampleTypeByteRepresentation, actualSampleTypeByteRepresentation);
            }));
        }
Example #3
0
        public Task WriteToStreamAsync_WritesDataButDoesNotCloseStream()
        {
            // Arrange
            TFormatter formatter  = CreateFormatter();
            SampleType sampleType = new SampleType {
                Number = 42
            };
            MemoryStream memStream = new MemoryStream();
            HttpContent  content   = new StringContent(String.Empty);

            content.Headers.ContentType = ExpectedSupportedMediaTypes.First();

            // Act
            return(formatter.WriteToStreamAsync(typeof(SampleType), sampleType, memStream, content, null).ContinueWith(
                       writeTask =>
            {
                // Assert
                Assert.Equal(TaskStatus.RanToCompletion, writeTask.Status);
                Assert.True(memStream.CanRead);

                byte[] actualSampleTypeByteRepresentation = memStream.ToArray();
                Assert.NotEmpty(actualSampleTypeByteRepresentation);
            }));
        }