/// <summary> /// Creates a server streaming call continuation with test results. /// </summary> /// <typeparam name="TResponse">The type of the response.</typeparam> /// <returns>The streaming continuation.</returns> private AsyncServerStreamingCall <HelloResponse> StreamingContinuationWithResult <TResponse>() where TResponse : class { Task <HelloResponse> responseTask = Task.FromResult(TEST_RESPONSE); Task <Metadata> responseHeadersTask = Task.FromResult(TEST_RESPONSE_METADATA); Func <Metadata> trailersTask = () => TEST_TRAILERS_METADATA; TestStreamReader <HelloResponse> responseStream = new TestStreamReader <HelloResponse>(new[] { TEST_RESPONSE }, null); AsyncServerStreamingCall <HelloResponse> call = new AsyncServerStreamingCall <HelloResponse>(responseStream, responseHeadersTask, null, trailersTask, null); return(call); }
public void DisposesWhenEnumerationIsCompleted() { var disposable = new TestDisposable(); var memoryStream = new TestMemoryStream(Encoding.Default.GetBytes("line1\r\nline2\r\nline3")); var streamReader = new TestStreamReader(memoryStream); var enumerable = new StreamReaderEnumerable(streamReader, disposable); // complete enumeration var lines = enumerable.ToList(); Assert.IsTrue(streamReader.DisposeCalled); Assert.IsTrue(streamReader.DisposeCalledDisposingValue); Assert.IsTrue(memoryStream.DisposeCalled); Assert.IsTrue(memoryStream.DisposeCalledDisposingValue); Assert.IsTrue(disposable.DisposeCalled); }
public void TestInterceptStreamNoException() { TestStreamReader <object> testStreamReader = new TestStreamReader <object>( new object[] { 1, 2, 3 }, null); StreamingRpcInterceptor <object> interceptor = new StreamingRpcInterceptor <object>(testStreamReader, delegate(object o, AggregateException e) { return; }); Assert.DoesNotThrow(delegate() { bool hasMoreItems = true; while (hasMoreItems) { Task <bool> task = interceptor.MoveNext(); task.Wait(); hasMoreItems = task.Result; object temp = interceptor.Current; } }); }