public async Task GivenBorrowServiceWhenSetScoreWithInvalidScoreThenThrowScoreOutRangeException()
        {
            Borrow          borrowDomain         = FakeBuilder.GetBorrowFake();
            ClaimsPrincipal user                 = new ClaimsPrincipal();
            int             scoreLessThanOne     = 0;
            int             scoreGreaterThanFive = 6;

            this._mockUserManager.Setup(mock => mock.FindUserDomain(It.IsAny <ClaimsPrincipal>()))
            .Returns(Task.FromResult(new User(Guid.NewGuid().ToString())));

            this._mockBorrowRepository
            .Setup(mock => mock.Get(borrowDomain.BorrowId))
            .ReturnsAsync(borrowDomain);

            await Assert
            .ThrowsAsync <ScoreOutRangeException>(() => this._borrowService.SetScore(borrowDomain.BorrowId, user, scoreLessThanOne));

            this._mockBorrowRepository
            .Verify(mock => mock.Save(It.IsAny <Borrow>()), Times.Never);

            await Assert
            .ThrowsAsync <ScoreOutRangeException>(() => this._borrowService.SetScore(borrowDomain.BorrowId, user, scoreGreaterThanFive));

            this._mockBorrowRepository
            .Verify(mock => mock.Save(It.IsAny <Borrow>()), Times.Never);
        }
        public async Task GivenBorrowServiceWhenSetScoreWithUserIsNullThenThrowArgumentNullException()
        {
            Borrow borrowDomain = FakeBuilder.GetBorrowFake();

            this._mockBorrowRepository.Setup(repo => repo.Get(It.IsAny <int>()))
            .ReturnsAsync(borrowDomain);
            int score = 5;

            ClaimsPrincipal user = null;
            await Assert.ThrowsAsync <ArgumentNullException>(() => this._borrowService.SetScore(borrowDomain.BorrowId, user, score));
        }
        public async Task GivenBorrowServiceWhenCloseWithBorrowFoundAndCreatedThenStatusInvalidException()
        {
            Borrow borrowDomain = FakeBuilder.GetBorrowFake();

            Assert.True(borrowDomain.Status == BorrowStatus.Created);

            this._mockBorrowRepository.Setup(repo => repo.Get(It.IsAny <int>()))
            .ReturnsAsync(borrowDomain);

            await Assert.ThrowsAsync <StatusInvalidException>(() =>
                                                              this._borrowService.Close(borrowDomain.BorrowId));

            this._mockBorrowRepository.Verify(mock => mock.Save(It.IsAny <Borrow>()), Times.Never);
        }
        public async Task GivenBorrowServiceWhenRejectWithBorrowFoundAndCreatedThenIsUpdated()
        {
            Borrow borrowDomain = FakeBuilder.GetBorrowFake();

            Assert.True(borrowDomain.Status == BorrowStatus.Created);

            this._mockBorrowRepository.Setup(repo => repo.Get(It.IsAny <int>()))
            .ReturnsAsync(borrowDomain);

            await this._borrowService.Reject(borrowDomain.BorrowId);

            this._mockBorrowRepository.Verify(mock => mock.Save(It.IsAny <Borrow>()), Times.Once);
            Assert.True(borrowDomain.Status == BorrowStatus.Rejected);
        }
        public async Task GivenBorrowServiceWhenAddCommentWithUserIsNullThenThrowArgumentNullException()
        {
            Borrow borrowDomain = FakeBuilder.GetBorrowFake();

            this._mockBorrowRepository.Setup(repo => repo.Get(It.IsAny <int>()))
            .ReturnsAsync(borrowDomain);
            string          comment = "aaaa";
            ClaimsPrincipal user    = null;

            await Assert
            .ThrowsAsync <ArgumentNullException>(() => this._borrowService.AddComment(borrowDomain.BorrowId, comment, user));

            this._mockBorrowRepository
            .Verify(mock => mock.Save(It.IsAny <Borrow>()), Times.Never);
        }
        public async Task GivenBorrowServiceWhenBorrowIdExistThenReturnBorrowNotNull()
        {
            int?   borrowId     = 1;
            Borrow borrowDomain = FakeBuilder.GetBorrowFake();

            this._mockBorrowRepository.Setup(repo => repo.Get(It.IsAny <int>()))
            .ReturnsAsync(borrowDomain);

            BorrowViewModel borrowViewModel = await this._borrowService.Get(borrowId);

            Assert.NotNull(borrowViewModel);
            borrowViewModel.BorrowId.Should().Be(borrowDomain.BorrowId);
            borrowViewModel.BorrowerId.Should().Be(borrowDomain.BorrowerId);
            borrowViewModel.Start.Should().Be(borrowDomain.Duration.Start);
            borrowViewModel.End.Should().Be(borrowDomain.Duration.End);
            borrowViewModel.Status.Should().Be(borrowDomain.Status.ToString());
        }
        public async Task GivenBorrowServiceWhenSetScoreWithValidScoreThenIsUpdate()
        {
            Borrow          borrowDomain = FakeBuilder.GetBorrowFake();
            ClaimsPrincipal user         = new ClaimsPrincipal();
            int             score        = 3;

            this._mockUserManager.Setup(mock => mock.FindUserDomain(It.IsAny <ClaimsPrincipal>()))
            .Returns(Task.FromResult(new User(Guid.NewGuid().ToString())));

            this._mockBorrowRepository
            .Setup(mock => mock.Get(borrowDomain.BorrowId))
            .ReturnsAsync(borrowDomain);

            await this._borrowService.SetScore(borrowDomain.BorrowId, user, score);

            this._mockBorrowRepository
            .Verify(mock => mock.Save(It.IsAny <Borrow>()), Times.Once);
        }
        public async Task GivenBorrowServiceWhenAddCommentWithValidCommentThenIsUpdated()
        {
            Borrow          borrowDomain = FakeBuilder.GetBorrowFake();
            ClaimsPrincipal user         = new ClaimsPrincipal();
            string          comment      = "aaaaaa";

            this._mockUserManager.Setup(mock => mock.FindUserDomain(It.IsAny <ClaimsPrincipal>()))
            .Returns(Task.FromResult(new User(Guid.NewGuid().ToString())));

            this._mockBorrowRepository
            .Setup(mock => mock.Get(borrowDomain.BorrowId))
            .ReturnsAsync(borrowDomain);

            await this._borrowService.AddComment(borrowDomain.BorrowId, comment, user);

            this._mockBorrowRepository
            .Verify(mock => mock.Save(It.IsAny <Borrow>()), Times.Once);
            Assert.True(borrowDomain.Comments.Count == 1);
        }
        public async Task GivenBorrowServiceWhenChangeDurationWithBorrowFoundThenBorrowIsUpdated()
        {
            int             productId       = 0;
            Borrow          borrowDomain    = FakeBuilder.GetBorrowFake();
            BorrowViewModel borrowViewModel = FakeBuilder.GetBorrowViewModelFake(0, productId);

            this._mockBorrowRepository.Setup(mock => mock.Get(It.IsAny <int>()))
            .ReturnsAsync(borrowDomain);

            borrowDomain.BorrowId.Should().Be(borrowViewModel.BorrowId);
            borrowDomain.Duration.Start.Should().NotBe(borrowViewModel.Start);
            borrowDomain.Duration.End.Should().NotBe(borrowViewModel.End);
            borrowDomain.Status.ToString().Should().Be(borrowViewModel.Status);

            await this._borrowService.ChangeDuration(borrowViewModel.BorrowId, borrowViewModel.Start, borrowViewModel.End);

            borrowViewModel.BorrowId.Should().Be(borrowDomain.BorrowId);
            borrowViewModel.Start.Should().Be(borrowDomain.Duration.Start);
            borrowViewModel.End.Should().Be(borrowDomain.Duration.End);
            borrowViewModel.Status.Should().Be(borrowDomain.Status.ToString());

            this._mockBorrowRepository.Verify(mock => mock.Save(It.IsAny <Borrow>()), Times.Once);
        }