示例#1
0
        public async void should_set_pagenumber_to_one_if_it_is_less()
        {
            //arrange
            var wordRepository = new Mock <IRepository <Word> >();

            wordRepository.Setup(x => x.FindAll(It.IsAny <Expression <Func <Word, bool> > >()))
            .Returns(new List <Word> {
                new Word {
                    Id = 1, Key = "key"
                }
            }.AsQueryable());

            var tagRepository = new Mock <IRepository <Tag> >();

            tagRepository.Setup(x => x.FindAll(It.IsAny <Expression <Func <Tag, bool> > >()))
            .Returns(new List <Tag> {
                new Tag {
                    Id = 1, Name = "name"
                }
            }.AsQueryable());

            //act
            var sut = new TagServiceBuilder().WithWordRepository(wordRepository.Object, tagRepository.Object)
                      .Build();

            var result = await sut.GetWords(string.Empty, 0);

            //assert
            Assert.AreEqual(result.Number, 1);
        }
示例#2
0
        public async void should_return_pagedlist()
        {
            //arrange
            var words = new List <Word>();

            for (var i = 1; i <= ConstHelper.PageSize * 4; i++)
            {
                words.Add(new Word {
                    Id = i
                });
            }

            var wordRepository = new Mock <IRepository <Word> >();

            wordRepository.Setup(x => x.FindAll(It.IsAny <Expression <Func <Word, bool> > >(), It.IsAny <Expression <Func <Word, object> > >()))
            .Returns(words.AsQueryable());

            var tags = new List <Tag>();

            for (var i = 1; i <= ConstHelper.PageSize * 4; i++)
            {
                tags.Add(new Tag {
                    Id = i
                });
            }

            var tagRepository = new Mock <IRepository <Tag> >();

            tagRepository.Setup(x => x.FindAll(It.IsAny <Expression <Func <Tag, bool> > >(), It.IsAny <Expression <Func <Tag, object> > >()))
            .Returns(tags.AsQueryable());

            //act
            var sut = new TagServiceBuilder().WithWordRepository(wordRepository.Object, tagRepository.Object)
                      .Build();

            var result = await sut.GetWords("url", 2);

            //assert
            Assert.AreEqual(result.Number, 2);
            Assert.AreEqual(result.Size, ConstHelper.PageSize);
            Assert.AreEqual(result.TotalCount, ConstHelper.PageSize * 4);
            Assert.AreEqual(result.HasPreviousPage, true);
            Assert.AreEqual(result.HasNextPage, true);
            Assert.AreEqual(result.Items.Count, ConstHelper.PageSize);
            Assert.AreEqual(result.Items.First().Id, (ConstHelper.PageSize * 4) - (ConstHelper.PageSize));
            Assert.AreEqual(result.Items.Last().Id, (ConstHelper.PageSize * 4) - (ConstHelper.PageSize * 2) + 1);
        }