public void HandleBookPayment_Failure() { // Arrange var packagingSlipServiceResponse = new PackagingSlipGenerationResponse { PackagingSlipGenerationResponseType = PackagingSlipGenerationResponseType.Failure }; packagingSlipServiceMock.Setup(c => c.GenerateDuplicateSlip(It.IsAny <Department>())).Returns(packagingSlipServiceResponse); var payment = CreatePayment(); var target = new BookPaymentFacade(packagingSlipServiceMock.Object, commissionServiceMock.Object, agentServiceMock.Object); // Act var result = target.HandleBookPayment(payment); // Assert Assert.AreEqual(PaymentResponseType.Failure, result.PaymentResponseType); packagingSlipServiceMock.Verify(c => c.GenerateDuplicateSlip(It.IsAny <Department>()), Times.Once); commissionServiceMock.Verify(c => c.Calculate(It.IsAny <double>()), Times.Never); }
public PaymentResponse Pay(Payment payment) { PaymentResponse paymentResponse; if (!payment.Validate(out paymentResponse)) { Logger.Instance.Log(LoggerType.Error, paymentResponse.ErrorMessage); return(paymentResponse); } try { switch (payment.PaymentType) { case PaymentType.PhysicalProduct: PhysicalProductPaymentFacade physicalProductPaymentFacade = new PhysicalProductPaymentFacade(container.Resolve <IPackagingSlipService>(), container.Resolve <ICommissionService>(), container.Resolve <IAgentService>()); return(physicalProductPaymentFacade.HandlePhysicalProductPayment(payment)); case PaymentType.Book: BookPaymentFacade bookPaymentFacade = new BookPaymentFacade(container.Resolve <IPackagingSlipService>(), container.Resolve <ICommissionService>(), container.Resolve <IAgentService>()); return(bookPaymentFacade.HandleBookPayment(payment)); case PaymentType.Membership: MembershipPaymentFacade membershipPaymentFacade = new MembershipPaymentFacade(container.Resolve <IMembershipService>(), container.Resolve <INotificationMembershipService>()); return(membershipPaymentFacade.HandleMembershipPayment(payment)); case PaymentType.UpgradeMembership: UpgradeMembershipPaymentFacade upgradeMembershipPaymentFacade = new UpgradeMembershipPaymentFacade(container.Resolve <IMembershipService>(), container.Resolve <INotificationMembershipService>()); return(upgradeMembershipPaymentFacade.HandleUpgradeMembershipPayment(payment)); case PaymentType.Video: VideoPaymentFacade videoPaymentFacade = new VideoPaymentFacade(container.Resolve <IPackagingSlipService>()); return(videoPaymentFacade.HandleVideoPayment(payment)); default: Logger.Instance.Log(LoggerType.Error, Resources.PaymentTypeNotSupported); return(new PaymentResponse { ErrorMessage = Resources.PaymentTypeNotSupported, PaymentResponseType = PaymentResponseType.Failure }); } } catch (Exception ex) { Logger.Instance.Log(LoggerType.Error, ex.Message); Logger.Instance.Log(LoggerType.Error, ex.StackTrace); return(new PaymentResponse { ErrorMessage = Resources.PaymentExceptionOccurred, PaymentResponseType = PaymentResponseType.Failure }); } }