Example #1
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>>>()))
                          .Returns(words.AsQueryable());

            //act
            var sut = new WordServiceBuilder().WithWordRepository(wordRepository.Object)
                                             .Build();

            var result = await sut.GetWords(2);

            //assert
            Assert.AreEqual(2, result.Number);
            Assert.AreEqual(ConstHelper.PageSize, result.Size);
            Assert.AreEqual(ConstHelper.PageSize * 4, result.TotalCount);
            Assert.AreEqual(true, result.HasPreviousPage);
            Assert.AreEqual(true, result.HasNextPage);
            Assert.AreEqual(ConstHelper.PageSize, result.Items.Count);
            Assert.AreEqual((ConstHelper.PageSize * 4) - (ConstHelper.PageSize), result.Items.First().Id);
            Assert.AreEqual((ConstHelper.PageSize * 4) - (ConstHelper.PageSize * 2) + 1, result.Items.Last().Id);
        }
Example #2
0
        public async void should_GetAll_return_words()
        {
            //arrange
            var wordRepository = new Mock<IRepository<Word>>();
            wordRepository.Setup(x => x.FindAll(It.IsAny<Expression<Func<Word, bool>>>()))
                          .Returns(new List<Word> { new Word { Key = "1" }, new Word { Key = "2" } }.AsQueryable());

            //act
            var sut = new WordServiceBuilder().WithWordRepository(wordRepository.Object).Build();

            var result = await sut.GetWords(1);

            //assert
            Assert.AreEqual(2, result.TotalCount);
            wordRepository.Verify(x => x.FindAll(It.IsAny<Expression<Func<Word, bool>>>()), Times.Once);
        }
Example #3
0
        public async void should_set_pagenumber_to_one_if_it_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());

            //act
            var sut = new WordServiceBuilder().WithWordRepository(wordRepository.Object)
                                             .Build();

            var result = await sut.GetWords(0);

            //assert
            Assert.AreEqual(1, result.Number);
        }