public async Task IfDailyEntryServiceFails_ShouldReturnErrors()
        {
            var request = new PayWithDebitRequest {
                ClientId = 10, Value = 5
            };
            var mockValidator    = new Mock <IValidator <PayWithDebitRequest> >();
            var validationResult = new ValidationResult();

            mockValidator.Setup(x => x.Validate(It.IsAny <PayWithDebitRequest>()))
            .Returns(validationResult);
            var mockCheckBalanceService = new Mock <ICheckingAccountBalanceService>();

            mockCheckBalanceService
            .Setup(x => x.HasSufficientBalance(request.ClientId, request.Value))
            .ReturnsAsync(true);
            var mockDailyEntryService = new Mock <IDailyEntryService>();

            mockDailyEntryService
            .Setup(x => x.SendDebit(request.ClientId, request.Value))
            .Throws(new System.Exception("Unexpected error"));
            var mockRepository = new Mock <IRecurrentPaymentRepository>();

            var handler = new PayWithDebitHandler(
                mockValidator.Object,
                mockCheckBalanceService.Object,
                mockDailyEntryService.Object,
                mockRepository.Object
                );

            var errors = await handler.Handle(request);

            errors.Should().NotBeEmpty();
        }
        public async Task IfRecurrentPaymentWasSaveWithSuccessfully_ShouldNotReturnErrors()
        {
            var request = new PayWithDebitRequest {
                ClientId = 10, Value = 5
            };
            var mockValidator    = new Mock <IValidator <PayWithDebitRequest> >();
            var validationResult = new ValidationResult();

            mockValidator.Setup(x => x.Validate(It.IsAny <PayWithDebitRequest>()))
            .Returns(validationResult);
            var mockCheckBalanceService = new Mock <ICheckingAccountBalanceService>();

            mockCheckBalanceService
            .Setup(x => x.HasSufficientBalance(request.ClientId, request.Value))
            .ReturnsAsync(true);
            var mockDailyEntryService = new Mock <IDailyEntryService>();
            var mockRepository        = new Mock <IRecurrentPaymentRepository>();

            var handler = new PayWithDebitHandler(
                mockValidator.Object,
                mockCheckBalanceService.Object,
                mockDailyEntryService.Object,
                mockRepository.Object
                );

            var errors = await handler.Handle(request);

            errors.Should().BeEmpty();
        }
        public async Task IfClientDoesNotHaveSufficienteBalance_ShouldReturnErrors()
        {
            var request = new PayWithDebitRequest {
                ClientId = 10, Value = 5
            };
            var handler = new HandlerBuilder()
                          .WithRequestValid()
                          .WithInsufficientBalance(request.ClientId, request.Value)
                          .Build();

            var errors = await handler.Handle(request);

            errors.Should().NotBeEmpty();
        }
        public async Task IfDailyEntryServiceFails_ShouldReturnErrors()
        {
            var request = new PayWithDebitRequest {
                ClientId = 10, Value = 5
            };
            var handler = new HandlerBuilder()
                          .WithRequestValid()
                          .WithSufficientBalance(request.ClientId, request.Value)
                          .WithDailyEntryServiceFailing(request.ClientId, request.Value)
                          .Build();

            var errors = await handler.Handle(request);

            errors.Should().NotBeEmpty();
        }
        public async Task IfRecurrentPaymentWasSaveWithSuccessfully_ShouldNotReturnErrors()
        {
            var request = new PayWithDebitRequest {
                ClientId = 10, Value = 5
            };

            var(handler, mockAssertions) = new HandlerBuilder()
                                           .WithRequestValid()
                                           .WithSufficientBalance(request.ClientId, request.Value)
                                           .BuildWithMock();

            var errors = await handler.Handle(request);

            errors.Should().BeEmpty();
            mockAssertions
            .ShouldCallRepository();
        }