public async Task GivenBorrowServiceWhenCreateWithDataValidThenCreateNewBorrow()
        {
            int             productId = 0;
            BorrowViewModel model     = FakeBuilder.GetBorrowViewModelFake(0, productId);

            this._mockUserManager.Setup(mock => mock.FindUserDomain(It.IsAny <ClaimsPrincipal>()))
            .Returns(Task.FromResult(new User(Guid.NewGuid().ToString())));
            this._mockProductRepository.Setup(mock => mock.Get(It.IsAny <int>()))
            .Returns(Task.FromResult(FakeBuilder.GetProductFake()));
            await this._borrowService.Create(new ClaimsPrincipal(), model);

            this._mockBorrowRepository.Verify(mock => mock.Save(It.IsAny <Borrow>()), Times.Once);
            Assert.True(true);
        }
        public async Task GivenBorrowServiceWhenCreateWithUnavailableProductDateThenProductNoAvailableException()
        {
            Product productDomain = FakeBuilder.GetProductFake();

            productDomain.EditAvailability(new Term(DateTime.Now.AddYears(2), DateTime.Now.AddYears(4)));
            BorrowViewModel model = FakeBuilder.GetBorrowViewModelFake(0, productDomain.ProductId);

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

            this._mockProductRepository.Setup(mock => mock.Get(It.IsAny <int>()))
            .Returns(Task.FromResult(productDomain));

            await Assert.ThrowsAsync <ProductNoAvailableException>(() => this._borrowService.Create(new ClaimsPrincipal(), model));

            this._mockBorrowRepository.Verify(mock => mock.Save(It.IsAny <Borrow>()), Times.Never);
        }
        public async Task GivenBorrowServiceWhenCreateWithProductUnsharyThenStatusInvalidException()
        {
            Product productDomain = FakeBuilder.GetProductFake();

            productDomain.UnShary();
            Assert.True(productDomain.IsUnshary());

            BorrowViewModel model = FakeBuilder.GetBorrowViewModelFake(0, productDomain.ProductId);

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

            this._mockProductRepository.Setup(mock => mock.Get(It.IsAny <int>()))
            .Returns(Task.FromResult(productDomain));

            await Assert.ThrowsAsync <StatusInvalidException>(() => this._borrowService.Create(new ClaimsPrincipal(), model));

            this._mockBorrowRepository.Verify(mock => mock.Save(It.IsAny <Borrow>()), Times.Never);
        }
        public async Task GivenBorrowServiceWhenCreateWithBorrowOwnerIsEqualProductOwnerThenInvalidOperationException()
        {
            User            user          = FakeBuilder.GetOwnerFake();
            Product         productDomain = FakeBuilder.GetProductFake(user);
            BorrowViewModel model         = FakeBuilder.GetBorrowViewModelFake(0, productDomain.ProductId);

            model.BorrowerId     = productDomain.OwnerId;
            model.ProductOwnerId = productDomain.OwnerId;

            this._mockUserManager.Setup(mock => mock.FindUserDomain(It.IsAny <ClaimsPrincipal>()))
            .Returns(Task.FromResult(user));

            this._mockProductRepository.Setup(mock => mock.Get(It.IsAny <int>()))
            .Returns(Task.FromResult(productDomain));

            await Assert.ThrowsAsync <BorrowerIsSameOwnerProductException>(() => this._borrowService.Create(new ClaimsPrincipal(), model));

            this._mockBorrowRepository.Verify(mock => mock.Save(It.IsAny <Borrow>()), Times.Never);
        }
        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);
        }