public void AddOrUpdateProcess_GoodArgument_NotInDb_Success() { _mockBookRepository.Setup(w => w.GetById(It.IsAny <string>())).ReturnsAsync(_book); using var bookService = new BookService(_mockBookRepository.Object, _mapper); var addOrUpdateProcess = bookService.AddOrUpdateProcess("123", It.IsAny <string>(), 2); _mockBookRepository.Verify(w => w.UpdateProcess(It.IsAny <Book>(), It.IsAny <string>(), 2), Times.Never); _mockBookRepository.Verify(w => w.AddProcess(It.IsAny <Book>(), It.IsAny <string>(), 2), Times.Once); }
public void AddOrUpdateProcess_GoodArgument_InOnDb_Exception() { var book = new Book { Id = Guid.NewGuid().ToString(), Name = "SomeBookName", Year = 2020, BookUrl = "SomeBookUrl", ImageIrl = "SomeBookImageUrl", Description = "SomeBookDescription", Authors = new List <AuthorBook>(), Genres = new List <GenreBook>(), Likes = new List <BookLike>(), Assessments = new List <BookAssessment> { new BookAssessment { Id = Guid.NewGuid().ToString(), Book = It.IsAny <Book>(), BookId = It.IsAny <string>(), User = It.IsAny <User>(), Count = 7, UserId = "123" } }, Comments = new List <BookComment>(), Processes = new List <BookProcess> { new BookProcess { Id = Guid.NewGuid().ToString(), Book = It.IsAny <Book>(), User = It.IsAny <User>(), BookId = It.IsAny <string>(), UserId = "123", Process = 2 } } }; _mockBookRepository.Setup(w => w.GetById(It.IsAny <string>())).ReturnsAsync(book); using var bookService = new BookService(_mockBookRepository.Object, _mapper); var addOrUpdateProcess = bookService.AddOrUpdateProcess("123", "123", 2); _mockBookRepository.Verify(w => w.UpdateProcess(It.IsAny <Book>(), It.IsAny <string>(), 2), Times.Once); _mockBookRepository.Verify(w => w.AddProcess(It.IsAny <Book>(), It.IsAny <string>(), 2), Times.Never); }
public void AddOrUpdateProcess_BadArgument_Process_Exception() { _mockBookRepository.Setup(w => w.GetById(It.IsAny <string>())).ReturnsAsync(() => null); using var bookService = new BookService(_mockBookRepository.Object, _mapper); Assert.ThrowsAsync <CustomException>(() => bookService.AddOrUpdateProcess("123", It.IsAny <string>(), 4)); }