private void GetListFilteredInTitle()
        {
            Setup();

            //Arrange
            var text  = "Alma";
            var list  = TodoListMock.GetList();
            var items = new List <TodoItem>()
            {
                new TodoItem()
                {
                    Title       = "Alma",
                    Description = "Alma Fa",
                    IsCompleted = false,
                    Id          = 4,
                }
            };
            var itemsCount = 1;

            _repositoryMock.Setup(item => item.GetAll(It.IsAny <ISpecification <TodoItem> >())).ReturnsAsync(items);

            //Act
            var result = _todoItemListService.GetAllContainText(text).Result;

            //Assert
            _repositoryMock.Verify(item => item.GetAll(It.IsAny <ISpecification <TodoItem> >()), Times.Once);
            Assert.Equal(itemsCount, result.Count());
            Assert.Equal(items, result);
            Assert.Single(result);
        }
Exemplo n.º 2
0
        public void GetByInvalidId()
        {
            Setup();
            //Arrange
            var list = TodoListMock.GetEmptyList();

            _repositoryMock.Setup(item => item.GetById(It.IsAny <int>())).ReturnsAsync(() => null);

            //Act
            var result = _todoItemService.Get(1).Result;

            //Assert
            _repositoryMock.Verify(item => item.GetById(1), Times.Once);
            Assert.Null(result);
        }
Exemplo n.º 3
0
        public void GetByValidId()
        {
            Setup();
            //Arrange
            var id   = 1;
            var list = TodoListMock.GetList();
            var item = list.First(item => item.Id == id);

            _repositoryMock.Setup(item => item.GetById(It.IsAny <int>())).ReturnsAsync(item);

            //Act
            var result = _todoItemService.Get(id).Result;

            //Assert
            _repositoryMock.Verify(item => item.GetById(id), Times.Once);
            Assert.NotNull(result);
            Assert.Equal(item, result);
        }
        public void ListMustContainOneElement()
        {
            Setup();

            //Arrange
            var list = TodoListMock.GetListWithOneItem();

            _repositoryMock.Setup(item => item.GetAll()).ReturnsAsync(list);


            //Act
            var result = _todoItemListService.GetAll().Result;

            //Assert
            _repositoryMock.Verify(item => item.GetAll(), Times.Once);
            Assert.Equal(list.Count(), result.Count());
            Assert.Single(result);
        }
        public void ListMustBeEmpty()
        {
            Setup();

            //Arrange
            var list = TodoListMock.GetEmptyList();

            _repositoryMock.Setup(item => item.GetAll()).ReturnsAsync(list);


            //Act
            var result = _todoItemListService.GetAll().Result;

            //Assert
            _repositoryMock.Verify(item => item.GetAll(), Times.Once);
            Assert.Equal(list.Count(), result.Count());
            Assert.Empty(result);
        }
        private void GetListFilteredInBodyCaseInSensitive()
        {
            Setup();

            //Arrange
            var text = "fa";
            var list = TodoListMock.GetList();
            Expression <Func <TodoItem, bool> > expr = GetFilterExpression(text);

            _repositoryMock.Setup(item => item.GetAll(It.IsAny <ISpecification <TodoItem> >())).ReturnsAsync(list.Where(expr.Compile()));
            var count = list.Where(expr.Compile()).Count();

            //Act
            var result = _todoItemListService.GetAllContainText(text).Result;

            //Assert
            _repositoryMock.Verify(item => item.GetAll(It.IsAny <ISpecification <TodoItem> >()), Times.Once);
            Assert.Equal(count, result.Count());
            Assert.Single(result);
        }
Exemplo n.º 7
0
        public void GetByValidId_2()
        {
            Setup();
            //Arrange
            var id   = 1;
            var list = TodoListMock.GetList();
            var item = new TodoItem()
            {
                Title       = "Todo 1",
                Description = "Desc 1",
                IsCompleted = false,
                Id          = 1,
            };

            _repositoryMock.Setup(item => item.GetById(It.IsAny <int>())).ReturnsAsync(item);

            //Act
            var result = _todoItemService.Get(id).Result;

            //Assert
            _repositoryMock.Verify(item => item.GetById(id), Times.Once);
            Assert.NotNull(result);
            Assert.Equal(item, result);
        }