本文整理汇总了C#中MockContent.LoadIntoBufferAsync方法的典型用法代码示例。如果您正苦于以下问题:C# MockContent.LoadIntoBufferAsync方法的具体用法?C# MockContent.LoadIntoBufferAsync怎么用?C# MockContent.LoadIntoBufferAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MockContent
的用法示例。
在下文中一共展示了MockContent.LoadIntoBufferAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CopyToAsync_UseStreamWriteByteWithBufferSizeSmallerThanContentSize_ThrowsHttpRequestException
public async Task CopyToAsync_UseStreamWriteByteWithBufferSizeSmallerThanContentSize_ThrowsHttpRequestException()
{
// MockContent uses stream.WriteByte() rather than stream.Write(): Verify that the max. buffer size
// is also checked when using WriteByte().
var content = new MockContent(MockOptions.UseWriteByteInCopyTo);
await Assert.ThrowsAsync<HttpRequestException>(() => content.LoadIntoBufferAsync(content.GetMockData().Length - 1));
}
示例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: LoadIntoBufferAsync_ThrowCustomExceptionInOverriddenAsyncMethod_ExceptionBubblesUpToCaller
public async Task LoadIntoBufferAsync_ThrowCustomExceptionInOverriddenAsyncMethod_ExceptionBubblesUpToCaller()
{
var content = new MockContent(new MockException(), MockOptions.ThrowInAsyncSerializeMethods);
await Assert.ThrowsAsync<MockException>(() => content.LoadIntoBufferAsync());
}
示例4: LoadIntoBufferAsync_ThrowIOExceptionInOverriddenAsyncMethod_ThrowsHttpRequestException
public async Task LoadIntoBufferAsync_ThrowIOExceptionInOverriddenAsyncMethod_ThrowsHttpRequestException()
{
var content = new MockContent(new IOException(), MockOptions.ThrowInAsyncSerializeMethods);
HttpRequestException ex = await Assert.ThrowsAsync<HttpRequestException>(() => content.LoadIntoBufferAsync());
Assert.IsType<IOException>(ex.InnerException);
}
示例5: 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);
}
示例6: LoadIntoBufferAsync_ThrowObjectDisposedExceptionInOverriddenMethod_ThrowsWrappedHttpRequestException
public async Task LoadIntoBufferAsync_ThrowObjectDisposedExceptionInOverriddenMethod_ThrowsWrappedHttpRequestException()
{
var content = new MockContent(new ObjectDisposedException(""), MockOptions.ThrowInSerializeMethods);
HttpRequestException ex = await Assert.ThrowsAsync<HttpRequestException>(() => content.LoadIntoBufferAsync());
Assert.IsType<ObjectDisposedException>(ex.InnerException);
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: LoadIntoBufferAsync_BufferSizeSmallerThanContentSizeWithNullContentLength_ThrowsHttpRequestException
public async Task LoadIntoBufferAsync_BufferSizeSmallerThanContentSizeWithNullContentLength_ThrowsHttpRequestException()
{
var content = new MockContent();
await Assert.ThrowsAsync<HttpRequestException>(() => content.LoadIntoBufferAsync(content.GetMockData().Length - 1));
}
示例11: 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());
}
示例12: TryComputeLength_RetrieveContentLengthFromBufferedContent_ComputeLengthIsNotCalled
public async Task TryComputeLength_RetrieveContentLengthFromBufferedContent_ComputeLengthIsNotCalled()
{
var content = new MockContent();
await content.LoadIntoBufferAsync();
Assert.Equal(content.GetMockData().Length, content.Headers.ContentLength);
// Called once to determine the size of the buffer.
Assert.Equal(1, content.TryComputeLengthCount);
}
示例13: CopyToAsync_BufferContentFirst_UseBufferedStreamAsSource
public async Task CopyToAsync_BufferContentFirst_UseBufferedStreamAsSource()
{
var data = new byte[10];
var content = new MockContent(data);
content.LoadIntoBufferAsync().Wait();
Assert.Equal(1, content.SerializeToStreamAsyncCount);
var destination = new MemoryStream();
await content.CopyToAsync(destination);
// Our MockContent should not be called for the CopyTo() operation since the buffered stream should be
// used.
Assert.Equal(1, content.SerializeToStreamAsyncCount);
Assert.Equal(data.Length, destination.Length);
}
示例14: LoadIntoBufferAsync_ThrowCustomExceptionInOverriddenMethod_ThrowsMockException
public async Task LoadIntoBufferAsync_ThrowCustomExceptionInOverriddenMethod_ThrowsMockException()
{
var content = new MockContent(new MockException(), MockOptions.ThrowInSerializeMethods);
Task t = content.LoadIntoBufferAsync();
await Assert.ThrowsAsync<MockException>(() => t);
}
示例15: MockContent
public async Task LoadIntoBufferAsync_BufferSizeSmallerThanContentSizeWithCalculatedContentLength_ThrowsHttpRequestException()
{
var content = new MockContent(MockOptions.CanCalculateLength);
Task t = content.LoadIntoBufferAsync(content.GetMockData().Length - 1);
await Assert.ThrowsAsync<HttpRequestException>(() => t);
}