コード例 #1
0
        public void WhenRequestingCustomerByNameEndsWithThenLoadsCustomer()
        {
            var waitHandle = new ManualResetEvent(false);

            _customerContext
            .Create()
            .Where(x => x.CompanyName.EndsWith("Futterkiste"))
            .Subscribe(
                x => waitHandle.Set(),
                e => Console.WriteLine(e.Message),
                () => waitHandle.Set());

            var result = waitHandle.WaitOne(5000);

            Assert.True(result);
        }
コード例 #2
0
        public void CanCreateSubscription()
        {
            var waitHandle = new ManualResetEvent(false);
            var observable = new RestObservable <FakeItem>(new FakeAsyncRestClientFactory(), new TestSerializerFactory());

            observable
            .Create()
            .SubscribeOn(NewThreadScheduler.Default)
            .Where(x => x.StringValue == "blah")
            .ObserveOn(Scheduler.Default)
            .Subscribe(
                x =>
            {
                Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
                waitHandle.Set();
            },
                () =>
            {
                Console.WriteLine(Thread.CurrentThread.ManagedThreadId);
                waitHandle.Set();
            });

            var result = waitHandle.WaitOne(5000);

            Assert.True(result);
        }
コード例 #3
0
        public void WhenObservingOnDifferentSchedulerThenInvocationHappensOnDifferentThread()
        {
            var testThreadId = Thread.CurrentThread.ManagedThreadId;

            var waitHandle = new ManualResetEvent(false);
            var observable = new RestObservable <FakeItem>(new FakeAsyncRestClientFactory(), new TestSerializerFactory());

            observable
            .Create()
            .Where(x => x.StringValue == "blah")
            .ObserveOn(Scheduler.Default)
            .Subscribe(
                x =>
            {
            },
                () =>
            {
                var observerThreadId = Thread.CurrentThread.ManagedThreadId;
                if (observerThreadId != testThreadId)
                {
                    waitHandle.Set();
                }
            });

            var result = waitHandle.WaitOne(2000);

            Assert.True(result);
        }
コード例 #4
0
        public void WhenGettingSingleThenReturnsResults()
        {
            var observable = new RestObservable <FakeItem>(new FakeAsyncRestClientFactory(), new TestSerializerFactory());
            var result     = observable
                             .Create()
                             .Where(x => x.StringValue == "blah")
                             .SingleOrDefault();

            Assert.Null(result);
        }
コード例 #5
0
        public void WhenResultReturnedThenCompletesSubscription()
        {
            var waitHandle   = new ManualResetEvent(false);
            var observable   = new RestObservable <FakeItem>(new FakeAsyncRestClientFactory(), new TestSerializerFactory());
            var subscription = observable
                               .Create()
                               .Where(x => x.StringValue == "blah")
                               .Subscribe(x => { }, () => waitHandle.Set());

            var result = waitHandle.WaitOne();

            Assert.True(result);
        }
コード例 #6
0
        public void WhenDisposingSubscriptionThenDoesNotExecute()
        {
            var completedWaitHandle = new ManualResetEvent(false);
            var onnextWaitHandle    = new ManualResetEvent(false);

            var observable   = new RestObservable <FakeItem>(new FakeAsyncRestClientFactory(2000), new TestSerializerFactory());
            var subscription = observable
                               .Create()
                               .Where(x => x.StringValue == "blah")
                               .ObserveOn(Scheduler.CurrentThread)
                               .Subscribe(x => onnextWaitHandle.Set(), () => completedWaitHandle.Set());

            subscription.Dispose();

            var next      = onnextWaitHandle.WaitOne(2000);
            var completed = completedWaitHandle.WaitOne(2000);

            Assert.False(next);
            Assert.True(completed);
        }
コード例 #7
0
        public void WhenGroupingSourceThenReturnsResults()
        {
            var waitHandle = new ManualResetEvent(false);
            var observable = new RestObservable <FakeItem>(new FakeAsyncRestClientFactory(), new TestSerializerFactory());

            observable
            .Create()
            .Where(x => x.StringValue == "blah")
            .GroupBy(x => x.StringValue)
            .Subscribe(
                x => { },
                e =>
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                waitHandle.Set();
            },
                () => waitHandle.Set());

            var result = waitHandle.WaitOne();

            Assert.True(result);
        }
コード例 #8
0
ファイル: RequestTests.cs プロジェクト: Hummer311/linq2rest
        public void WhenAnyExpressionRequiresEagerEvaluationThenCallsRestServiceWithExistingFilterParameter()
        {
            var waitHandle = new ManualResetEvent(false);

            _observable
            .Create()
            .Where(x => x.IntValue <= 3)
            .Any(x => x.DoubleValue.Equals(3d))
            .Subscribe(x => waitHandle.Set(), () => waitHandle.Set());

            waitHandle.WaitOne(2000);

            var requestUri = new Uri("http://localhost/?$filter=Number+le+3");

            _mockClientFactory.Verify(x => x.Create(requestUri), Times.Once());
        }