public void GivenBorrowWhenAddCommentThenCommentIsAdded() { User borrower = new User("Test"); User lender = new User("Test1"); Product product = new Product(lender, "Test", "Test", new ProductType(), new Term(DateTime.Now.AddDays(-6), DateTime.Now)); Borrow borrow = new Borrow(borrower, product, new Term(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(-1))); Assert.False(borrow.Comments.Any()); borrow.AddComment("comment", lender); Assert.True(borrow.Comments.Any()); }
public void GivenBorrowWhenAddCommentInBlankThenCommentNotIsAddedAndThrowException() { User borrower = new User("Test"); User lender = new User("Test1"); Product product = new Product(lender, "Test", "Test", new ProductType(), new Term(DateTime.Now.AddDays(-6), DateTime.Now)); Borrow borrow = new Borrow(borrower, product, new Term(DateTime.Now.AddDays(-2), DateTime.Now.AddDays(-1))); Assert.False(borrow.Comments.Any()); Assert.Throws <ArgumentException>(() => borrow.AddComment("", lender)); Assert.False(borrow.Comments.Any()); }
public async Task AddComment(int borrowId, string comment, ClaimsPrincipal user) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (string.IsNullOrWhiteSpace(comment)) { throw new ArgumentNullException(nameof(comment)); } User userDomain = await this._userManager.FindUserDomain(user); Borrow borrowDomain = await GetBorrowAsync(borrowId); borrowDomain.AddComment(comment, userDomain); await this._borrowRepository.Save(borrowDomain); }