public async Task TestMixed()
        {
            var entities = new[]
            {
                this.database.CreateSimilarEntities(2, "Name 1", "Description 1"),
                this.database.CreateSimilarEntities(2, "Name 2", "Description 1"),
                this.database.CreateSimilarEntities(2, "Name 2", "Description 2"),
            }
            .SelectMany(e => e)
            .OrderBy(e => e.Description)
            .ThenByDescending(e => e.Name)
            .ThenBy(e => e.Id)
            .ToList();
            var orderByDictionary = new OrderByExpressionDictionary <Entity>()
                                    .Add(e => e.Name)
                                    .Add(e => e.Description)
                                    .Add(e => e.Id);

            this.interpreter
            .Add(new OrderByRequest(nameof(Entity.Description), OrderByDirection.Ascending))
            .Add(new OrderByRequest(nameof(Entity.Name), OrderByDirection.Descending))
            .Add(new OrderByRequest(nameof(Entity.Id), OrderByDirection.Ascending));
            var resultEntities = await Observable.Single(
                this.database.Create().Entities, this.provider)
                                 .ApplyOrderByClientRequest(orderByDictionary)
                                 .ToList();

            Assert.Equal(entities, resultEntities, new PropertyComparer <Entity>());
        }
        public async Task TestEmptyCase()
        {
            var entities          = this.database.CreateEnumeratedEntities(10);
            var orderByDictionary = new OrderByExpressionDictionary <Entity>();
            var resultEntities    = await Observable.Single(
                this.database.Create().Entities, this.provider)
                                    .ApplyOrderByClientRequest(orderByDictionary)
                                    .ToList();

            Assert.Equal(entities, resultEntities, new PropertyComparer <Entity>());
        }
        public async Task TestDescending()
        {
            var entities = this.database.CreateEnumeratedEntities(10)
                           .OrderByDescending(e => e.Name)
                           .ToList();
            var orderByDictionary = new OrderByExpressionDictionary <Entity>()
                                    .Add(e => e.Name);

            this.interpreter
            .Add(new OrderByRequest(nameof(Entity.Name), OrderByDirection.Descending));
            var resultEntities = await Observable.Single(
                this.database.Create().Entities, this.provider)
                                 .ApplyOrderByClientRequest(orderByDictionary)
                                 .ToList();

            Assert.Equal(entities, resultEntities, new PropertyComparer <Entity>());
        }
Exemplo n.º 4
0
        public void TestOrderByConfiguration()
        {
            var entities = this.database.CreateEnumeratedEntities(10)
                           .OrderByDescending(e => e.Name)
                           .ToList();
            var dictionary1 = new OrderByExpressionDictionary <Entity>()
                              .Add(e => e.Name);
            var dictionary2 = new OrderByExpressionDictionary <Entity>()
                              .AddProperties();

            foreach (var dictionary in new[] { dictionary1, dictionary2 })
            {
                using (var context = this.database.Create())
                {
                    var expression = dictionary[nameof(Entity.Name)]
                                     .Create(OrderByDirection.Descending);
                    var result = expression
                                 .OrderBy(context.Entities)
                                 .ToList();
                    Assert.Equal(entities, result, new PropertyComparer <Entity>());
                }
            }
        }