Пример #1
0
        public void Test_SubmitRequest_OrderHeader_serialization()
        {
            // Prepare
            SubmitRequestHeader header = new SubmitRequestHeader
            {
                // Order details mandatory
                DistributorId        = "7918180560",
                CustomerName         = "Ivan Ivanov",
                ExternalOrderNumber  = "C5K1234567",
                TotalDue             = 123.45m,
                OrderMonth           = new DateTime(2020, 11, 1),
                SalesChannelCode     = "AutoStore",
                OrderDate            = new DateTime(2020, 11, 27, 14, 43, 40),
                PricingDate          = new DateTime(2020, 11, 27, 14, 40, 10),
                TotalVolume          = 15,
                OrderTypeCode        = "RSO",
                TotalAmountPaid      = 123.45m,
                OrderPaymentStatus   = "PAID",// "UNDERPAID" "OVERPAID"
                OrderDiscountPercent = 35m,
                // Location payload mandatory
                CountryCode        = "RU",
                WareHouseCode      = "Foo",
                ProcessingLocation = "Bar",
                ShippingMethodCode = "Baz",
                City        = "Moscow",
                InvShipFlag = "Y",
                OrgId       = 1589,
                PostalCode  = "125167",
                Province    = "qux",
                Address1    = "quux",
                Address2    = "quuz",
                State       = "corge",
                // Non-mandatory
                ShippingInstructions = "10/00-16/00",
                PickupName           = "pckp",
                TaxAmount            = 1.58m,
                DiscountAmount       = 35m,
                OrderConfirmEmail    = "*****@*****.**",
                OrderPurpose         = "OP",
                OrderSource          = "KIOSK",
                TotalRetailPrice     = 123.45m,    // спорный момент, скорее не нужен	   = isAALatviaStub ? 0 : 99,    bool isAALatviaStub = string.Equals(salesChannelCode, "AUTOATTENDANT", StringComparison.InvariantCultureIgnoreCase);
                ChrAttribute4        = "Chr4",     //(isPudo ? postamatCode : null)  bool isPudo = freightCode.Equals("BLD") || freightCode.Equals("BLO");
                ChrAttribute3        = "Chr3",     // isPudo ?"Y":"N"
                ChrAttribute6        = "Chr6",     // QR хардкод (для Балтики как минимум)
                ChrAttribute5        = "Chr5",     //(isPudo ? phone : null)
                Phone        = "79262140000",      // null по ум
                Notes        = "hello world!",     //string     не mandatory (null по-умолчанию)
                SMSNumber    = "79262140000",      // null string
                SMSAction    = "ORDER COMPLETION", //"ORDER COMPLETION" по-умолчанию
                SMSRole      = "DS",               //      "DS" по-умолчанию
                OrderSubType = "ost"               // "" по-умолчанию
            };

            // Perform
            string result = JsonConvert.SerializeObject(header);

            // Post-validate
            Assert.Equal("{\"DistributorId\":\"7918180560\",\"CustomerName\":\"Ivan Ivanov\",\"ExternalOrderNumber\":\"C5K1234567\",\"TotalDue\":\"123.45\",\"OrderMonth\":\"2011\",\"SalesChannelCode\":\"AutoStore\",\"OrderDate\":\"2020-11-27T14:43:40\",\"PricingDate\":\"2020-11-27T14:40:10\",\"TotalVolume\":\"15\",\"OrderTypeCode\":\"RSO\",\"TotalAmountPaid\":\"123.45\",\"OrderPaymentStatus\":\"PAID\",\"OrderDiscount\":\"35\",\"CountryCode\":\"RU\",\"WareHouseCode\":\"Foo\",\"ProcessingLocation\":\"Bar\",\"ShippingMethodCode\":\"Baz\",\"City\":\"Moscow\",\"InvShipFlag\":\"Y\",\"OrgId\":\"1589\",\"PostalCode\":\"125167\",\"Province\":\"qux\",\"Address1\":\"quux\",\"Address2\":\"quuz\",\"State\":\"corge\",\"ShippingInstructions\":\"10/00-16/00\",\"PickupName\":\"pckp\",\"TaxAmount\":\"1.58\",\"DiscountAmount\":\"35\",\"OrderConfirmEmail\":\"[email protected]\",\"WillCallFlag\":\"N\",\"OrderPurpose\":\"OP\",\"SlidingDiscount\":\"0\",\"OrderSource\":\"KIOSK\",\"Balance\":\"0\",\"TotalRetailPrice\":\"123.45\",\"ChrAttribute4\":\"Chr4\",\"ChrAttribute3\":\"Chr3\",\"ChrAttribute6\":\"Chr6\",\"ChrAttribute5\":\"Chr5\",\"Phone\":\"79262140000\",\"Notes\":\"hello world!\",\"SMSNumber\":\"79262140000\",\"SMSAction\":\"ORDER COMPLETION\",\"SMSRole\":\"DS\",\"OrderSubType\":\"ost\"}", result);
        }
Пример #2
0
        public SubmitRequestBuilder AddHeader(Action <SubmitRequestHeader> setupHeader)
        {
            SubmitRequestHeader header = setupHeader?.CreateTargetAndInvoke();

            #region Validation
            StringBuilder issues = new StringBuilder();

            if (string.IsNullOrWhiteSpace(header.DistributorId))
            {
                issues.AppendLine($"Distributor id is mandatory");
            }

            if (string.IsNullOrWhiteSpace(header.CustomerName))
            {
                issues.AppendLine($"Customer name is mandatory");
            }

            if (string.IsNullOrWhiteSpace(header.ExternalOrderNumber))
            {
                issues.AppendLine($"Order number is mandatory");
            }

            if (header.TotalDue <= 0m)
            {
                issues.AppendLine($"Total due must be positive");
            }

            if (header.OrderMonth == DateTime.MinValue)
            {
                issues.AppendLine($"Invalid order month");
            }

            if (string.IsNullOrWhiteSpace(header.SalesChannelCode))
            {
                issues.AppendLine($"Sales channel code is mandatory");
            }

            if (header.OrderDate == DateTime.MinValue)
            {
                issues.AppendLine($"Invalid order date");
            }

            if (header.PricingDate == DateTime.MinValue)
            {
                issues.AppendLine($"Invalid pricing date");
            }

            if (header.TotalVolume < 0)
            {
                issues.AppendLine($"Total volume must be non-negative");
            }

            if (string.IsNullOrWhiteSpace(header.OrderTypeCode))
            {
                issues.AppendLine($"Order type code is mandatory");
            }

            if (header.TotalAmountPaid < 0m)
            {
                issues.AppendLine($"Total amount paid must be non-negative");
            }

            if (string.IsNullOrWhiteSpace(header.OrderPaymentStatus))
            {
                issues.AppendLine($"Order payment status is mandatory");
            }

            if (header.OrderDiscountPercent < 0m)
            {
                issues.AppendLine($"Order discount must be non-negative");
            }

            if (string.IsNullOrWhiteSpace(header.CountryCode))
            {
                issues.AppendLine($"Country code is mandatory");
            }

            if (string.IsNullOrWhiteSpace(header.WareHouseCode))
            {
                issues.AppendLine($"WareHouse code is mandatory");
            }

            if (string.IsNullOrWhiteSpace(header.ProcessingLocation))
            {
                issues.AppendLine($"Processing location is mandatory");
            }

            if (string.IsNullOrWhiteSpace(header.ShippingMethodCode))
            {
                issues.AppendLine($"Shipping method code is mandatory");
            }

            if (string.IsNullOrWhiteSpace(header.City))
            {
                issues.AppendLine($"City is mandatory");
            }

            //if (header.FreightCharges < 0m)
            //    issues.AppendLine($"Freight charge must be non-negative");

            if (string.IsNullOrWhiteSpace(header.InvShipFlag))
            {
                issues.AppendLine($"InvShipFlag is mandatory");
            }

            if (header.OrgId <= 0)
            {
                issues.AppendLine($"OrgId must be positive");
            }

            if (string.IsNullOrWhiteSpace(header.PostalCode))
            {
                issues.AppendLine($"Postal code is mandatory");
            }

            if (string.IsNullOrWhiteSpace(header.Address1))
            {
                issues.AppendLine($" is mandatory");
            }

            if (issues.Length > 0)
            {
                throw new ArgumentException(issues.ToString());
            }
            #endregion

            _request.Header = header;

            return(this);
        }