예제 #1
0
        public void CreateNewUserPaymentThenFindThenDelete()
        {
            var command = new SavePaymentInfoCommand();

            command.UserId                        = Guid.Parse("c9276b76-c56a-43ba-96b5-83b48a5fcce3");
            command.Id                            = Guid.NewGuid();
            command.PaymentInfo                   = new UserPaymentInfo();
            command.PaymentInfo.Token             = "thisisnotalegittoken";
            command.PaymentInfo.UserPaymentInfoId = Guid.NewGuid();

            var userRepo    = new MockUserRepository();
            var paymentRepo = new MockUserPaymentRepository();
            var encryptor   = new RijndaelManagedEncryptor();

            var handler = new PaymentCommandHandler(userRepo, paymentRepo, encryptor);

            handler.Handle(command);

            var paymentInfo = paymentRepo.Get(command.PaymentInfo);

            try
            {
                Assert.IsNotNull(paymentInfo);
                Assert.AreNotEqual(command.PaymentInfo.Token, "thisisnotalegittoken");
            }
            finally
            {
                paymentRepo.Remove(paymentInfo);
            }
        }
예제 #2
0
        public void PaymentCommandHandler_ValidRequest_Success()
        {
            // Arrange
            var command = FakeCommandRequest();

            var handler = new PaymentCommandHandler(_logger.Object, _paymentMethodRepository.Object);

            _paymentMethodRepository.Setup(x => x.Add(It.Is <PaymentMethod>(p =>
                                                                            p.Id == command.Id &&
                                                                            p.AcquiringBankId == _merchantIdValid &&
                                                                            p.MerchantId == _merchantIdValid &&
                                                                            p.Amount == command.Amount &&
                                                                            p.CardExpiry == command.CardExpiry &&
                                                                            p.CardNumber == command.CardNumber &&
                                                                            p.CurrencyCode == command.Currency &&
                                                                            p.CVV == command.CardCvv &&
                                                                            p.TransactionId == command.TransactionId &&
                                                                            p.Status == command.PaymentStatus &&
                                                                            p.ErrorDescription == command.ErrorDescription
                                                                            )))
            .Returns(Task.CompletedTask);


            // Act
            handler.Handle(command).Wait();


            //Assert
            _paymentMethodRepository.Verify(x => x.Add(It.IsAny <PaymentMethod>()), Times.Once);
        }
예제 #3
0
        private PaymentCommandHandler ReturnPaymentCommandHandlerObject(Mock <IMediatorHandler> mockMediatorHandler)
        {
            var mockDataProtectionProvider  = new Mock <IDataProtectionProvider>();
            var mockDataProtector           = new Mock <IDataProtector>();
            var mockIPaymentEventRepository = new Mock <IPaymentRepository>();
            var mockNotificationHandler     = new Mock <DomainNotificationHandler>();
            var mockTopicProducer           = new Mock <ITopicProducer <PaymentRegisteredEvent> >();

            var paymentCommandHandler = new PaymentCommandHandler(mockIPaymentEventRepository.Object,
                                                                  mockMediatorHandler.Object, mockDataProtectionProvider.Object, mockTopicProducer.Object,
                                                                  mockNotificationHandler.Object);

            mockDataProtectionProvider
            .Setup(dp => dp.CreateProtector(It.IsAny <string>()))
            .Returns(mockDataProtector.Object);

            mockDataProtector
            .Setup(sut => sut.Protect(It.IsAny <byte[]>()))
            .Returns(Encoding.UTF8.GetBytes("protectedText"));

            return(paymentCommandHandler);
        }
        public PaymentCommandHandlerTests()
        {
            _fixture               = new Fixture();
            _handlerMock           = new Mock <HttpMessageHandler>(MockBehavior.Strict);
            _paymentRepositoryMock = new Mock <IPaymentCommandRepository>();
            var httpClient = new HttpClient(_handlerMock.Object)
            {
                BaseAddress = new Uri("http://bank.com")
            };
            IOptions <AppSettings> appSettings = new OptionsWrapper <AppSettings>(new AppSettings
            {
                BankSimulatorPaymentUrl = "http://bank.com"
            });

            _paymentCommandHandler = new PaymentCommandHandler(new BankPaymentProcessor(httpClient, appSettings),
                                                               new PaymentCommandValidator(), _paymentRepositoryMock.Object);

            _validPaymentCommand = _fixture.Build <PaymentCommand>()
                                   .With(c => c.CardNumber, "1234567898765432")
                                   .With(c => c.ExpiryMonth, DateTime.Now.Month)
                                   .With(c => c.ExpiryYear, DateTime.Now.Year + 1)
                                   .With(c => c.CurrencyCode, "GBP")
                                   .Create();
        }