|
| 1 | +namespace ShippoTests.Integration; |
| 2 | + |
| 3 | +public class SetupFixture |
| 4 | +{ |
| 5 | + public SetupFixture() |
| 6 | + { |
| 7 | + Initialization = DeleteAllServiceGroups(); |
| 8 | + } |
| 9 | + |
| 10 | + public Task Initialization { get; private set; } |
| 11 | + |
| 12 | + async Task DeleteAllServiceGroups() |
| 13 | + { |
| 14 | + ShippoSDK sdk = new SDKFixture().SDK; |
| 15 | + List<ServiceGroup> serviceGroups = await sdk.ServiceGroups.ListAsync(); |
| 16 | + await Task.WhenAll( |
| 17 | + serviceGroups.Select( |
| 18 | + async serviceGroup => await |
| 19 | + sdk.ServiceGroups.DeleteAsync(serviceGroup.ObjectId) |
| 20 | + ).ToList() |
| 21 | + ); |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +[Collection("Integration")] |
| 26 | +public class RatesAtCheckout : IClassFixture<SetupFixture> |
| 27 | +{ |
| 28 | + SDKFixture sdkFixture; |
| 29 | + SetupFixture setupFixture; |
| 30 | + |
| 31 | + public RatesAtCheckout(SDKFixture sdkFixture, SetupFixture setupFixture) |
| 32 | + { |
| 33 | + this.sdkFixture = sdkFixture; |
| 34 | + this.setupFixture = setupFixture; |
| 35 | + } |
| 36 | + |
| 37 | + [Fact] |
| 38 | + public async void Test() |
| 39 | + { |
| 40 | + await setupFixture.Initialization; |
| 41 | + |
| 42 | + CarrierAccountWithExtraInfo carrierAccount = ( |
| 43 | + await Helpers.GetCarrierAccount(sdkFixture.SDK, CarriersEnum.Ups) |
| 44 | + )!; |
| 45 | + carrierAccount.Should().NotBeNull(); |
| 46 | + string accountId = carrierAccount.ObjectId!; |
| 47 | + accountId.Should().NotBeNullOrEmpty(); |
| 48 | + |
| 49 | + List<ServiceLevelUPSEnum> availableServiceLevels = new List<ServiceLevelUPSEnum> |
| 50 | + { |
| 51 | + ServiceLevelUPSEnum.UpsGround, ServiceLevelUPSEnum.UpsNextDayAirSaver |
| 52 | + }; |
| 53 | + |
| 54 | + List<ServiceGroupAccountAndServiceLevel> serviceLevels = |
| 55 | + availableServiceLevels.Select( |
| 56 | + availableServiceLevel => new ServiceGroupAccountAndServiceLevel() |
| 57 | + { |
| 58 | + AccountObjectId = accountId, |
| 59 | + ServiceLevelToken = availableServiceLevel.Value(), |
| 60 | + } |
| 61 | + ).ToList(); |
| 62 | + |
| 63 | + ServiceGroup serviceGroup = await sdkFixture.SDK.ServiceGroups.CreateAsync( |
| 64 | + new ServiceGroupCreateRequest() |
| 65 | + { |
| 66 | + Name = "UPS shipping", |
| 67 | + Description = "UPS shipping options", |
| 68 | + FlatRate = "5", |
| 69 | + FlatRateCurrency = "USD", |
| 70 | + Type = ServiceGroupTypeEnum.LiveRate, |
| 71 | + ServiceLevels = serviceLevels, |
| 72 | + } |
| 73 | + ); |
| 74 | + serviceGroup.Should().NotBeNull(); |
| 75 | + |
| 76 | + LiveRatePaginatedList liveRates = |
| 77 | + await sdkFixture.SDK.RatesAtCheckout.CreateAsync( |
| 78 | + new LiveRateCreateRequest() |
| 79 | + { |
| 80 | + AddressFrom = |
| 81 | + LiveRateCreateRequestAddressFrom.CreateAddressCompleteCreateRequest( |
| 82 | + new AddressCompleteCreateRequest() |
| 83 | + { |
| 84 | + Name = "Rachael", |
| 85 | + Street1 = "1092 Indian Summer Ct", |
| 86 | + City = "San Jose", |
| 87 | + State = "CA", |
| 88 | + Zip = "95122", |
| 89 | + Country = "US", |
| 90 | + Phone = "4159876543", |
| 91 | + |
| 92 | + } |
| 93 | + ), |
| 94 | + AddressTo = |
| 95 | + LiveRateCreateRequestAddressTo.CreateAddressCompleteCreateRequest( |
| 96 | + new AddressCompleteCreateRequest() |
| 97 | + { |
| 98 | + Name = "Mr Hippo", |
| 99 | + Street1 = "965 Mission St #572", |
| 100 | + City = "San Francisco", |
| 101 | + State = "CA", |
| 102 | + Zip = "94103", |
| 103 | + Country = "US", |
| 104 | + Phone = "4151234567", |
| 105 | + |
| 106 | + } |
| 107 | + ), |
| 108 | + LineItems = new List<LineItem>() |
| 109 | + { |
| 110 | + new LineItem() |
| 111 | + { |
| 112 | + Quantity = 1, |
| 113 | + TotalPrice = "12.00", |
| 114 | + Currency = "USD", |
| 115 | + Weight = "1.0", |
| 116 | + WeightUnit = WeightUnitEnum.Lb, |
| 117 | + Title = "Hippo Snax", |
| 118 | + ManufactureCountry = "US", |
| 119 | + Sku = "HM-123", |
| 120 | + } |
| 121 | + }, |
| 122 | + Parcel = LiveRateCreateRequestParcel.CreateParcel( |
| 123 | + new Parcel() |
| 124 | + { |
| 125 | + Length = "10", |
| 126 | + Width = "15", |
| 127 | + Height = "10", |
| 128 | + DistanceUnit = DistanceUnitEnum.In, |
| 129 | + Weight = "1", |
| 130 | + MassUnit = WeightUnitEnum.Lb, |
| 131 | + } |
| 132 | + ), |
| 133 | + } |
| 134 | + ); |
| 135 | + liveRates.Should().NotBeNull(); |
| 136 | + liveRates.Results.Should().NotBeNullOrEmpty(); |
| 137 | + foreach (LiveRate liveRate in liveRates.Results!) |
| 138 | + { |
| 139 | + liveRate.Title.Should().Be(serviceGroup.Name); |
| 140 | + } |
| 141 | + } |
| 142 | +} |
0 commit comments