Esempio n. 1
0
        public void CanSelectAggregationUsingAggregateHelper()
        {
            var aggregation = Query <UserEntity>()
                              .Select(u => new
            {
                Avg = Aggregate.Average(u.Id),
                Sum = Aggregate.Sum(u.Id),
                Min = Aggregate.Min(u.Id),
                Max = Aggregate.Max(u.Id),
                Cnt = Aggregate.Count(u.Id),
                Cnd = Aggregate.CountDistinct(u.Id)
            });

            Assert.That(aggregation.Count(), Is.EqualTo(1));

            var a = aggregation.First();

            Assert.That(a.Avg, Is.EqualTo(2.5));
            Assert.That(a.Sum, Is.EqualTo(10));
            Assert.That(a.Min, Is.EqualTo(1));
            Assert.That(a.Max, Is.EqualTo(4));
            Assert.That(a.Cnt, Is.EqualTo(4));
            Assert.That(a.Cnd, Is.EqualTo(4));
        }
Esempio n. 2
0
 public void CountDistinctThrowsWhenCalledOutsideLambdaExpression()
 {
     Assert.That(() => Aggregate.CountDistinct(3), Throws.InstanceOf <InvalidOperationException>());
     Assert.That(() => Aggregate.CountDistinct((int?)3), Throws.InstanceOf <InvalidOperationException>());
 }
Esempio n. 3
0
        public void CanSelectAggregationUsingAggregateHelper()
        {
            // avg
            IDetachedFlowQuery <UserEntity> aggregation = DetachedQuery <UserEntity>()
                                                          .Select(u => Aggregate.Average(u.Id));

            IEnumerable <UserEntity> users = Query <UserEntity>()
                                             .Where(x => x.Id, FqIs.GreaterThan(aggregation))
                                             .Select();

            Assert.That(users.Count(), Is.EqualTo(2));

            // sum
            aggregation = DetachedQuery <UserEntity>()
                          .Select(u => Aggregate.Sum(u.Id));

            users = Query <UserEntity>()
                    .Where(x => x.Id, FqIs.LessThan(aggregation))
                    .Select();

            Assert.That(users.Count(), Is.EqualTo(4));

            // min
            aggregation = DetachedQuery <UserEntity>()
                          .Select(u => Aggregate.Min(u.Id));

            users = Query <UserEntity>()
                    .Where(x => x.Id, FqIs.EqualTo(aggregation))
                    .Select();

            Assert.That(users.Count(), Is.EqualTo(1));
            Assert.That(users.First().Id, Is.EqualTo(1));

            // max
            aggregation = DetachedQuery <UserEntity>()
                          .Select(u => Aggregate.Max(u.Id));

            users = Query <UserEntity>()
                    .Where(x => x.Id, FqIs.EqualTo(aggregation))
                    .Select();

            Assert.That(users.Count(), Is.EqualTo(1));
            Assert.That(users.First().Id, Is.EqualTo(4));

            // count
            aggregation = DetachedQuery <UserEntity>()
                          .Select(u => Aggregate.Count(u.Id));

            users = Query <UserEntity>()
                    .Where(x => x.Id, FqIs.EqualTo(aggregation))
                    .Select();

            Assert.That(users.Count(), Is.EqualTo(1));
            Assert.That(users.First().Id, Is.EqualTo(4));

            // count distinct
            aggregation = DetachedQuery <UserEntity>()
                          .Select(u => Aggregate.CountDistinct(u.Id));

            users = Query <UserEntity>()
                    .Where(x => x.Id, FqIs.EqualTo(aggregation))
                    .Select();

            Assert.That(users.Count(), Is.EqualTo(1));
            Assert.That(users.First().Id, Is.EqualTo(4));

            // group by
            aggregation = DetachedQuery <UserEntity>()
                          .Select(x => Aggregate.GroupBy(x.Id));

            users = Query <UserEntity>()
                    .Where(x => x.Id, FqIs.In(aggregation))
                    .Select();

            Assert.That(users.Count(), Is.EqualTo(4));
        }