public Task ReadFromStreamAsync_WhenContentLengthIsNull_ReadsDataButDoesNotCloseStream() { // Arrange TFormatter formatter = CreateFormatter(); MemoryStream memStream = new MemoryStream(ExpectedSampleTypeByteRepresentation); HttpContent content = new StringContent(String.Empty); HttpContentHeaders contentHeaders = content.Headers; contentHeaders.ContentLength = null; contentHeaders.ContentType = ExpectedSupportedMediaTypes.First(); // Act return(formatter.ReadFromStreamAsync(typeof(SampleType), memStream, content, null).ContinueWith( readTask => { // Assert Assert.Equal(TaskStatus.RanToCompletion, readTask.Status); Assert.True(memStream.CanRead); var value = Assert.IsType <SampleType>(readTask.Result); Assert.Equal(42, value.Number); })); }
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); })); }
public void SupportMediaTypes_DefaultSupportedMediaTypes() { TFormatter formatter = CreateFormatter(); Assert.True(ExpectedSupportedMediaTypes.SequenceEqual(formatter.SupportedMediaTypes)); }
protected virtual MediaTypeHeaderValue CreateSupportedMediaType() { return(ExpectedSupportedMediaTypes.First()); }
public void SupportEncoding_DefaultSupportedMediaTypes() { TFormatter formatter = new TFormatter(); Assert.True(ExpectedSupportedMediaTypes.SequenceEqual(formatter.SupportedMediaTypes)); }