コード例 #1
0
        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();
        }
コード例 #2
0
        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();
        }
コード例 #3
0
        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); });
        }
コード例 #4
0
        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();
        }