コード例 #1
0
        public async Task Should_Filter_Works_Properly(
            Mock <IMemoryDatabaseProvider <TestDbContext> > mockProvider,
            List <Book> source)
        {
            // Arrange
            string searchText = "a";
            var    queryable  = source.AsQueryable();
            var    repository = new MockingMemoryRepository <TestDbContext, Book, Guid>(mockProvider.Object, queryable);
            var    sut        = CreateAppService(repository);

            var filter = new BookFilterDto {
                Filter = searchText
            };

            // Act
            var actual = await sut.GetListAsync(filter);

            var expectedItems = queryable.ApplyFilter(filter).ToList();
            var expectedCount = filter.ApplyFilterWithoutPaginationAndOrdering(queryable).Count();

            // Assert
            actual.Items.ShouldNotBeNull();
            actual.TotalCount.ShouldBe(expectedCount);
            actual.Items.Count.ShouldBe(expectedItems.Count);
        }
コード例 #2
0
ファイル: AbpFilterBase_Tests.cs プロジェクト: enisn/abp
        public async Task Should_Sorting_Work_Properly(
            Mock <IMemoryDatabaseProvider <TestDbContext> > mockProvider,
            List <Book> source)
        {
            // Arrange
            string sorting    = "Title DESC";
            var    query      = source.AsQueryable();
            var    repository = new MockingMemoryRepository <TestDbContext, Book, Guid>(mockProvider.Object, query);
            var    sut        = CreateAppService(repository);
            var    filter     = new BookFilterDto {
                Sorting = sorting
            };

            // Act
            var actual = await sut.GetListAsync(filter);

            var expected = query
                           .OrderByDescending(x => x.Title)
                           .Skip(filter.SkipCount)
                           .Take(filter.MaxResultCount)
                           .ToList();

            actual.ShouldNotBeNull();
            actual.Items.ShouldNotBeNull();
            actual.Items.Count.ShouldBe(expected.Count);
            for (int i = 0; i < actual.Items.Count; i++)
            {
                actual.Items[i].Title.ShouldBe(expected[i].Title); // Id cannot be mocked. All ids are same.
            }
        }
コード例 #3
0
ファイル: AbpFilterBase_Tests.cs プロジェクト: enisn/abp
        public async Task Should_Filter_Work_Properly(
            Mock <IMemoryDatabaseProvider <TestDbContext> > mockProvider,
            List <Book> source)
        {
            // Arrange
            string sorting    = "Title DESC";
            string searchText = "ab";
            var    query      = source.AsQueryable();
            var    repository = new MockingMemoryRepository <TestDbContext, Book, Guid>(mockProvider.Object, query);
            var    sut        = CreateAppService(repository);
            var    filter     = new BookFilterDto {
                Sorting = sorting, Filter = searchText
            };

            // Act
            var actual = await sut.GetListAsync(filter);

            var expected = query
                           // ToLowerContainsComparison attribute should generate exactly following expression:
                           .Where(x => x.Title.ToLowerInvariant().Contains(searchText.ToLowerInvariant()))
                           .OrderByDescending(x => x.Title)
                           .Skip(filter.SkipCount)
                           .Take(filter.MaxResultCount)
                           .ToList();

            actual.ShouldNotBeNull();
            actual.Items.ShouldNotBeNull();
            actual.Items.Count.ShouldBe(expected.Count);
            for (int i = 0; i < actual.Items.Count; i++)
            {
                actual.Items[i].Title.ShouldBe(expected[i].Title); // Id cannot be mocked. All ids are same.
            }
        }
コード例 #4
0
ファイル: AbpFilterBase_Tests.cs プロジェクト: enisn/abp
        public async Task Should_RangeFilter_Work_Properly(
            Mock <IMemoryDatabaseProvider <TestDbContext> > mockProvider,
            List <Book> source)
        {
            // Arrange
            string sorting    = "Title DESC";
            var    query      = source.AsQueryable();
            var    repository = new MockingMemoryRepository <TestDbContext, Book, Guid>(mockProvider.Object, query);
            var    sut        = CreateAppService(repository);
            var    filter     = new BookFilterDto
            {
                Sorting     = sorting,
                PublishDate = new Range <DateTime>()
                {
                    Min = DateTime.UtcNow
                }
            };

            // Act
            var actual = await sut.GetListAsync(filter);

            var expected = query
                           // TRange type should generate exactly following expression:
                           .Where(x => x.PublishDate >= filter.PublishDate.Min)
                           .OrderByDescending(x => x.Title)
                           .Skip(filter.SkipCount)
                           .Take(filter.MaxResultCount)
                           .ToList();

            actual.ShouldNotBeNull();
            actual.Items.ShouldNotBeNull();
            actual.Items.Count.ShouldBe(expected.Count);
            for (int i = 0; i < actual.Items.Count; i++)
            {
                actual.Items[i].Title.ShouldBe(expected[i].Title); // Id cannot be mocked. All ids are same.
            }
        }
コード例 #5
0
        public async Task Should_Pagination_Works_Properly(
            Mock <IMemoryDatabaseProvider <TestDbContext> > mockProvider,
            List <Book> source)
        {
            // Arrange
            int skip = 3, take = 2;
            var repository = new MockingMemoryRepository <TestDbContext, Book, Guid>(mockProvider.Object, source.AsQueryable());
            var sut        = CreateAppService(repository);

            var filter = new BookFilterDto {
                SkipCount = skip, MaxResultCount = take
            };

            // Act
            var actual = await sut.GetListAsync(filter);

            var expectedItems = source.AsQueryable().ApplyFilter(filter).ToList();
            var expectedCount = source.Count;

            // Assert
            actual.Items.ShouldNotBeNull();
            actual.TotalCount.ShouldBe(expectedCount);
            actual.Items.Count.ShouldBe(expectedItems.Count);
        }