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();
        }
        public void EndExecuteQueryThrowsOnInvalidExpression()
        {
            MockRepository  mocks   = new MockRepository();
            IRasterProvider adapted = MockRepository.GenerateStub <IRasterProvider>();
            AsyncResult     result  = new AsyncResult(null, this);

            AsyncRasterProviderAdapter adapter = new AsyncRasterProviderAdapter(adapted);

            Assert.Throws <ArgumentException>(delegate { adapter.EndExecuteQuery(result); });
        }
        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 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 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();
        }
        public void EndExecuteQueryThrowsOnInvalidExpression()
        {
            MockRepository mocks = new MockRepository();
            IRasterProvider adapted = MockRepository.GenerateStub<IRasterProvider>();
            AsyncResult result = new AsyncResult(null, this);

            AsyncRasterProviderAdapter adapter = new AsyncRasterProviderAdapter(adapted);
            Assert.Throws<ArgumentException>(delegate { adapter.EndExecuteQuery(result); });
        }