public void ReturnLoanLoanNoSuchCustomer() { var loanManagerMock = new Mock <ILoanManager>(); var customerManagerMock = new Mock <ICustomerManager>(); var bookManagerMock = new Mock <IBookManager>(); loanManagerMock.Setup(m => m.GetLoanByCustomerAndBook(It.IsAny <int>(), (It.IsAny <int>()))) .Returns(new Loan { CustomerID = 2, BookID = 2 }); bookManagerMock.Setup(m => m.GetBookByBookNumber(It.IsAny <int>())) .Returns(new Book { BookNumber = 2 }); var loanAPI = new LoanAPI(bookManagerMock.Object, loanManagerMock.Object, customerManagerMock.Object); var result = loanAPI.ReturnLoan(2, 2); Assert.AreEqual(ErrorCodesReturnBook.NoSuchCustomer, result); loanManagerMock.Verify(m => m.ReturnLoan(2, 2), Times.Never()); }
public void ReturnLoanNoOpenLoan() { var bookManagerMock = new Mock <IBookManager>(); var loanManagerMock = new Mock <ILoanManager>(); var customerManagerMock = new Mock <ICustomerManager>(); bookManagerMock.Setup(m => m.GetBookByBookNumber(It.IsAny <int>())) .Returns( new Book { BookNumber = 2 } ); customerManagerMock.Setup(m => m.GetCustomerByCustomerID(It.IsAny <int>())) .Returns( new Customer { CustomerID = 4 } ); loanManagerMock.Setup(m => m.GetLoanByCustomerAndBook(It.Is <int>(i => i == 2), (It.Is <int>(i => i == 4)))) .Returns( new Loan { CustomerID = 4, BookID = 3 }); loanManagerMock.Setup(m => m.ReturnLoan(It.Is <int>(i => i == 3), It.Is <int>(i => i == 2))); var loanAPI = new LoanAPI(bookManagerMock.Object, loanManagerMock.Object, customerManagerMock.Object); var successfull = loanAPI.ReturnLoan(2, 4); Assert.AreEqual(ErrorCodesReturnBook.NoOpenLoan, successfull); loanManagerMock.Verify(m => m.ReturnLoan(It.IsAny <int>(), It.IsAny <int>()), Times.Never); }
[TestMethod] //inte löst public void ReturnLoanLoanOk() { var loanManagerMock = new Mock <ILoanManager>(); var bookManagerMock = new Mock <IBookManager>(); var customerManagerMock = new Mock <ICustomerManager>(); loanManagerMock.Setup(m => m.GetLoanByCustomerAndBook(It.IsAny <int>(), It.IsAny <int>())) .Returns(new Loan { LoanID = 2, Items = new Book() }); customerManagerMock.Setup(m => m.GetCustomerByCustomerID(It.IsAny <int>())) .Returns(new Customer { CustomerID = 2 }); bookManagerMock.Setup(m => m.GetBookByBookNumber(It.IsAny <int>())) .Returns( new Book { BookNumber = 1, BookActiveLoan = true } ); var loanAPI = new LoanAPI(bookManagerMock.Object, loanManagerMock.Object, customerManagerMock.Object); var result = loanAPI.ReturnLoan(2, 2); Assert.AreEqual(ErrorCodesReturnBook.Ok, result); loanManagerMock.Verify(m => m.ReturnLoan(It.IsAny <int>(), (It.IsAny <int>())), Times.Once()); }