public void BeginExecuteQueryBlockUntilDone() { MockRepository mocks = new MockRepository(); IRasterProvider adapted = mocks.CreateMock <IRasterProvider>(); IExtents iExtentsStub = MockRepository.GenerateStub <IExtents>(); RasterQueryExpression RasterQueryExpressionStub = MockRepository.GenerateStub <RasterQueryExpression>(iExtentsStub, SpatialOperation.Intersects); _returnStreamStub = MockRepository.GenerateStub <Stream>(); _sleepInterval = 750; using (mocks.Unordered()) { Expect.Call(adapted.ExecuteRasterQuery(RasterQueryExpressionStub)) .Do(new ExecuteQueryDelegate(executeQueryMock)); } mocks.ReplayAll(); AsyncRasterProviderAdapter adapter = new AsyncRasterProviderAdapter(adapted); IAsyncResult ar = adapter.BeginExecuteQuery(RasterQueryExpressionStub, null); Assert.NotNull(ar); Stopwatch timer = Stopwatch.StartNew(); Assert.Same(_returnStreamStub, adapter.EndExecuteQuery(ar)); timer.Stop(); Assert.True(ar.IsCompleted); Assert.False(ar.CompletedSynchronously); Assert.True(timer.ElapsedMilliseconds > 500L); mocks.VerifyAll(); }
public void BeginExecuteQueryPollingNotification() { MockRepository mocks = new MockRepository(); IRasterProvider adapted = mocks.CreateMock <IRasterProvider>(); IExtents iExtentsStub = MockRepository.GenerateStub <IExtents>(); RasterQueryExpression RasterQueryExpressionStub = MockRepository.GenerateStub <RasterQueryExpression>(iExtentsStub, SpatialOperation.Intersects); _returnStreamStub = MockRepository.GenerateStub <Stream>(); _sleepInterval = 1000; using (mocks.Unordered()) { Expect.Call(adapted.ExecuteRasterQuery(RasterQueryExpressionStub)) .Do(new ExecuteQueryDelegate(executeQueryMock)); } mocks.ReplayAll(); AsyncRasterProviderAdapter adapter = new AsyncRasterProviderAdapter(adapted); IAsyncResult ar = adapter.BeginExecuteQuery(RasterQueryExpressionStub, null); Assert.NotNull(ar); Assert.False(ar.IsCompleted); while (!ar.IsCompleted) { Thread.Sleep(350); } Assert.True(ar.IsCompleted); Assert.Same(_returnStreamStub, adapter.EndExecuteQuery(ar)); mocks.VerifyAll(); }
private void QueueableBeginQuery(Object asyncResult) { AsyncResult <Stream> typedAsyncResult = asyncResult as AsyncResult <Stream>; RasterQueryExpression query = typedAsyncResult.AsyncState as RasterQueryExpression; try { typedAsyncResult.SetComplete(InnerRasterProvider.ExecuteRasterQuery(query), false); } catch (Exception terminatingException) { typedAsyncResult.SetComplete(false, terminatingException); } }
public override IAsyncResult BeginExecuteQuery(Expression query, AsyncCallback callback) { RasterQueryExpression rasterQuery = query as RasterQueryExpression; if (rasterQuery == null) { throw new ArgumentException("query must be non-null and of type RasterQueryExpression.", "query"); } AsyncResult <Stream> asyncResult = new AsyncResult <Stream>(callback, query); ThreadPool.QueueUserWorkItem(QueueableBeginQuery, asyncResult); return(asyncResult); }
public void EndExecuteQueryThrowsTerminatingException() { MockRepository mocks = new MockRepository(); IRasterProvider adapted = mocks.CreateMock <IRasterProvider>(); IExtents iExtentsStub = MockRepository.GenerateStub <IExtents>(); RasterQueryExpression RasterQueryExpressionStub = MockRepository.GenerateStub <RasterQueryExpression>(iExtentsStub, SpatialOperation.Intersects); using (mocks.Unordered()) { Expect.Call(adapted.ExecuteRasterQuery(RasterQueryExpressionStub)) .Do(new ExecuteQueryDelegate(executeQueryExceptionMock)); } mocks.ReplayAll(); AsyncRasterProviderAdapter adapter = new AsyncRasterProviderAdapter(adapted); IAsyncResult ar = adapter.BeginExecuteQuery(RasterQueryExpressionStub, null); Assert.NotNull(ar); Assert.Throws <InvalidOperationException>(delegate { adapter.EndExecuteQuery(ar); }); }
public void IRasterProviderMethodsPassThroughAdapter() { MockRepository mocks = new MockRepository(); IRasterProvider adapted = mocks.CreateMock <IRasterProvider>(); Stream streamStub = MockRepository.GenerateStub <Stream>(); IExtents iExtentsStub = MockRepository.GenerateStub <IExtents>(); RasterQueryExpression rasterQueryExpressionStub = MockRepository.GenerateStub <RasterQueryExpression>(iExtentsStub, SpatialOperation.Intersects); using (mocks.Unordered()) { Expect.Call(adapted.ExecuteRasterQuery(rasterQueryExpressionStub)) .Return(streamStub); } mocks.ReplayAll(); AsyncRasterProviderAdapter adapter = new AsyncRasterProviderAdapter(adapted); Assert.Same(streamStub, adapter.ExecuteRasterQuery(rasterQueryExpressionStub)); mocks.VerifyAll(); }
public Stream ExecuteRasterQuery(RasterQueryExpression query) { return(InnerRasterProvider.ExecuteRasterQuery(query)); }
private Stream executeQueryExceptionMock(RasterQueryExpression query) { Thread.Sleep(100); throw new InvalidOperationException("Failure succeeded"); }
private Stream executeQueryMock(RasterQueryExpression query) { Thread.Sleep(_sleepInterval); return _returnStreamStub; }
private Stream executeQueryMock(RasterQueryExpression query) { Thread.Sleep(_sleepInterval); return(_returnStreamStub); }