public void BeginExecuteQueryCallBackNotification() { CallBackHelper callBackRecorder = new CallBackHelper(); MockRepository mocks = new MockRepository(); IFeatureProvider adapted = mocks.CreateMock <IFeatureProvider>(); IExtents iExtentsStub = MockRepository.GenerateStub <IExtents>(); FeatureQueryExpression featureQueryExpressionStub = MockRepository.GenerateStub <FeatureQueryExpression>(iExtentsStub, SpatialOperation.Intersects); _returnReaderStub = MockRepository.GenerateStub <IFeatureDataReader>(); _sleepInterval = 500; using (mocks.Unordered()) { Expect.Call(adapted.ExecuteFeatureQuery(featureQueryExpressionStub)) .Do(new ExecuteQueryDelegate(executeQueryMock)); } mocks.ReplayAll(); AsyncFeatureProviderAdapter adapter = new AsyncFeatureProviderAdapter(adapted); IAsyncResult ar = adapter.BeginExecuteQuery(featureQueryExpressionStub, callBackRecorder.CallBack); Assert.NotNull(ar); Assert.False(ar.IsCompleted); Thread.Sleep(1000); Assert.Same(ar, callBackRecorder.Result); Assert.True(ar.IsCompleted); Assert.Same(_returnReaderStub, adapter.EndExecuteQuery(ar)); mocks.VerifyAll(); }
public void CallBack() { CallBackHelper callBackRecorder = new CallBackHelper(); AsyncResult ar = new AsyncResult(callBackRecorder.CallBack, this); ar.SetComplete(); Assert.Same(ar, callBackRecorder.Result); }
public void AsyncCallBackNotification() { CallBackHelper callBackRecorder = new CallBackHelper(); AsynchronousTask task = new AsynchronousTask(1); IAsyncResult ar = task.BeginDoTask(callBackRecorder.CallBack, this); Thread.Sleep(2000); Assert.Same(ar, callBackRecorder.Result); Assert.True(ar.IsCompleted); Assert.False(ar.CompletedSynchronously); task.EndDoTask(ar); // should not throw }
public void AsyncCallBackNotificationWithException() { CallBackHelper callBackRecorder = new CallBackHelper(); InvalidOperationException terminatingException = new InvalidOperationException("Failure succeeded"); AsynchronousTask<String> task = new AsynchronousTask<String>(1, terminatingException); IAsyncResult ar = task.BeginDoTask(callBackRecorder.CallBack, this); Thread.Sleep(2000); Assert.Same(ar, callBackRecorder.Result); Assert.True(ar.IsCompleted); Assert.False(ar.CompletedSynchronously); Assert.Throws<InvalidOperationException>(delegate { task.EndDoTask(ar); }); }
public void AsyncCallBackNotificationWithException() { CallBackHelper callBackRecorder = new CallBackHelper(); InvalidOperationException terminatingException = new InvalidOperationException("Failure succeeded"); AsynchronousTask task = new AsynchronousTask(1, terminatingException); IAsyncResult ar = task.BeginDoTask(callBackRecorder.CallBack, this); Thread.Sleep(2000); Assert.Same(ar, callBackRecorder.Result); Assert.True(ar.IsCompleted); Assert.False(ar.CompletedSynchronously); Assert.Throws <InvalidOperationException>(delegate { task.EndDoTask(ar); }); }
public void AsyncCallBackNotification() { CallBackHelper callBackRecorder = new CallBackHelper(); String expectedResult = "Result we expected"; AsynchronousTask<String> task = new AsynchronousTask<String>(expectedResult, 1); IAsyncResult ar = task.BeginDoTask(callBackRecorder.CallBack, this); Thread.Sleep(2000); Assert.Same(ar, callBackRecorder.Result); Assert.True(ar.IsCompleted); Assert.False(ar.CompletedSynchronously); String actualResult = task.EndDoTask(ar); // should not throw Assert.Same(expectedResult, actualResult); }
public void AsyncCallBackNotification() { CallBackHelper callBackRecorder = new CallBackHelper(); String expectedResult = "Result we expected"; AsynchronousTask <String> task = new AsynchronousTask <String>(expectedResult, 1); IAsyncResult ar = task.BeginDoTask(callBackRecorder.CallBack, this); Thread.Sleep(2000); Assert.Same(ar, callBackRecorder.Result); Assert.True(ar.IsCompleted); Assert.False(ar.CompletedSynchronously); String actualResult = task.EndDoTask(ar); // should not throw Assert.Same(expectedResult, actualResult); }
public void BeginExecuteQueryCallBackNotification() { CallBackHelper callBackRecorder = new CallBackHelper(); 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 = 500; using (mocks.Unordered()) { Expect.Call(adapted.ExecuteRasterQuery(RasterQueryExpressionStub)) .Do(new ExecuteQueryDelegate(executeQueryMock)); } mocks.ReplayAll(); AsyncRasterProviderAdapter adapter = new AsyncRasterProviderAdapter(adapted); IAsyncResult ar = adapter.BeginExecuteQuery(RasterQueryExpressionStub, callBackRecorder.CallBack); Assert.NotNull(ar); Assert.False(ar.IsCompleted); Thread.Sleep(1000); Assert.Same(ar, callBackRecorder.Result); Assert.True(ar.IsCompleted); Assert.Same(_returnStreamStub, adapter.EndExecuteQuery(ar)); mocks.VerifyAll(); }