[TestMethod] //inte löst public void AddToLoanBookBelongsToActiveLoan() { var loanManagerMock = new Mock <ILoanManager>(); var bookManagerMock = new Mock <IBookManager>(); var customerManagerMock = new Mock <ICustomerManager>(); customerManagerMock.Setup(m => m.GetCustomerByCustomerID(It.IsAny <int>())) .Returns( new Customer { CustomerID = 4, } ); bookManagerMock.Setup(m => m.GetBookByBookNumber(It.IsAny <int>())) .Returns( new Book { BookNumber = 1, BookActiveLoan = true } );; var loanAPI = new LoanAPI(bookManagerMock.Object, null, customerManagerMock.Object); var successfull = loanAPI.AddLoan(1, 4); Assert.AreEqual(ErrorCodesLoan.BookBelongsToActiveLoan, successfull); loanManagerMock.Verify(m => m.AddLoan(3, 2, It.IsAny <DateTime>(), It.IsAny <DateTime>()), Times.Never()); }
public void AddToLoanNoSuchBook() { var bookManagerMock = new Mock <IBookManager>(); var loanAPI = new LoanAPI(bookManagerMock.Object, null, null); var result = loanAPI.AddLoan(0, 0); Assert.AreEqual(ErrorCodesLoan.NoSuchBook, result); }
private LoanedBookStatusCodes AddLoanNumberOne(Mock<ILoanManager> loanManagerMock) { var customerManagerMock = SetupMock(new Customer { CustomerName = "Erika Axelsson" }); var bookManagerMock = SetupMock(new Book { BookTitle = "Peter Pan", IsLoaned = false }); var loanAPI = new LoanAPI(loanManagerMock.Object, bookManagerMock.Object, customerManagerMock.Object); var successfull = loanAPI.AddLoan("Erika Axelsson", "Peter Pan"); return successfull; }
public void TestAddExistingLoanExtend() { Mock<ILoanManager> loanManagerMock = SetupMock(new Loan()); var customerManagerMock = SetupMock(new Customer { CustomerName = "Erika Axelsson" }); var bookManagerMock = SetupMock(new Book { BookTitle = "Peter Pan", IsLoaned = true }); var loanApi = new LoanAPI(loanManagerMock.Object, bookManagerMock.Object, customerManagerMock.Object); var result = loanApi.AddLoan("Erika Axelsson", "Peter Pan"); Assert.AreEqual(LoanedBookStatusCodes.ExtendLoan, result); }
public void TestCustomerHasToManyLoans() { Mock<ILoanManager> loanManagerMock = SetupMock(new Loan()); var customerManagerMock = SetupMock(new Customer { CustomerName = "Erika Axelsson" }); var bookManagerMock = SetupMock(new Book { BookID = 7, BookTitle = "Oliver Twist" }); loanManagerMock.Setup(m => m.GetLoanFromCustomer(It.IsAny<string>())) .Returns(new List<Loan> { new Loan { CustomerID = 1, BookID = 1 }, new Loan { CustomerID = 1, BookID = 2 }, new Loan { CustomerID = 1, BookID = 3 }, new Loan { CustomerID = 1, BookID = 4 }, new Loan { CustomerID = 1, BookID = 5 }, }); var loanApi = new LoanAPI(loanManagerMock.Object, bookManagerMock.Object, customerManagerMock.Object); var result = loanApi.AddLoan("Erika Axelsson", "Oliver Twist"); Assert.AreEqual(LoanedBookStatusCodes.CustomerHasToManyLoans, result); loanManagerMock.Verify( m => m.AddLoan(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.Is<string>(i => i == "Erika Axelsson"), It.Is<string>(i => i == "Oliver Twist")), Times.Never()); }
public void AddToLoanNoSuchCustomer() { var bookManagerMock = new Mock <IBookManager>(); bookManagerMock.Setup(m => m.GetBookByBookNumber(It.IsAny <int>())) .Returns( new Book() ); var customerManager = new Mock <ICustomerManager>(); var loanAPI = new LoanAPI(bookManagerMock.Object, null, customerManager.Object); var result = loanAPI.AddLoan(0, 0); Assert.AreEqual(ErrorCodesLoan.NoSuchCustomer, result); }
public void TestAddLoanNoSuchBook() { Mock<ILoanManager> loanManagerMock = SetupMock(new Loan()); var customerManagerMock = SetupMock(new Customer { CustomerID = 4, CustomerName = "Lovisa Lund" }); var bookManagerMock = SetupMock((Book)null); var loanApi = new LoanAPI(null, bookManagerMock.Object, customerManagerMock.Object); var result = loanApi.AddLoan("Lovisa Lund", "ABC Boken"); Assert.AreEqual(LoanedBookStatusCodes.NoSuchBook, result); loanManagerMock.Verify( m => m.AddLoan(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.Is<string>(i => i == "Lovisa Lund"), It.Is<string>(i => i == "ABC")), Times.Never()); }
public void TestAddExistingLoan() { var loanManagerMock = new Mock<ILoanManager>(); var customerManagerMock = SetupMock(new Customer { CustomerName = "Lovisa Lund"}); var bookManagerMock = SetupMock(new Book { BookTitle = "Peter Pan", IsLoaned = true }); var loanApi = new LoanAPI(loanManagerMock.Object, bookManagerMock.Object, customerManagerMock.Object); var result = loanApi.AddLoan("Lovisa Lund", "Peter Pan"); Assert.AreEqual(LoanedBookStatusCodes.BookIsLoaned, result); loanManagerMock.Verify( m => m.AddLoan(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.Is<string>(i => i == "Lovisa Lund"), It.Is<string>(i => i == "Peter Pan")), Times.Never()); }
public void TestAddLoanNoSuchCustomer() { Mock<ILoanManager> loanManagerMock = SetupMock(new Loan()); var customerManagerMock = SetupMock((Customer)null); var bookManagerMock = SetupMock(new Book { BookID = 4, BookTitle = "Moby Dick" }); var loanApi = new LoanAPI(null, bookManagerMock.Object, customerManagerMock.Object); var result = loanApi.AddLoan("Bobo Krut", "Moby Dick"); Assert.AreEqual(LoanedBookStatusCodes.NoSuchCustomer, result); loanManagerMock.Verify( m => m.AddLoan(It.IsAny<DateTime>(), It.IsAny<DateTime>(), It.Is<string>(i => i == "Gunvor Gnut"), It.Is<string>(i => i == "Moby Dick")), Times.Never()); }
public void addLoanOk() { var bookManagerMock = new Mock <IBookManager>(); var customerManagerMock = new Mock <ICustomerManager>(); var loanManagerMock = new Mock <ILoanManager>(); 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 = 1 } ); loanManagerMock.Setup(m => m.GetLoanByCustomers(It.IsAny <int>())) .Returns(new List <Loan> { new Loan { CustomerID = 1, BookID = 5 }, new Loan { CustomerID = 1, BookID = 3 }, new Loan { CustomerID = 1, BookID = 2 }, new Loan { CustomerID = 1, BookID = 6 }, } ); loanManagerMock.Setup(m => m.AddLoan(It.Is <int>(i => i == 3), It.Is <int>(i => i == 2), It.IsAny <DateTime>(), It.IsAny <DateTime>())); var loanAPI = new LoanAPI(bookManagerMock.Object, loanManagerMock.Object, customerManagerMock.Object); var successfull = loanAPI.AddLoan(4, 2); Assert.AreEqual(ErrorCodesLoan.Ok, successfull); loanManagerMock.Verify(m => m.AddLoan(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <DateTime>(), It.IsAny <DateTime>()), Times.Once); }