public BorrowViewModel(Borrow borrow) : this() { if (borrow == null) { throw new ArgumentNullException(nameof(borrow)); } this.BorrowerId = borrow.BorrowerId; this.BorrowId = borrow.BorrowId; this.BorrowerUserIdentity = borrow.Borrower.UserIdentityId; this.Start = borrow.Duration.Start; this.End = borrow.Duration.End; this.ProductId = borrow.ProductId; this.ProductStart = borrow.Product.Availability.Start; this.ProductEnd = borrow.Product.Availability.End; this.ProductName = borrow.Product.Name; this.ProductOwnerId = borrow.Product.OwnerId; this.ProductOwnerUserIdentity = borrow.Product.Owner.UserIdentityId; this.Score = borrow.AverageScore(); this.Status = borrow.Status.ToString(); this.Comments = new List <CommentViewModel>(); foreach (BorrowComment comment in borrow.Comments) { this.Comments.Add(new CommentViewModel(comment)); } }
public void GivenBorrowWhenAddScoreThenScoreIsAddedAndAverageIsCalculateOk() { int score1 = 5; int score2 = 1; int average = (score1 + score2) / 2; 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.Scores.Any()); borrow.AddScore(new Score(score1), lender); borrow.AddScore(new Score(score2), borrower); Assert.True(borrow.Scores.Any()); borrow.AverageScore().Should().Be(average); }