public void WHEN_param_is_null_SHOULD_throw_NullArgumentException()
        {
            RemoveCouponsParam p = null;
            var sut = Container.CreateInstance <CartRepository>();

            var ex = Assert.ThrowsAsync <ArgumentNullException>(() => sut.RemoveCouponsAsync(p));

            ex.ParamName.Should().BeEquivalentTo("param");
        }
        public void WHEN_cartName_is_invalid_SHOULD_throw_ArgumentException(string cartName)
        {
            //Arrange
            var p = new RemoveCouponsParam()
            {
                CartName    = cartName,
                CouponCodes = new List <string>(),
                CustomerId  = GetRandom.Guid(),
                Scope       = GetRandom.String(7)
            };

            var sut = Container.CreateInstance <CartRepository>();

            //Act
            var ex = Assert.ThrowsAsync <ArgumentException>(() => sut.RemoveCouponsAsync(p));

            //Assert
            ex.ParamName.Should().BeEquivalentTo("param");
        }
        public void WHEN_couponCodes_is_null_SHOULD_throw_ArgumentException()
        {
            //Arrange
            var p = new RemoveCouponsParam()
            {
                CartName    = GetRandom.String(7),
                CouponCodes = null,
                CustomerId  = GetRandom.Guid(),
                Scope       = GetRandom.String(7)
            };

            var sut = Container.CreateInstance <CartRepository>();

            //Act
            Expression <Func <Task> > expression = () => sut.RemoveCouponsAsync(p);
            var exception = Assert.ThrowsAsync <ArgumentException>(() => expression.Compile().Invoke());

            exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name);
            exception.Message.Should().StartWith(GetMessageOfNull(nameof(p.CouponCodes)));
        }
Example #4
0
        /// <summary>
        /// Removes the specified coupons for a specific cart instance.
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public virtual async Task RemoveCouponsAsync(RemoveCouponsParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException("param");
            }
            if (string.IsNullOrWhiteSpace(param.CartName))
            {
                throw new ArgumentException("Cart name cannot be null or whitespace", "param");
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException("Scope cannot be null or whitespace", "param");
            }
            if (param.CustomerId == Guid.Empty)
            {
                throw new ArgumentException("CustomerId cannot be Empty GUID", "param");
            }
            if (param.CouponCodes == null)
            {
                throw new ArgumentNullException("param");
            }


            foreach (var couponCode in param.CouponCodes)
            {
                var request = new RemoveCouponRequest
                {
                    CouponCode = couponCode,
                    CartName   = param.CartName,
                    CustomerId = param.CustomerId,
                    ScopeId    = param.Scope
                };

                // Do not remove coupons in parallel, because otherwise it could corrupt your cart.
                await OvertureClient.SendAsync(request).ConfigureAwait(false);
            }
        }
Example #5
0
        /// <summary>
        /// Removes the specified coupons for a specific cart instance.
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public virtual async Task RemoveCouponsAsync(RemoveCouponsParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.CartName))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.CartName)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param));
            }
            if (param.CustomerId == Guid.Empty)
            {
                throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param));
            }
            if (param.CouponCodes == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CouponCodes)), nameof(param));
            }

            foreach (var couponCode in param.CouponCodes)
            {
                var request = new RemoveCouponRequest
                {
                    CouponCode = couponCode,
                    CartName   = param.CartName,
                    CartType   = param.CartType,
                    CustomerId = param.CustomerId,
                    ScopeId    = param.Scope
                };

                // Do not remove coupons in parallel, because otherwise it could corrupt your cart.
                await OvertureClient.SendAsync(request).ConfigureAwait(false);
            }
        }
        public void WHEN_request_is_valid_SHOULD_invoke_overture_client()
        {
            //Arrange
            var p = new RemoveCouponsParam()
            {
                CartName    = GetRandom.String(7),
                CouponCodes = new List <string>()
                {
                    GetRandom.UpperCaseString(8),
                    GetRandom.UpperCaseString(5)
                },
                CustomerId = GetRandom.Guid(),
                Scope      = GetRandom.String(7)
            };

            var sut = Container.CreateInstance <CartRepository>();

            //Act
            Assert.DoesNotThrowAsync(() => sut.RemoveCouponsAsync(p));

            //Assert
            Container.Verify <IOvertureClient>();
        }
 public Task RemoveCouponsAsync(RemoveCouponsParam param)
 {
     throw new NotImplementedException();
 }