public async Task <(bool status, string message)> ValidateBookAssignAsync(BookCountInfo currentBook, int userId) { if (currentBook.BookCount != 0) { var userAssignedBook = await Repository.GetFilteredAsync(p => p.UserID == userId && p.IsReturned == false); if (userAssignedBook.Count() == 0 || (userAssignedBook.Count() < 2 && userAssignedBook.Any(p => p.BookID != currentBook.BookID))) { return(true, "Success"); } return(false, "User cannot borrow more than two books or more than one copy of same books"); } return(false, "Book does not exist in the library"); }
public async Task ValidateBookAssignAsync_SameBookAssign_ReturnFalse() { using (var mock = AutoMock.GetLoose()) { var sampleAssignBook = new BookCountInfo { BookCount = 5, BookID = 4 }; var userId = 4; mock.Mock <IAssignBookRepository>() .Setup(x => x.GetFilteredAsync(p => p.UserID == userId && p.IsReturned == false)) .ReturnsAsync(SameBookSample()); var service = mock.Create <AssignBookService>(); var actual = await service.ValidateBookAssignAsync(sampleAssignBook, userId); Assert.True(!actual.status); } }