Exemple #1
0
        public void WHEN_CultureInfo_Is_Null_SHOULD_Throw_ArgumentException()
        {
            var service = _container.CreateInstance <CartService>();
            var param   = new UpdateCartViewModelParam
            {
                CultureInfo     = null,
                CustomerId      = GetRandom.Guid(),
                CartName        = GetRandom.String(32),
                BaseUrl         = GetRandom.String(32),
                Shipments       = new List <Shipment>(),
                BillingCurrency = GetRandom.String(32),
                CartType        = GetRandom.String(32),
                Coupons         = new List <Coupon>(),
                Customer        = new CustomerSummary(),
                OrderLocation   = new OrderLocationSummary(),
                Scope           = GetRandom.String(32),
                Status          = GetRandom.String(32)
            };

            // Act
            var exception = Assert.ThrowsAsync <ArgumentException>(() => service.UpdateCartAsync(param));

            //Assert
            exception.ParamName.Should().BeSameAs("param");
            exception.Message.Should().Contain("CultureInfo");
        }
Exemple #2
0
        public void WHEN_Status_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string status)
        {
            var service = _container.CreateInstance <CartService>();
            var param   = new UpdateCartViewModelParam
            {
                CultureInfo     = TestingExtensions.GetRandomCulture(),
                CustomerId      = GetRandom.Guid(),
                CartName        = GetRandom.String(32),
                BaseUrl         = GetRandom.String(32),
                Shipments       = new List <Shipment>(),
                BillingCurrency = GetRandom.String(32),
                CartType        = GetRandom.String(32),
                Coupons         = new List <Coupon>(),
                Customer        = new CustomerSummary(),
                OrderLocation   = new OrderLocationSummary(),
                Scope           = GetRandom.String(32),
                Status          = status
            };

            // Act
            Expression <Func <Task <CartViewModel> > > expression = () => service.UpdateCartAsync(param);
            var exception = Assert.ThrowsAsync <ArgumentException>(() => expression.Compile().Invoke());

            //Assert
            exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name);
            exception.Message.Should().StartWith(GetMessageOfNullWhiteSpace(nameof(param.Status)));
        }
Exemple #3
0
        /// <summary>
        /// Update the Cart
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public virtual async Task <CartViewModel> UpdateCartAsync(UpdateCartViewModelParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (param.Coupons == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.Coupons)), nameof(param));
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param));
            }
            if (param.Shipments == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.Shipments)), nameof(param));
            }
            if (param.CustomerId == Guid.Empty)
            {
                throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.BaseUrl))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.BaseUrl)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.BillingCurrency))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.BillingCurrency)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.CartName))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartName)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.CartType))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartType)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Status))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Status)), nameof(param));
            }

            var updatedCart = await CartRepository.UpdateCartAsync(param).ConfigureAwait(false);

            await CartRepository.RemoveCouponsAsync(new RemoveCouponsParam
            {
                CartName    = param.CartName,
                CouponCodes = CouponViewService.GetInvalidCouponsCode(param.Coupons).ToList(),
                CustomerId  = param.CustomerId,
                Scope       = param.Scope
            }).ConfigureAwait(false);

            var vmParam = new CreateCartViewModelParam
            {
                Cart        = updatedCart,
                CultureInfo = param.CultureInfo,
                IncludeInvalidCouponsMessages = true,
                BaseUrl = param.BaseUrl
            };

            var viewModel = await CreateCartViewModelAsync(vmParam).ConfigureAwait(false);

            return(viewModel);
        }