本文整理汇总了C#中MockContent.ReadAsStreamAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MockContent.ReadAsStreamAsync方法的具体用法?C# MockContent.ReadAsStreamAsync怎么用?C# MockContent.ReadAsStreamAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockContent
的用法示例。
在下文中一共展示了MockContent.ReadAsStreamAsync方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Dispose_GetReadStreamThenDispose_ReadStreamGetsDisposed
public async Task Dispose_GetReadStreamThenDispose_ReadStreamGetsDisposed()
{
var content = new MockContent();
MockMemoryStream s = (MockMemoryStream) await content.ReadAsStreamAsync();
Assert.Equal(1, content.CreateContentReadStreamCount);
Assert.Equal(0, s.DisposeCount);
content.Dispose();
Assert.Equal(1, s.DisposeCount);
}
示例2: Dispose_DisposedObjectThenAccessMembers_ThrowsObjectDisposedException
public async Task Dispose_DisposedObjectThenAccessMembers_ThrowsObjectDisposedException()
{
var content = new MockContent();
content.Dispose();
var m = new MemoryStream();
await Assert.ThrowsAsync<ObjectDisposedException>(() => content.CopyToAsync(m));
await Assert.ThrowsAsync<ObjectDisposedException>(() => content.ReadAsByteArrayAsync());
await Assert.ThrowsAsync<ObjectDisposedException>(() => content.ReadAsStringAsync());
await Assert.ThrowsAsync<ObjectDisposedException>(() => content.ReadAsStreamAsync());
await Assert.ThrowsAsync<ObjectDisposedException>(() => content.LoadIntoBufferAsync());
// Note that we don't throw when users access the Headers property. This is useful e.g. to be able to
// read the headers of a content, even though the content is already disposed. Note that the .NET guidelines
// only require members to throw ObjectDisposedExcpetion for members "that cannot be used after the object
// has been disposed of".
_output.WriteLine(content.Headers.ToString());
}
示例3: MockContent
public async Task LoadIntoBufferAsync_CallOnMockContentWithLessLengthThanContentLengthHeader_BufferedStreamLengthMatchesActualLengthNotContentLengthHeaderValue()
{
byte[] data = Encoding.UTF8.GetBytes("16 bytes of data");
var content = new MockContent(data);
content.Headers.ContentLength = 32; // Set the Content-Length header to a value > actual data length.
Assert.Equal(32, content.Headers.ContentLength);
await content.LoadIntoBufferAsync();
Assert.Equal(1, content.SerializeToStreamAsyncCount);
Assert.NotNull(content.Headers.ContentLength);
Assert.Equal(32, content.Headers.ContentLength);
Stream stream = await content.ReadAsStreamAsync();
Assert.Equal(data.Length, stream.Length);
}
示例4: LoadIntoBufferAsync_CallMultipleTimesWithNullContentLength_CopyToAsyncMemoryStreamCalledOnce
public async Task LoadIntoBufferAsync_CallMultipleTimesWithNullContentLength_CopyToAsyncMemoryStreamCalledOnce()
{
var content = new MockContent();
await content.LoadIntoBufferAsync();
await content.LoadIntoBufferAsync();
Assert.Equal(1, content.SerializeToStreamAsyncCount);
Stream stream = await content.ReadAsStreamAsync();
Assert.False(stream.CanWrite);
}
示例5: LoadIntoBufferAsync_CallOnMockContentWithNullContentLength_CopyToAsyncMemoryStreamCalled
public async Task LoadIntoBufferAsync_CallOnMockContentWithNullContentLength_CopyToAsyncMemoryStreamCalled()
{
var content = new MockContent();
Assert.Null(content.Headers.ContentLength);
await content.LoadIntoBufferAsync();
Assert.NotNull(content.Headers.ContentLength);
Assert.Equal(content.MockData.Length, content.Headers.ContentLength);
Assert.Equal(1, content.SerializeToStreamAsyncCount);
Stream stream = await content.ReadAsStreamAsync();
Assert.False(stream.CanWrite);
}
示例6: ReadAsStreamAsync_UseBaseImplementation_ContentGetsBufferedThenMemoryStreamReturned
public async Task ReadAsStreamAsync_UseBaseImplementation_ContentGetsBufferedThenMemoryStreamReturned()
{
var content = new MockContent(MockOptions.DontOverrideCreateContentReadStream);
Stream stream = await content.ReadAsStreamAsync();
Assert.NotNull(stream);
Assert.Equal(1, content.SerializeToStreamAsyncCount);
Stream stream2 = await content.ReadAsStreamAsync();
Assert.Same(stream, stream2);
Assert.Equal(0, stream.Position);
Assert.Equal((byte)'d', stream.ReadByte());
}
示例7: ReadAsStreamAsync_FirstGetFromUnbufferedContentThenGetFromBufferedContent_SameStream
public async Task ReadAsStreamAsync_FirstGetFromUnbufferedContentThenGetFromBufferedContent_SameStream()
{
var content = new MockContent(MockOptions.CanCalculateLength);
Stream before = await content.ReadAsStreamAsync();
Assert.Equal(1, content.CreateContentReadStreamCount);
await content.LoadIntoBufferAsync();
Stream after = await content.ReadAsStreamAsync();
Assert.Equal(1, content.CreateContentReadStreamCount);
// Note that ContentReadStream returns always the same stream. If the user gets the stream, buffers content,
// and gets the stream again, the same instance is returned. Returning a different instance could be
// confusing, even though there shouldn't be any real world scenario for retrieving the read stream both
// before and after buffering content.
Assert.Equal(before, after);
}
示例8: ReadAsStreamAsync_GetFromBufferedContent_CreateContentReadStreamCalled
public async Task ReadAsStreamAsync_GetFromBufferedContent_CreateContentReadStreamCalled()
{
var content = new MockContent(MockOptions.CanCalculateLength);
await content.LoadIntoBufferAsync();
Stream stream = await content.ReadAsStreamAsync();
Assert.Equal(0, content.CreateContentReadStreamCount);
Assert.Equal(content.GetMockData().Length, stream.Length);
Stream stream2 = await content.ReadAsStreamAsync();
Assert.Same(stream, stream2);
Assert.Equal(0, stream.Position);
Assert.Equal((byte)'d', stream.ReadByte());
}
示例9: ReadAsStreamAsync_GetFromUnbufferedContent_CreateContentReadStreamCalledOnce
public async Task ReadAsStreamAsync_GetFromUnbufferedContent_CreateContentReadStreamCalledOnce()
{
var content = new MockContent(MockOptions.CanCalculateLength);
// Call multiple times: CreateContentReadStreamAsync() should be called only once.
Stream stream = await content.ReadAsStreamAsync();
stream = await content.ReadAsStreamAsync();
stream = await content.ReadAsStreamAsync();
Assert.Equal(1, content.CreateContentReadStreamCount);
Assert.Equal(content.GetMockData().Length, stream.Length);
Stream stream2 = await content.ReadAsStreamAsync();
Assert.Same(stream, stream2);
}