public async Task GetShippingMethodsForCartInStore()
        {
            await WithStore(client, async store =>
            {
                await WithCartWithSingleLineItem(client, 2,
                                                 draft => DefaultCartDraftInStore(draft, store.ToKeyResourceIdentifier()),
                                                 async cart =>
                {
                    Assert.NotNull(cart.Store);
                    Assert.Equal(store.Key, cart.Store.Key);
                    Assert.NotNull(cart.ShippingInfo.ShippingMethod);

                    var shippingMethod =
                        await client.ExecuteAsync(cart.ShippingInfo.ShippingMethod.GetById());

                    var expansions = new List <Expansion <ShippingMethod> >
                    {
                        new ReferenceExpansion <ShippingMethod>(sm => sm.ZoneRates.ExpandAll().Zone)
                    };

                    var command     = new GetShippingMethodsForCartCommand(cart.Id, expansions).InStore(store);
                    var returnedSet = await client.ExecuteAsync(command);
                    Assert.Single(returnedSet.Results);
                    var returnedShippingMethod = returnedSet.Results[0];
                    Assert.Equal(shippingMethod.Key, returnedShippingMethod.Key);

                    Assert.Single(returnedShippingMethod.ZoneRates);
                    var returnedZoneRate = returnedShippingMethod.ZoneRates[0];

                    Assert.True(
                        returnedZoneRate.ShippingRates.Count(shippingRate => shippingRate.IsMatching) == 1);
                });
            });
        }
Ejemplo n.º 2
0
        public void GetShippingMethodsForCart()
        {
            var command = new GetShippingMethodsForCartCommand("2bafc816-4223-4ff0-ac8a-0f08a8f29fd6");

            IHttpApiCommandFactory httpApiCommandFactory = this.clientFixture.GetService <IHttpApiCommandFactory>();
            IHttpApiCommand        httpApiCommand        = httpApiCommandFactory.Create(command);

            HttpRequestMessage httpRequestMessage = httpApiCommand.HttpRequestMessage;

            Assert.Equal(HttpMethod.Get, httpRequestMessage.Method);
            Assert.Equal("shipping-methods/matching-cart?cartId=2bafc816-4223-4ff0-ac8a-0f08a8f29fd6", httpRequestMessage.RequestUri.ToString());
        }
        public async Task GetShippingMethodsForCart()
        {
            var shippingAddress = TestingUtility.GetRandomAddress();

            await WithShippingMethodWithZoneRateAndTaxCategory(client,
                                                               DefaultShippingMethodDraft, shippingAddress,
                                                               async shippingMethod =>
            {
                await WithCart(client,
                               draft =>
                {
                    var cartDraft = DefaultCartDraftWithShippingAddress(draft, shippingAddress);
                    cartDraft     = DefaultCartDraftWithShippingMethod(cartDraft, shippingMethod);
                    return(cartDraft);
                },
                               async cart =>
                {
                    Assert.NotNull(cart.ShippingInfo.ShippingMethod);
                    Assert.Equal(shippingMethod.Id, cart.ShippingInfo.ShippingMethod.Id);

                    var expansions = new List <Expansion <ShippingMethod> >
                    {
                        new ReferenceExpansion <ShippingMethod>(sm => sm.ZoneRates.ExpandAll().Zone)
                    };

                    var command     = new GetShippingMethodsForCartCommand(cart.Id, expansions);
                    var returnedSet = await client.ExecuteAsync(command);
                    Assert.Single(returnedSet.Results);
                    var returnedShippingMethod = returnedSet.Results[0];
                    Assert.Equal(shippingMethod.Key, returnedShippingMethod.Key);

                    Assert.Single(returnedShippingMethod.ZoneRates);
                    var returnedZoneRate = returnedShippingMethod.ZoneRates[0];

                    Assert.True(returnedZoneRate.ShippingRates.Count(shippingRate => shippingRate.IsMatching) == 1);
                });
            });
        }