public void TestFailingCreditCardPayment() { //Arrange IPaymentsDao paymentsDao = new PaymentsDao(); ICreditCardProcessor creditCardProcessor = new CreditCardProcessor(); IEftProcessor eftProcessor = new EftProcessor(); PaymentProcessor.PaymentProcessor paymentProcessor = new PaymentProcessor.PaymentProcessor(creditCardProcessor, eftProcessor, paymentsDao); CreditCardPaymentData creditCardPayment = new CreditCardPaymentData() { CreditCardNumber = SampleData.CARD_NUMBER_ONE, ExpirationDate = "10/2019", Cvv = "755", CustomerAccountNumber = "00012345", PaymentDate = DateTime.Today, BillingZipCode = "60067", CardholderName = "John Doe", PaymentType = PaymentType.CREDIT_CARD, Amount = 10000.00m }; // Act PaymentResult result = paymentProcessor.ProcessPayment(creditCardPayment); // Assert Assert.False(result.Success); Assert.Equal(15, result.ReferenceNumber); }
public void TestSuccessfulEftPayment() { //Arrange IPaymentsDao paymentsDao = new PaymentsDao(); ICreditCardProcessor creditCardProcessor = new CreditCardProcessor(); IEftProcessor eftProcessor = new EftProcessor(); PaymentProcessor.PaymentProcessor paymentProcessor = new PaymentProcessor.PaymentProcessor(creditCardProcessor, eftProcessor, paymentsDao); EftPaymentData eftPaymentData = new EftPaymentData() { CustomerAccountNumber = "00012345", PaymentDate = DateTime.Today, PaymentType = PaymentType.EFT, Amount = 100.00m, RoutingNumber = SampleData.BANK_ROUTING_ONE, BankAccountNumber = SampleData.BANK_ACCOUNT_ONE, AccountType = BankAccountType.CHECKING }; // Act PaymentResult result = paymentProcessor.ProcessPayment(eftPaymentData); // Assert Assert.True(result.Success); Assert.Equal(20, result.ReferenceNumber); }
/// <summary> /// This example uses the Bridge Pattern to separate high-level abstractions from implementation details. /// We have a Farmers Market, where different types of vendors process payments using different /// types of Payment Processing services, including credit cards and gift cards. /// The "Bridge" is the has-a relationship between vendors and their payment processors. /// Any FarmersMarketVendor has an object that implements the IProcessesPayments interface. /// Because every concrete FarmersMarketVendor is programmed to work with the high-level IProcessesPayments interface, /// the vendor logic can be extended independently of the implementations of the Payment Processors. Likewise, /// the implementors of IProcessesPayments know nothing about the context in which they are used, and can be treated like a plugin. /// in fact, they can be used in many other contexts, so they've been extracted to the RealisticDependencies class library. /// By using object composition in this way, we avoid creating an exponential explosion in a potential /// subclass hierarchy for specific vendor-processor combinations. /// </summary> /// <param name="args"></param> /// <returns></returns> private static void Main(string[] args) { Console.WriteLine("🧑🌾 Welcome to the Farmer's Market!"); Console.OutputEncoding = System.Text.Encoding.UTF8; const string organicGardens = "Organic Gardens"; const string olsenFarm = "Olsen Farm"; const string andersenFarm = "Andersen Farm"; const string pleasantValley = "Pleasant Valley"; const string hillsideRanch = "Hillside Ranch"; var creditCardProcessor = new CreditCardProcessor(); var giftCardProcessor = new GiftCardProcessor(); var booth1 = new VegetableFarmer(creditCardProcessor); var booth2 = new VegetableFarmer(giftCardProcessor); var booth3 = new CattleFarmer(creditCardProcessor); var booth4 = new Florist(creditCardProcessor); var booth5 = new Florist(giftCardProcessor); booth1.ProcessCustomerPayment(10.00m, organicGardens); booth1.ProcessCustomerPayment(12.00m, organicGardens); booth1.ProcessCustomerPayment(1.50m, organicGardens); booth2.ProcessCustomerPayment(15.50m, olsenFarm); booth3.ProcessCustomerPayment(5.00m, andersenFarm); booth3.ProcessCustomerPayment(5.00m, andersenFarm); booth3.ProcessCustomerPayment(5.00m, andersenFarm); booth4.ProcessCustomerPayment(12.00m, pleasantValley); booth4.ProcessCustomerPayment(11.00m, pleasantValley); booth5.ProcessCustomerPayment(12.00m, hillsideRanch); }
private void Start() { payScreenCanvas = gameObject.GetComponent <Canvas>(); cashButton = new List <GameObject>(GameObject.FindGameObjectsWithTag("CashButton")).Find(g => g.transform.IsChildOf(this.transform)); creditButton = new List <GameObject>(GameObject.FindGameObjectsWithTag("CreditButton")).Find(g => g.transform.IsChildOf(this.transform)); okButton = new List <GameObject>(GameObject.FindGameObjectsWithTag("OKButton")).Find(g => g.transform.IsChildOf(this.transform)); cardSwipe = new List <GameObject>(GameObject.FindGameObjectsWithTag("CardSwipe")).Find(g => g.transform.IsChildOf(this.transform)); cardInsert = new List <GameObject>(GameObject.FindGameObjectsWithTag("CardInsert")).Find(g => g.transform.IsChildOf(this.transform)); itemizedTextObject = new List <GameObject>(GameObject.FindGameObjectsWithTag("PayScreenItemizedText")).Find(g => g.transform.IsChildOf(this.transform)); outputTotalTextObject = new List <GameObject>(GameObject.FindGameObjectsWithTag("PayScreenOutputText")).Find(g => g.transform.IsChildOf(this.transform)); mainTextObject = new List <GameObject>(GameObject.FindGameObjectsWithTag("SelfCheckMainText")).Find(g => g.transform.IsChildOf(this.transform)); changeTextObject = new List <GameObject>(GameObject.FindGameObjectsWithTag("ChangeText")).Find(g => g.transform.IsChildOf(this.transform)); itemizedText = itemizedTextObject.GetComponent <TMPro.TextMeshProUGUI>(); outputTotalText = outputTotalTextObject.GetComponent <TMPro.TextMeshProUGUI>(); mainText = mainTextObject.GetComponent <TMPro.TextMeshProUGUI>(); changeText = changeTextObject.GetComponent <TMPro.TextMeshProUGUI>(); insertProcessScript = cardInsert.GetComponent <CreditCardProcessor>(); audioSource2 = gameObject.GetComponent <AudioSource>(); audioSource1 = insertProcessScript.audioSource1; creditButton.SetActive(false); cashButton.SetActive(false); cardSwipe.SetActive(false); cardInsert.SetActive(false); }
private PaymentProcessor CreatePaymentProcessor() { var bluePay = new BluePayProcessor(BluePayClient, new WebEnvironment(), new RandomGenerator(), IntegrationConfig.GetBluePaySandBoxConfig()); var creditCard = new CreditCardProcessor(bluePay); var invoiceSender = new InvoiceSender(MockEmail); return(new PaymentProcessor(MockEmail, CurrencyConverter, OntraProcessor, invoiceSender, creditCard, null, new RandomGenerator())); }
public void CreditCardProcessor_HandlePayment_Returns_Amount_in_Some_String(decimal amount) { var gcProcessor = new CreditCardProcessor(); var response = gcProcessor.HandlePayment(amount); response.Should().Contain(amount.ToString()); response.ToLower().Should().Contain("credit card"); }
public void String_Converted_To_Int_Throws_Exception() { // Arrange string withDollarSign = "!!@!@"; // Act Exception ex = Assert.Throws <System.IO.IOException>(() => CreditCardProcessor.CurrencyStringConvertToInt(withDollarSign)); // Assert Assert.Equal("The handle is invalid", ex.Message); }
public PaymentProcessor CreatePaymentProcessor() { IPaymentsDao paymentsDao = new PaymentsDao(); ICreditCardProcessor creditCardProcessor = new CreditCardProcessor(); IEftProcessor eftProcessor = new EftProcessor(); CheckPaymentTypeHandler checkHandler = new CheckPaymentTypeHandler(null, paymentsDao); EftPaymentTypeHandler eftPaymentHandler = new EftPaymentTypeHandler(checkHandler, eftProcessor, paymentsDao); CreditCardPaymentTypeHandler creditCardHandler = new CreditCardPaymentTypeHandler(eftPaymentHandler, creditCardProcessor, paymentsDao); PaymentProcessor paymentProcessor = new PaymentProcessor(creditCardHandler); return(paymentProcessor); }
public void String_Successfully_Converted_To_Int() { // Arrange string withDollarSign = "$1000"; string withComma = "1,000"; string withDollarSignAndComma = "$1,000"; // Act int dollarSignConversion = CreditCardProcessor.CurrencyStringConvertToInt(withDollarSign); int commaConversion = CreditCardProcessor.CurrencyStringConvertToInt(withComma); int dollarSignAndCommaConversion = CreditCardProcessor.CurrencyStringConvertToInt(withDollarSignAndComma); // Assert Assert.Equal(1000, dollarSignConversion); Assert.Equal(1000, commaConversion); Assert.Equal(1000, dollarSignAndCommaConversion); }
public void Invalid_Parse_Strings() { // Arrange string testInput = "Add Bob 4111111111111111 $1000\r\nAdd Steve 5454545454545454 $3000\r\nAdd Rob 1234567890123456 $2000\r\nCharge Bob $500\r\nCharge Steve $800\r\nCharge Rob $7\r\nCredit Lisa $100\r\nCredit Bob $200"; List <string> incorrectUserNamesList = new List <string>(); SortedDictionary <string, string> incorrectUserBalances = new SortedDictionary <string, string>(); Dictionary <string, string> incorrectCreditCards = new Dictionary <string, string>(); Dictionary <string, int> incorrectCreditLimits = new Dictionary <string, int>(); // Act CreditCardProcessor.ParseString(testInput); // Assert Assert.NotEqual(incorrectUserNamesList, CreditCardProcessor.userNames); Assert.NotEqual(incorrectUserBalances, CreditCardProcessor.userBalances); Assert.NotEqual(incorrectCreditCards, CreditCardProcessor.creditCards); Assert.NotEqual(incorrectCreditLimits, CreditCardProcessor.creditLimits); }
public void Validate_Parse_Strings() { // Arrange string testInput = "Add Tom 4111111111111111 $1000\r\nAdd Lisa 5454545454545454 $3000\r\nAdd Quincy 1234567890123456 $2000\r\nCharge Tom $500\r\nCharge Tom $800\r\nCharge Lisa $7\r\nCredit Lisa $100\r\nCredit Quincy $200"; List <string> correctUserNamesList = new List <string>() { "Tom", "Lisa", "Quincy" }; SortedDictionary <string, string> correctUserBalances = new SortedDictionary <string, string>() { { "Lisa", "$-93" }, { "Quincy", "Error" }, { "Tom", "$500" } }; Dictionary <string, string> correctCreditCards = new Dictionary <string, string>() { { "Tom", "4111111111111111" }, { "Lisa", "5454545454545454" }, { "Quincy", "1234567890123456" } }; Dictionary <string, int> correctCreditLimits = new Dictionary <string, int>() { { "Tom", 1000 }, { "Lisa", 3000 }, { "Quincy", 2000 } }; // Act CreditCardProcessor.ParseString(testInput); // Assert Assert.Equal(correctUserNamesList, CreditCardProcessor.userNames); Assert.Equal(correctUserBalances, CreditCardProcessor.userBalances); Assert.Equal(correctCreditCards, CreditCardProcessor.creditCards); Assert.Equal(correctCreditLimits, CreditCardProcessor.creditLimits); }