Example #1
0
        public static CreateNewBookInput GetInputWithNotValidCategoryMock()
        {
            var newBookInput = new CreateNewBookInput()
            {
                CategoryId = 0,
            };

            return(newBookInput);
        }
Example #2
0
        public static CreateNewBookInput GetValidInputMock()
        {
            var newBookInput = new CreateNewBookInput()
            {
                CategoryId  = 1,
                Price       = 5,
                Description = "Book Description",
                Title       = "Clean Code"
            };

            return(newBookInput);
        }
Example #3
0
        public void AddNewBook(CreateNewBookInput newBookInput)
        {
            var category = _categoryRepo.GetById(newBookInput.CategoryId);

            if (category == null)
            {
                throw new BLLException(ExceptionCodes.BLLExceptions.CategoryNotFound);
            }
            try
            {
                var newBook = Mapper.Map <Book>(newBookInput);
                newBook.Category = category;
                _bookRepo.Insert(newBook);
                _unitOfWork.SaveChanges();
            }
            catch (BLLException ex)
            {
                throw new BLLException(ExceptionCodes.BLLExceptions.UnhandledError, ex.Message);
            }
        }
Example #4
0
        public void When_AddNewBook_Success()
        {
            //arrange
            var newBook = new CreateNewBookInput
            {
                Title      = "Asp.Net Core",
                Price      = 20,
                CategoryId = 1
            };

            _categoryRepo.GetById(newBook.CategoryId).Returns(CategoryMock.GetValidSingle());
            try
            {
                //act
                _bookBLL.AddNewBook(newBook);
                _bookRepo.Received().Insert(Arg.Any <Book>());
            }
            catch
            {
                //assert
                Assert.Fail();
            }
        }