public static CreateNewBookInput GetInputWithNotValidCategoryMock() { var newBookInput = new CreateNewBookInput() { CategoryId = 0, }; return(newBookInput); }
public static CreateNewBookInput GetValidInputMock() { var newBookInput = new CreateNewBookInput() { CategoryId = 1, Price = 5, Description = "Book Description", Title = "Clean Code" }; return(newBookInput); }
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); } }
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(); } }