Exemplo n.º 1
0
        public void GivenAPaymentProcessingRequestIsProvided_WhenPostingToAcquirerBank_ThenItReturnsABankingResponse()
        {
            // Given

            var mockedAcquirerBankingService = Substitute.For <IAcquirerBankingService>();
            var mockedLogger = Substitute.For <ILogger <BankingHandler> >();

            var realBankingHandler = new BankingHandler(mockedLogger, mockedAcquirerBankingService);
            var request            = new PaymentProcessingRequest();

            mockedAcquirerBankingService
            .Post(request)
            .Returns(new BankingResponse {
                Success = true, TransactionId = Guid.NewGuid()
            });

            // When

            var response = realBankingHandler.Handle(request).GetAwaiter().GetResult();

            // Then

            response.Should().NotBeNull();
            response.Should().BeOfType <BankingResponse>();
            response.Success.Should().BeTrue();
        }
Exemplo n.º 2
0
        public void GivenAcquirerBankingServiceThrowsAnException_WhenPostingToAcquirerBank_ThenItReturnsABankingException()
        {
            // Given

            var mockedAcquirerBankingService = Substitute.For <IAcquirerBankingService>();
            var mockedLogger = Substitute.For <ILogger <BankingHandler> >();

            var realBankingHandler = new BankingHandler(mockedLogger, mockedAcquirerBankingService);
            var request            = new PaymentProcessingRequest();

            var exception = new Exception("Exception thrown");

            mockedAcquirerBankingService
            .Post(request)
            .Throws(exception);

            // When

            var response = Assert.Throws <BankingException>(() => realBankingHandler.Handle(request).GetAwaiter().GetResult());

            // Then

            response.Should().NotBeNull();
            response.Should().BeOfType <BankingException>();
            response.Message.Should().Be(exception.Message);
        }
Exemplo n.º 3
0
        public IUser RegisterTestUser(string userType)
        {
            if (userType.ToLower().Contains("basic"))
            {
                _user = new RegistrationHandler().RegisterUser(new BasicUser());
            }
            else if (userType.ToLower().Contains("banking"))
            {
                var basicUser = new RegistrationHandler().RegisterUser(new BasicUser());
                _user = new BankingHandler().RegisterUser(new BankingUser(basicUser));
            }
            else if (userType.ToLower().Contains("bonus"))
            {
                var basicUser   = new RegistrationHandler().RegisterUser(new BasicUser());
                var bankingUser = new BankingHandler().RegisterUser(new BankingUser(basicUser));
                _user = new BonusSystemHandler().RegisterUser(new BonusUser(bankingUser, basicUser));
            }

            return(_user);
        }