Ejemplo n.º 1
0
        public async Task WHEN_calling_RemovePaymentAsync_SHOULD_invoke_Overture_Client()
        {
            //Arrange
            var param = new VoidOrRemovePaymentParam
            {
                CartName    = GetRandom.String(7),
                CustomerId  = GetRandom.Guid(),
                CultureInfo = CultureInfo.InvariantCulture,
                Scope       = GetRandom.String(12),
                PaymentId   = GetRandom.Guid()
            };
            var sut = _container.CreateInstance <PaymentRepository>();

            //Act
            await sut.RemovePaymentAsync(param);

            //Assert
            _container.Verify <IOvertureClient>(oc => oc.SendAsync(It.IsNotNull <RemovePaymentRequest>()));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Voids a payment and generates a new one.
        /// </summary>
        /// <param name="param">Parameters used to void the payment.</param>
        /// <returns>The updated cart.</returns>
        public virtual Task <Overture.ServiceModel.Orders.Cart> VoidPaymentAsync(VoidOrRemovePaymentParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.CartName))
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CartName"), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("Scope"), nameof(param));
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CultureInfo"), nameof(param));
            }
            if (param.CustomerId == default(Guid))
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("CustomerId"), nameof(param));
            }
            if (param.PaymentId == default(Guid))
            {
                throw new ArgumentException(ArgumentNullMessageFormatter.FormatErrorMessage("PaymentId"), nameof(param));
            }

            var cacheKey = BuildCartCacheKey(param.Scope, param.CartName, param.CustomerId);

            var request = new VoidPaymentRequest
            {
                CartName    = param.CartName,
                CultureName = param.CultureInfo.Name,
                CustomerId  = param.CustomerId,
                PaymentId   = param.PaymentId,
                ScopeId     = param.Scope
            };

            return(CacheProvider.ExecuteAndSetAsync(cacheKey, () => OvertureClient.SendAsync(request)));
        }
        /// <summary>
        /// Removes a payment from a cart.
        /// </summary>
        /// <param name="param">Parameters used to remove the payment.</param>
        /// <returns>The updated cart.</returns>
        public virtual Task <ProcessedCart> RemovePaymentAsync(VoidOrRemovePaymentParam 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.CultureInfo == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param));
            }
            if (param.CustomerId == Guid.Empty)
            {
                throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param));
            }
            if (param.PaymentId == Guid.Empty)
            {
                throw new ArgumentException(GetMessageOfEmpty(nameof(param.PaymentId)), nameof(param));
            }

            var cacheKey = BuildCartCacheKey(param.Scope, param.CartName, param.CustomerId);

            var request = new RemovePaymentRequest
            {
                CartName    = param.CartName,
                CultureName = param.CultureInfo.Name,
                CustomerId  = param.CustomerId,
                Id          = param.PaymentId,
                ScopeId     = param.Scope
            };

            return(CacheProvider.ExecuteAndSetAsync(cacheKey, () => OvertureClient.SendAsync(request)));
        }
Ejemplo n.º 4
0
        public void WHEN_scope_is_null_or_whitespace_SHOULD_throw_ArgumentException(string scope)
        {
            //Arrange
            var param = new VoidOrRemovePaymentParam
            {
                CartName    = GetRandom.String(7),
                CustomerId  = GetRandom.Guid(),
                CultureInfo = CultureInfo.InvariantCulture,
                Scope       = scope,
                PaymentId   = GetRandom.Guid()
            };

            var sut = _container.CreateInstance <PaymentRepository>();

            //Act
            var exception = Assert.ThrowsAsync <ArgumentException>(() => sut.RemovePaymentAsync(param));

            //Assert
            exception.Should().NotBeNull();
            exception.ParamName.Should().Be("param");
            exception.Message.Should().ContainEquivalentOf("scope");
        }
Ejemplo n.º 5
0
        public void WHEN_scope_is_null_or_whitespace_SHOULD_throw_ArgumentException(string scope)
        {
            //Arrange
            var param = new VoidOrRemovePaymentParam
            {
                CartName    = GetRandom.String(7),
                CustomerId  = GetRandom.Guid(),
                CultureInfo = CultureInfo.InvariantCulture,
                Scope       = scope,
                PaymentId   = GetRandom.Guid()
            };

            var sut = _container.CreateInstance <PaymentRepository>();

            //Act
            Expression <Func <Task <Overture.ServiceModel.Orders.Cart> > > expression = () => sut.VoidPaymentAsync(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.Scope)));
        }