Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.36 KB | None | 0 0
  1. [TestMethod()]
  2. public void TestMultiInit()
  3. {
  4. var Client2 = new cpEasyPost("123");
  5. var Client = new cpEasyPost("123456qq785412");
  6.  
  7. var Shipment = Client.CreateShipment(
  8. new EasyPost.Address
  9. {
  10. street1 = "417 MONTGOMERY ST",
  11. street2 = "FLOOR 5",
  12. city = "SAN FRANCISCO",
  13. state = "CA",
  14. zip = "94104",
  15. country = "US",
  16. company = "EasyPost"
  17. },
  18. new EasyPost.Address
  19. {
  20. street1 = "417 MONTGOMERY ST",
  21. street2 = "FLOOR 5",
  22. city = "SAN FRANCISCO",
  23. state = "CA",
  24. zip = "94104",
  25. country = "US",
  26. company = "EasyPost"
  27. },
  28. new EasyPost.Parcel
  29. {
  30. length = 20.2,
  31. width = 10.9,
  32. height = 5,
  33. weight = 65.9
  34. });
  35.  
  36. var Shipment2 = Client2.CreateShipment(
  37. new EasyPost.Address
  38. {
  39. street1 = "417 MONTGOMERY ST",
  40. street2 = "FLOOR 5",
  41. city = "SAN FRANCISCO",
  42. state = "CA",
  43. zip = "94104",
  44. country = "US",
  45. company = "EasyPost"
  46. },
  47. new EasyPost.Address
  48. {
  49. street1 = "417 MONTGOMERY ST",
  50. street2 = "FLOOR 5",
  51. city = "SAN FRANCISCO",
  52. state = "CA",
  53. zip = "94104",
  54. country = "US",
  55. company = "EasyPost"
  56. },
  57. new EasyPost.Parcel
  58. {
  59. length = 20.2,
  60. width = 10.9,
  61. height = 5,
  62. weight = 65.9
  63. });
  64.  
  65.  
  66. }
  67.  
  68. public cpEasyPost(string secretKey)
  69. {
  70. SecretKey = secretKey;
  71. //Original way of init Client
  72. //ClientManager.SetCurrent(SecretKey);
  73.  
  74. //Create ClientManager
  75. ClientManager.SetCurrent(() => new Client(new ClientConfiguration(SecretKey)));
  76. }
  77.  
  78. public Shipment CreateShipment(Address AddressFrom, Address AddressTo, Parcel Parcel, CustomsInfo customs = null, string CustomReference = "", double? InsauranceAmount = null)
  79. {
  80. //Validate Adress
  81. var isValidFrom = ValidateAddress(AddressFrom);
  82. var isValidTo = ValidateAddress(AddressFrom);
  83.  
  84. if (!isValidFrom.isSuccess)
  85. throw new Exception("Address From is not Valid");
  86.  
  87. if (!isValidTo.isSuccess)
  88. throw new Exception("Address To is not Valid");
  89.  
  90. //Validate Pacrcel
  91. var isValidParcel = ValidateParcel(Parcel);
  92.  
  93. if (!isValidFrom.isSuccess)
  94. throw new Exception("Parcel is not Valid");
  95.  
  96. //Create Shipment
  97. Shipment shipment = new Shipment()
  98. {
  99. reference = CustomReference,
  100. to_address = AddressTo,
  101. from_address = AddressFrom,
  102. parcel = Parcel,
  103. customs_info = customs
  104. };
  105.  
  106. //ClientManager.SetCurrent(SecretKey); **
  107. shipment.Create();
  108.  
  109. //Add Insurance
  110. if (InsauranceAmount != null)
  111. shipment.Insure(InsauranceAmount.Value);
  112.  
  113. return shipment;
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement