Beispiel #1
0
        public void GivenRegisterSnapshotCalledWhenQueryExecutedTwiceThenShouldCallbackTwice()
        {
            var query     = new QuerySnapshotHost <IdType>(Query);
            int callCount = 0;

            query.RegisterSnap(e => callCount++);
            var _  = query.Skip(2).Take(3).ToList();
            var __ = query.Skip(3).Take(2).ToList();

            Assert.Equal(2, callCount);
        }
Beispiel #2
0
        public void GivenRegisterSnapshotCalledWhenUnregisterCalledThenShouldStopCallingBack()
        {
            var query     = new QuerySnapshotHost <IdType>(Query);
            int callCount = 0;
            var key       = query.RegisterSnap(e => callCount++);
            var _         = query.Skip(2).Take(3).ToList();

            query.UnregisterSnap(key);
            var __ = query.Skip(3).Take(2).ToList();

            Assert.Equal(1, callCount);
        }
Beispiel #3
0
        public void GivenRegisterSnapshotCalledMultipleTimesWhenQueryExecutedThenShouldCallAllCallbacks()
        {
            var query          = new QuerySnapshotHost <IdType>(Query);
            var firstCallback  = false;
            var secondCallback = false;

            query.RegisterSnap(e => firstCallback  = true);
            query.RegisterSnap(e => secondCallback = true);
            var _ = query.Skip(2).Take(3).ToList();

            Assert.True(firstCallback && secondCallback);
        }
Beispiel #4
0
        public void GivenRegisterSnapshotCalledWhenQueryExecutedThenShouldCallbackOnce()
        {
            var        query  = new QuerySnapshotHost <IdType>(Query);
            Expression target = null;

            query.RegisterSnap(e => target = e);
            var _ = query.Skip(2).Take(3).ToList();

            Assert.NotNull(target);
            Assert.True(target.AsEnumerable()
                        .MethodsWithNameForType(typeof(Queryable), nameof(Enumerable.Take))
                        .Any());
        }
Beispiel #5
0
        public void GivenSnapshotHostProviderWhenQueryExecutedThenFiresQueryExecutedEvent()
        {
            var        target     = new QuerySnapshotHost <IdType>(Query);
            Expression expression = null;

            void handler(object o, QuerySnapshotEventArgs e)
            {
                expression = e.Expression;
            }

            target.CustomProvider.QueryExecuted += handler;
            var _ = target.Skip(2).ToList();

            target.CustomProvider.QueryExecuted -= handler;
            Assert.NotNull(expression);
        }
Beispiel #6
0
        public void GivenSnapshotHostProviderWhenQueryExecutedThenFiresQueryExecutedEventWithExpression()
        {
            var        query  = new QuerySnapshotHost <IdType>(Query);
            Expression target = null;

            void handler(object o, QuerySnapshotEventArgs e) =>
            target = e.Expression;

            query.CustomProvider.QueryExecuted += handler;
            var _ = query.Skip(2).Take(3).ToList();

            query.CustomProvider.QueryExecuted -= handler;
            Assert.NotNull(target);
            Assert.True(target.AsEnumerable()
                        .MethodsWithNameForType(typeof(Queryable), nameof(Enumerable.Take))
                        .Any());
        }
Beispiel #7
0
        public void GivenRegisterSnapshotCalledWhenQueryExecutedWithProjectionThenShouldCallbackOnce()
        {
            var        query  = new QuerySnapshotHost <IdType>(Query);
            Expression target = null;

            void CaptureSnap(Expression e)
            {
                target = e;
            }

            query.RegisterSnap(CaptureSnap);
            var _ = query.Skip(2).Take(3).Select(i => new { i.Id, i.IdVal }).ToList();

            Assert.NotNull(target);
            Assert.True(target.AsEnumerable()
                        .MethodsWithNameForType(typeof(Queryable), nameof(Enumerable.Take))
                        .Any());
        }