Example #1
0
        public void ReplaceLoan()
        {
            // Arrange
            int      userID         = 1;
            int      bookID         = 1;
            var      loanDate       = new DateTime(2000, 1, 1);
            DateTime?returnDate     = null;
            var      patchViewModel = MockDataGenerator.CreatePatchLoanViewModel(loanDate, returnDate);
            var      viewModel      = MockDataGenerator.CreateLoanViewModel(loanDate, returnDate);

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

            mockLoanRepo.Setup(f => f.UpdateLoan(userID, bookID, patchViewModel));
            mockMapper.Setup(x => x.Map <LoanViewModel, PatchLoanViewModel>(viewModel)).Returns(patchViewModel);

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

            // Act
            service.ReplaceLoan(userID, bookID, viewModel);

            // Assert
            mockLoanRepo.Verify(f => f.UpdateLoan(userID, bookID, patchViewModel), Times.Once());
            mockMapper.Verify(f => f.Map <LoanViewModel, PatchLoanViewModel>(viewModel), Times.Once());
        }
Example #2
0
        public void UpdateLoanException()
        {
            // Arrange
            int      userID         = 1;
            int      bookID         = 1;
            var      loanDate       = new DateTime(2000, 1, 1);
            DateTime?returnDate     = null;
            var      patchViewModel = MockDataGenerator.CreatePatchLoanViewModel(loanDate, returnDate);

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

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

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

            // Act
            service.UpdateLoan(userID, bookID, patchViewModel);
        }