Exemplo n.º 1
0
        public string Extension_Format(string format)
        {
            Customer          customer = new Customer("Jeffrey Richter", "+1 (425) 555-0100", 1000000);
            CustomerFormatter cf       = new CustomerFormatter();

            return(cf.Format(format, customer, CultureInfo.CurrentCulture));
        }
        public string ParseRequestToMessage(AuthorizationRequest authorizationRequestData)
        {
            logger.Info("Formatando mensagem de requisição", new { Env = "DEV", ServerName = "ABCXYZ", LibLocation = "C:\\xxx\\RLabs.Cielo.SDK.dll", TransactionId = "12345", Date = "2018-05-06:09:03:00", Level = "INFO" });
            dynamic bodyMessage = new JObject();

            if (authorizationRequestData != null)
            {
                bodyMessage.MerchantOrderId = authorizationRequestData.MerchantOrderId;

                if (authorizationRequestData.Customer != null)
                {
                    bodyMessage.Customer = CustomerFormatter.BuildCustomer(authorizationRequestData.Customer);
                }

                if (authorizationRequestData.Payment != null)
                {
                    bodyMessage.Payment = PaymentFormatter.BuildPayment(authorizationRequestData.Payment);
                }

                if (authorizationRequestData.Wallet != null)
                {
                    bodyMessage.Wallet = PaymentFormatter.BuildWallet(authorizationRequestData.Wallet);
                }
            }

            return(bodyMessage.ToString());
        }
        public void CustomerFormatter_PositiveTest(string name, string phone, decimal revenue, string format, string result)
        {
            Customer        cust = new Customer(name, phone, revenue);
            IFormatProvider fp   = new CustomerFormatter();

            Assert.AreEqual(result, string.Format(fp, "{0:" + format + "}", cust));
        }
        public void CustomerFormatter_FormatException(string name, string phone, decimal revenue, string format, string result)
        {
            Customer        cust = new Customer(name, phone, revenue);
            IFormatProvider fp   = new CustomerFormatter();

            Assert.Throws <FormatException>(() => string.Format(fp, "{0:" + format + "}", cust));
        }
        public void Format_ObjectArgumentIsNotCustomer_ThrowsArgumentException(string format)
        {
            CustomerFormatter formatter = new CustomerFormatter();
            Object            person    = new Object();

            Assert.Throws <ArgumentException>(() => string.Format(formatter, format, person));
        }
        public void Format_NullReferencedCustomer_ThrowsArgumentNullException(string format)
        {
            CustomerFormatter formatter = new CustomerFormatter();
            Customer          person    = null;

            Assert.Throws <ArgumentNullException>(() => string.Format(formatter, format, person));
        }
        public void Format_InvalidFormatStrings_ThrowsFormatException(string format)
        {
            CustomerFormatter formatter = new CustomerFormatter();
            Customer          person    = new Customer("Jeffrey Richter", "+1(425) 555 - 0100", 1000000);

            Assert.Throws <FormatException>(() => string.Format(formatter, format, person));
        }
        public string Format_NormalFormatStrings_PositiveTests(string format)
        {
            CustomerFormatter formatter = new CustomerFormatter();
            Customer          person    = new Customer("Jeffrey Richter", "+1(425) 555 - 0100", 1000000);

            return(string.Format(formatter, format, person));
        }
Exemplo n.º 9
0
        public string ToString_Test(string str)
        {
            var customerFormatter = new CustomerFormatter();
            var customer          = new Customer {
                Name = "Gogol", Revenue = 100000000, Telephone = "+1(425) 55-0100"
            };

            var result = customer.ToString(str, customerFormatter);

            return(result);
        }
Exemplo n.º 10
0
        public string Format_Test(string str)
        {
            var customerFormatter = new CustomerFormatter();
            var customer          = new Customer {
                Name = "Gogol", Revenue = 100000000, Telephone = "+1(425) 55-0100"
            };
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(customerFormatter, str, customer);
            var result = customer.ToString(str, customerFormatter);

            return(sb.ToString());
        }
        public void Format_RNFormatString_RevenueNameSeparatedByComma()
        {
            var customer = new Customer
            {
                Name         = "Jeffrey Richter",
                ContactPhone = "+1 (425) 555-0100",
                Revenue      = 1000000m
            };
            var fomatter = new CustomerFormatter();

            var expected = "1,000,000.00, Jeffrey Richter";
            var actual   = string.Format(fomatter, "{0:RN}", customer);

            Assert.AreEqual(expected, actual);
        }
        public void Format_DFormatString_NameContactPhoneRevenueSeparatedByVerticalLine()
        {
            var customer = new Customer
            {
                Name         = "Jeffrey Richter",
                ContactPhone = "+1 (425) 555-0100",
                Revenue      = 1000000m
            };
            var fomatter = new CustomerFormatter();

            var expected = "Jeffrey Richter | +1 (425) 555-0100 | 1000000";
            var actual   = string.Format(fomatter, "{0:D}", customer);

            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 13
0
        public void Run()
        {
            DomainModel dm = new DomainModel();

            // Test of existing report generator
            IReportGenerator irg = new ReportGenerator();

            dm.GenerateReports(irg);

            // Test of new report generator
            ITextElementFormatterFactory teff      = new TextElementFormatterFactoryPadRight();
            IEnumerableCollectionFactory ecf       = new EnumerableCollectionFactorySimple();
            IItemFormatter <Customer>    ifc       = new CustomerFormatter(teff, ReportGeneratorSetup.ReportWidth);
            IItemFormatter <Product>     ifp       = new ProductFormatter(teff, ReportGeneratorSetup.ReportWidth);
            IItemFormatter <ShippingBox> ifsb      = new ShippingBoxFormatter(teff, ReportGeneratorSetup.ReportWidth);
            IReportGenerator             irgBetter = new BetterReportGenerator(ifc, ifp, ifsb, ecf);

            dm.GenerateReports(irgBetter);
        }
Exemplo n.º 14
0
        public async Task CreateSalesFile(int lines = 1024)
        {
            using (var streamWriter = new StreamWriter("./data/Sample01.txt"))
            {
                var vendorFormatter = new VendorFormatter();
                foreach (var vendor in vendors)
                {
                    await streamWriter.WriteAsync(vendorFormatter.Format(vendor));
                }

                var customerFormatter = new CustomerFormatter();
                foreach (var customer in customers)
                {
                    await streamWriter.WriteAsync(customerFormatter.Format(customer));
                }

                var saleFormatter = new SaleFormatter();
                for (int id = 1; id < lines; id++)
                {
                    await streamWriter.WriteAsync(saleFormatter.Format(CreateRandomSale(id)));
                }
            }

            using (var streamWriter = new StreamWriter("./data/Sample02.txt"))
            {
                var saleFormatter = new SaleFormatter();
                for (int id = lines; id < lines * 2; id++)
                {
                    await streamWriter.WriteAsync(saleFormatter.Format(CreateRandomSale(id)));
                }
            }

            using (var streamWriter = new StreamWriter("./data/Sample03.txt"))
            {
                var saleFormatter = new SaleFormatter();
                for (int id = lines * 2; id < lines * 3; id++)
                {
                    await streamWriter.WriteAsync(saleFormatter.Format(CreateRandomSale(id)));
                }
            }
        }