コード例 #1
0
ファイル: BookServiceTests.cs プロジェクト: Indexu/LibraryAPI
        public void AddLoanException()
        {
            // Arrange
            int userID = 1;
            int bookID = 1;

            var mockBookRepo = new Mock <IBookRepository>();
            var mockLoanRepo = new Mock <ILoanRepository>();
            var mockMapper   = new Mock <IMapper>();

            mockLoanRepo.Setup(f => f.AddLoan(userID, bookID)).Throws(new Exception());

            var service = new BookService(mockBookRepo.Object, mockLoanRepo.Object, mockMapper.Object);

            // Act
            service.AddLoan(userID, bookID);
        }
コード例 #2
0
ファイル: BookServiceTests.cs プロジェクト: Indexu/LibraryAPI
        public void AddLoan()
        {
            // Arrange
            int userID = 1;
            int bookID = 1;

            var mockBookRepo = new Mock <IBookRepository>();
            var mockLoanRepo = new Mock <ILoanRepository>();
            var mockMapper   = new Mock <IMapper>();

            mockLoanRepo.Setup(f => f.AddLoan(userID, bookID)).Returns(1);

            var service = new BookService(mockBookRepo.Object, mockLoanRepo.Object, mockMapper.Object);

            // Act
            var returnedID = service.AddLoan(userID, bookID);

            // Assert
            mockLoanRepo.Verify(f => f.AddLoan(userID, bookID), Times.Once());
            Assert.IsNotNull(returnedID);
            Assert.AreEqual(returnedID, 1);
        }