Exemplo n.º 1
0
            public void AddQueueItemIsSuccessful()
            {
                var queueDaoMock = new Mock<IQueueDao>();
                var payment = new Model.Booking.Payment
                    {
                        OrderId = 5,
                        CreatedByUserId = new Guid("00000000-0000-0000-0000-000000000000")
                    };
                var invoiceRequest = new SettlementInvoiceRequest
                    {
                        BusinessId = 10,
                        OrderId = payment.OrderId,
                        BookingId = 2,
                        OrderSourceCode = SourceType.Online.GetCode()
                    };
                queueDaoMock.Setup(q => q.AddQueueItem(It.Is<QueueItem>(qi =>
                    qi.PayloadType == PayloadTypeEnum.BookingInv &&
                    qi.QueueCode == QueueCodeType.SettlementInvoiceRequest &&
                    qi.UserId == payment.CreatedByUserId &&
                    qi.Key == payment.OrderId.ToString() &&
                    qi.Payload.IndexOf("10") > 0))).Returns(new QueueItem());

                QueueManager manager = new QueueManager
                    {
                        QueueDao = queueDaoMock.Object
                    };
                QueueItem item = new PaymentManager().GetSettlementQueueItemFromPayment(payment, invoiceRequest);
                manager.AddQueueItem(item);

                queueDaoMock.VerifyAll();
            }
Exemplo n.º 2
0
            public void GetPaymentsByOrderWithValidOrderIdReturnsPayments()
            {
                // Arrange
                var paymentManager = new PaymentManager();
                const int ORDER_ID = 1;
                const long BUSINESS_ID = 1;
                CacheHelper.StubBusinessCacheSingleBusiness(BUSINESS_ID, "TestBus");

                var payments = new List<Model.Booking.Payment>
                                      {
                                          new Model.Booking.Payment
                                          {
                                              Id = 1
                                          },
                                          new Model.Booking.Payment
                                          {
                                              Id = 2
                                          }
                                      };

                var paymentDao = new Mock<IPaymentDao>();
                paymentManager.PaymentDao = paymentDao.Object;
                paymentDao.Setup(b => b.GetPaymentsByOrder(ORDER_ID)).Returns(payments);

                // Act
                var paymentsReturnedByManager = paymentManager.GetPaymentsByOrder(ORDER_ID, BUSINESS_ID);

                // Assert
                Assert.IsNotNull(paymentsReturnedByManager, "Payments are null.");
                Assert.AreEqual(payments, paymentsReturnedByManager, "Order payments return are not correct.");

                paymentDao.VerifyAll();
                CacheHelper.ReAssignBusinessDaoToBusinessCache();
            }
Exemplo n.º 3
0
            public void GetPaymentByKeyWithValidPaymentIdReturnsPayment()
            {
                // Arrange
                var paymentManager = new PaymentManager();
                const int PAYMENT_ID = 1;

                var payment = new Model.Booking.Payment { Id = 1 };

                var paymentDao = new Mock<IPaymentDao>();
                paymentManager.PaymentDao = paymentDao.Object;

                paymentDao.Setup(b => b.GetByKey(PAYMENT_ID)).Returns(payment);

                // Act
                var paymentReturnedByManager = paymentManager.GetPaymentByKey(PAYMENT_ID);

                // Assert
                Assert.IsNotNull(paymentReturnedByManager, "Payment is null.");
                paymentDao.VerifyAll();
            }
Exemplo n.º 4
0
            public void PreauthoriseAmountWithNoCurrencyCodeThrowsException()
            {
                // Arrange
                const string ORDER_REFERENCE = "TST-123-456";
                const string CURRENCY_CODE = "";

                var amount = new decimal(10);

                var paymentManager = new PaymentManager();

                // Act
                try
                {
                    paymentManager.PreauthoriseAmount(ORDER_REFERENCE, amount, CURRENCY_CODE);

                    // Assert
                    Assert.Fail("An exception SRVEX30124 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual("SRVEX30124", ex.Code, "The Validation exception is not returning the right error code");
                }
            }
Exemplo n.º 5
0
            public void PreauthoriseAmountIsSuccessful()
            {
                // Arrange
                const string ORDER_REFERENCE = "TST-123-456";
                const string CURRENCY_CODE = "GBP";

                var amount = new decimal(10);

                var eviivoPaymentServiceClient = new Mock<IPaymentServiceServiceClient>();

                var paymentManager = new PaymentManager
                    {
                        EviivoPaymentServiceClient = eviivoPaymentServiceClient.Object
                    };

                eviivoPaymentServiceClient.Setup(b => b.PlacePreAuth(ORDER_REFERENCE, amount, CURRENCY_CODE)).Returns(true);

                // Act
                var result = paymentManager.PreauthoriseAmount(ORDER_REFERENCE, amount, CURRENCY_CODE);

                // Assert
                Assert.IsTrue(result, "Preauth was not successul");
            }
Exemplo n.º 6
0
            public void GetPaymentMethods()
            {
                const string CULTURE_CODE = "en";

                var initialCardTypes = new[] {CardTypeEnum.AMEX, CardTypeEnum.Maestro, CardTypeEnum.Visa, CardTypeEnum.VisaElectron};
                var cardTypeDao = new Mock<ICardTypeDao>();

                var paymentManager = new PaymentManager
                {
                    CardTypeDao = cardTypeDao.Object
                };

                // Create a list of closeout reasons
                var cardTypeData = from cardType
                                   in initialCardTypes
                                   select new CardType {Code = cardType.GetCode()};

                cardTypeDao.Setup(x => x.GetAll(CULTURE_CODE)).Returns(cardTypeData.ToList());

                var cardTypes = paymentManager.GetCardTypes(CULTURE_CODE);

                Assert.AreEqual(4, cardTypes.Count, "Check that correct number of card types methods are returned.");

                cardTypeDao.VerifyAll();
            }
Exemplo n.º 7
0
            public void GetPaymentMethods()
            {
                const string CULTURE_CODE = "en";

                var paymentMethodDao = new Mock<IPaymentMethodDao>();

                var paymentManager = new PaymentManager
                {
                    PaymentMethodDao = paymentMethodDao.Object
                };

                // Create a list of closeout reasons
                var paymentMethodData = new List<PaymentMethod>
                                         {
                                             new PaymentMethod
                                             {
                                                 Code = PaymentMethodEnum.AccountTransfer.GetCode()
                                             },
                                             new PaymentMethod
                                             {
                                                 Code = PaymentMethodEnum.BankTransfer.GetCode()
                                             },
                                             new PaymentMethod
                                             {
                                                 Code = PaymentMethodEnum.Cash.GetCode()
                                             },
                                             new PaymentMethod
                                             {
                                                 Code = PaymentMethodEnum.Cheque.GetCode()
                                             }
                                         };

                paymentMethodDao.Setup(x => x.GetAll(CULTURE_CODE)).Returns(paymentMethodData);

                var paymentMethods = paymentManager.GetPaymentMethods(CULTURE_CODE);

                Assert.AreEqual(4, paymentMethods.Count, "Check that correct number of payment methods are returned.");

                paymentMethodDao.VerifyAll();
            }
Exemplo n.º 8
0
            public void CreatePaymentInvalidReceivedDateThrowsValidationException()
            {
                // Arrange
                var stubPaymentDao = MockRepository.GenerateStub<IPaymentDao>();
                var paymentManager = new PaymentManager
                {
                    PaymentDao = stubPaymentDao
                };

                var payment = new Model.Booking.Payment
                {
                    Amount = new decimal(10.00),
                    ReceivedDate = DateTime.Today.AddDays(10),
                    Currency = new Currency("GBP"),
                    PaymentMethod = new PaymentMethod { Code = PaymentMethodEnum.Cash.GetCode() },
                    PaymentSource = new PaymentSource { Code = PaymentSourceEnum.Pms.GetCode() },
                    PaymentStatus = new PaymentStatus { Code = PaymentStatusEnum.Created.GetCode() },
                    PaymentType = new PaymentType { Code = PaymentTypeEnum.Payment.GetCode() },
                    Notes = "New Payment"
                };

                stubPaymentDao.Stub(b => b.Create(payment)).WhenCalled(delegate { payment.Id = 1; });

                try
                {
                    // Act
                    paymentManager.CreatePaymentForOrder(payment, 1);

                    // Assert
                    Assert.Fail("An exception SRVEX30071 of type ValidationException should have been thrown");
                }
                catch (ValidationException ex)
                {
                    // Assert
                    Assert.AreEqual("SRVEX30071", ex.Code, "The Validation exception is not returning the right error code");
                }

                // Make sure this is reset for future tests
                paymentManager.PaymentDao = new PaymentDao();
            }
Exemplo n.º 9
0
            public void CreatePaymentCreatesEvents()
            {
                // Arrange
                var mockEventTrackingManager = MockRepository.GenerateMock<IEventTrackingManager>();
                CacheHelper.StubBusinessCacheSingleBusiness(1, "TestBus1");

                var paymentManager = new PaymentManager
                {
                    PaymentDao = MockRepository.GenerateStub<IPaymentDao>(),
                    EventTrackingManager = mockEventTrackingManager
                };

                var payment = new Model.Booking.Payment
                {
                    Id = 1,
                    OrderId = 1,
                    Amount = new decimal(10.00),
                    ReceivedDate = DateTime.Today,
                    Currency = new Currency("GBP"),
                    PaymentMethod = new PaymentMethod { Code = PaymentMethodEnum.Cash.GetCode() },
                    PaymentSource = new PaymentSource { Code = PaymentSourceEnum.Pms.GetCode() },
                    PaymentStatusEnum = PaymentStatusEnum.Created,
                    PaymentTypeEnum = PaymentTypeEnum.Payment,
                    Notes = "New Payment"                    
                };

                mockEventTrackingManager.Expect(
                    u =>
                    u.CreatePaymentEvent(Arg<int>.Is.Equal(payment.Id),
                                         Arg<PaymentEventTypeEnum>.Is.Equal(PaymentEventTypeEnum.Created), Arg<string>.Is.Equal(payment.Notes)))
                                        .Repeat.Once(); ;

                mockEventTrackingManager.Expect(
                    ev =>
                    ev.CreateOrderEvent(Arg<int>.Is.Equal(payment.OrderId),
                                        Arg<OrderEventTypeEnum>.Is.Equal(OrderEventTypeEnum.PaymentAdded), Arg<string>.Is.Equal(payment.Id.ToString()), Arg<string>.Is.Equal(payment.Notes)))
                                        .Repeat.Once();
                
                paymentManager.CreatePaymentForOrder(payment, 1);

                CacheHelper.ReAssignBusinessDaoToBusinessCache();
                // Assert
                mockEventTrackingManager.VerifyAllExpectations();
            }
Exemplo n.º 10
0
            public void CreateRefundIsSuccessful()
            {
                // Arrange
                const int PAYMENT_ID = 1;
                var stubPaymentDao = MockRepository.GenerateStub<IPaymentDao>();
                var paymentManager = new PaymentManager
                {
                    PaymentDao = stubPaymentDao
                };

                var payment = new Model.Booking.Payment
                {
                    Id = PAYMENT_ID,
                    Amount = new decimal(10.00),
                    ReceivedDate = DateTime.Today,
                    Currency = new Currency("GBP"),
                    PaymentMethod = new PaymentMethod { Code = PaymentMethodEnum.Cash.GetCode() },
                    PaymentSource = new PaymentSource { Code = PaymentSourceEnum.Pms.GetCode() },
                    PaymentStatusEnum = PaymentStatusEnum.Deleted,
                    PaymentTypeEnum = PaymentTypeEnum.Refund,
                    Notes = "New Payment"
                };

                stubPaymentDao.Stub(b => b.Create(payment)).WhenCalled(delegate { payment.Id = 1; });

                // Act
                paymentManager.CreatePaymentForOrder(payment, 1);

                // Assert
                Assert.IsNotNull(payment.Id, "The payment reversal id was not attributed.");

                // Make sure this is reset for future tests
                paymentManager.PaymentDao = new PaymentDao();
            }
Exemplo n.º 11
0
            protected override void RunBeforeAllTests()
            {
                base.RunBeforeAllTests();

                GuestManager guestManager = new GuestManager();
                PaymentManager paymentManager = new PaymentManager();

                Guest guest = new Guest
                {
                    BusinessId = BUSINESS_ID,
                    DefaultCultureCode = "en-GB",
                    AddressLine1 = "AL1",
                    City = "City",
                    Forename = "Bob",
                    Surname = "Smith"
                };
                guestManager.Create(guest);

                var mockOrder = new Order
                {
                    IntegrationType = IntegrationTypeEnum.Myweb,
                    OfflineSourceEnum = OfflineSourceEnum.Web,
                    CustomerCurrencyCode = "GBP",
                    OrderSourceCode = SourceType.Online.GetCode(),
                    LeadGuest = guest,
                    LeadGuestId = guest.Id.Value
                };

                orderDao.CreateOrder(BUSINESS_ID, mockOrder);

                // set up payment for the order
                setupPayment = new Model.Booking.Payment
                                   {
                                       OrderId = mockOrder.Id.Value,
                                       PaymentSourceEnum = PaymentSourceEnum.Online,
                                       PaymentTypeEnum = PaymentTypeEnum.Payment,
                                       PaymentMethodEnum = PaymentMethodEnum.AccountTransfer,
                                       Currency = new Currency(mockOrder.CustomerCurrencyCode),
                                       Amount = 30,
                                       Notes = "Test Notes",
                                       PaymentStatusEnum = PaymentStatusEnum.Created,
                                       ReceivedDate = DateTime.Now.AddDays(-5),
                                       MerchantType = MerchantTypeEnum.EviivoAccount
                                   };

                paymentManager.CreatePaymentForOrder(setupPayment, BUSINESS_ID);
            }