Ejemplo n.º 1
0
        public void MustTranformPagedDataAttributesWhenSorting()
        {
            // Arrange
            var items = MockModel.ArrangeFixture();

            var settings = new PagedDataSettings()
            {
            };

            settings.Sorting.Add(new SortingSettings()
            {
                Property = "UIFirstProperty"
            });

            settings.Sorting.Add(new SortingSettings()
            {
                Property = "UISecondProperty"
            });

            // Act
            var transformedSettings = DataPagerAdapter.TransformSettings(settings, this.GetType().GetMethod(nameof(MustTranformPagedDataAttributesWhenSorting)));

            // Assert
            Assert.Equal(transformedSettings.Filter.Count, settings.Filter.Count);
            Assert.Equal(transformedSettings.Sorting.Count, settings.Sorting.Count);
            Assert.True(transformedSettings.Sorting.Where(x => x.Property == "BackEndFirstProperty").Any());
            Assert.True(transformedSettings.Sorting.Where(x => x.Property == "BackEndSecondProperty").Any());
        }
        public void CanFilterPagedDataWithPartialMatch()
        {
            // Arrange
            var items           = MockModel.ArrangeFixture();
            var pagedSize       = 5;
            var expectedResults = items.Count - 1;

            var settings = new PagedDataSettings()
            {
                TotalPerPage = pagedSize
            };

            settings.Filter.Add(new FilterSettings()
            {
                Property     = "Label",
                Value        = "Label",
                IsExactMatch = false
            });

            // Act
            var result = _dataPager.GetPagedData(items.AsQueryable(), settings);

            // Assert
            Assert.True(result.TotalRecords == expectedResults, "Results differ of what they should be. Possibly the filter on the DataPager class is not working.");
            Assert.True(result.Result.Count == pagedSize, "Total items in first paged batch does not match the configured page size.");
        }
Ejemplo n.º 3
0
        public void MustTranformPagedDataAttributesWhenFiltering()
        {
            // Arrange
            var items = MockModel.ArrangeFixture();

            var settings = new PagedDataSettings()
            {
            };

            settings.Filter.Add(new FilterSettings()
            {
                Property     = "UIFirstProperty",
                Value        = items.First().Label,
                IsExactMatch = true
            });

            settings.Filter.Add(new FilterSettings()
            {
                Property     = "UISecondProperty",
                Value        = items.Last().Label,
                IsExactMatch = true
            });

            // Act
            var transformedSettings = DataPagerAdapter.TransformSettings(settings, this.GetType().GetMethod(nameof(MustTranformPagedDataAttributesWhenFiltering)));

            // Assert
            Assert.Equal(transformedSettings.Filter.Count, settings.Filter.Count);
            Assert.Equal(transformedSettings.Sorting.Count, settings.Sorting.Count);
            Assert.True(transformedSettings.Filter.Where(x => x.Property == "BackEndFirstProperty").Any());
            Assert.True(transformedSettings.Filter.Where(x => x.Property == "BackEndSecondProperty").Any());
            Assert.True(transformedSettings.Filter.Where(x => x.Property == "BackEndFirstProperty").FirstOrDefault().Value.Contains("First"));
            Assert.True(transformedSettings.Filter.Where(x => x.Property == "BackEndSecondProperty").FirstOrDefault().Value.Contains("Nineth"));
        }
        public void CanFilterPagedDataWithExactMatch()
        {
            // Arrange
            var items           = MockModel.ArrangeFixture();
            var pagedSize       = 5;
            var expectedResults = 1;

            var settings = new PagedDataSettings()
            {
                TotalPerPage = pagedSize
            };

            settings.Filter.Add(new FilterSettings()
            {
                Property     = "Label",
                Value        = items.Last().Label,
                IsExactMatch = true
            });

            // Act
            var result = _dataPager.GetPagedData(items.AsQueryable(), settings);

            // Assert
            Assert.True(result.TotalRecords == expectedResults, "Results differ of what they should be. Possibly the filter on the DataPager class is not working.");
            Assert.True(result.Result.Count == expectedResults, "Returned results differ than total records.");
        }
        public void CanFilterAndSortPostQueryPathsByDescending()
        {
            // Arrange
            var items     = MockModel.ArrangeFixture();
            var pagedSize = 5;

            var settings = new PagedDataSettings()
            {
                TotalPerPage = pagedSize
            };

            settings.Filter.Add(new FilterSettings()
            {
                Property = "ChildCollection.Label",
                Value    = "First"
            });

            settings.Sorting.Add(new SortingSettings()
            {
                PostQuerySortingPath = "ChildCollection.Label",
                Order = SortOrderEnum.DESC
            });

            // Act
            var result = _dataPager.GetPagedData(items.AsQueryable(), settings);

            // Assert
            Assert.True(result.Result[0].ChildCollection[0].Label.Contains("Third"));
            Assert.True(result.Result[0].ChildCollection[1].Label.Contains("Second"));
            Assert.True(result.Result[0].ChildCollection[2].Label.Contains("First"));
        }
        public void CanFilterPostQueryPathsByExactMatch()
        {
            // Arrange
            var items     = MockModel.ArrangeFixture();
            var pagedSize = 5;

            var settings = new PagedDataSettings()
            {
                TotalPerPage = pagedSize
            };

            settings.Filter.Add(new FilterSettings()
            {
                Property     = "ChildCollection.Label",
                Value        = "First",
                IsExactMatch = true
            });

            // Act
            var result = _dataPager.GetPagedData(items.AsQueryable(), settings);

            // Assert
            Assert.True(result.TotalRecords == 0);
            Assert.True(result.Result.Count() == 0);
        }
Ejemplo n.º 7
0
        public void ShouldSetDefaultSortingByAttributes()
        {
            // Arrange
            var items = MockModel.ArrangeFixture();

            var settings = new PagedDataSettings()
            {
            };

            // Act
            var transformedSettings = DataPagerAdapter.TransformSettings(settings, this.GetType().GetMethod(nameof(ShouldSetDefaultSortingByAttributes)));

            // Assert
            Assert.Equal(transformedSettings.Sorting.Count, 1);
            Assert.True(transformedSettings.Sorting.Where(x => x.Property == "MyDefaultSortingProperty").Any());
        }
        public void CanGetPagedData()
        {
            // Arrange
            var items     = MockModel.ArrangeFixture();
            var pagedSize = 5;

            var settings = new PagedDataSettings()
            {
                TotalPerPage = pagedSize
            };

            // Act
            var result = _dataPager.GetPagedData(items.AsQueryable(), settings);

            // Assert
            Assert.True(result.TotalRecords == items.Count, "Total records in the paged result does not match the total in the fixture collection.");
            Assert.True(result.Result.Count == pagedSize, "Total items in first paged batch does not match the configured page size.");
        }
        public void CanSortPagedDataByDescending()
        {
            // Arrange
            var items     = MockModel.ArrangeFixture();
            var pagedSize = 5;

            var settings = new PagedDataSettings()
            {
                TotalPerPage = pagedSize
            };

            settings.Sorting.Add(new SortingSettings()
            {
                Property = "Label",
                Order    = SortOrderEnum.DESC // Should default to ASC
            });

            // Act
            var result = _dataPager.GetPagedData(items.AsQueryable(), settings);

            // Assert
            Assert.True(result.Result.First().Label == "Third Label");
            Assert.True(result.Result.Last().Label == "Nineth");
        }