/// <summary>
        /// Delete an Address for the given customer
        /// </summary>
        /// <param name="param">Service call params <see cref="DeleteAddressParam"/></param>
        /// <returns>
        /// The status representing a possible cause of errors.
        /// </returns>
        public virtual async Task <DeleteAddressStatusViewModel> DeleteAddressAsync(DeleteAddressParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (param.CustomerId == Guid.Empty)
            {
                throw new ArgumentException(GetMessageOfEmpty(nameof(param.CustomerId)), nameof(param));
            }
            if (param.AddressId == Guid.Empty)
            {
                throw new ArgumentException(GetMessageOfEmpty(nameof(param.AddressId)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param));
            }

            if (!await EnsureAddressBelongsToCustomer(param.CustomerId, param.Scope, param.AddressId).ConfigureAwait(false))
            {
                return(null);
            }

            await CustomerAddressRepository.DeleteAddressAsync(param.AddressId).ConfigureAwait(false);

            return(new DeleteAddressStatusViewModel());
        }
Exemplo n.º 2
0
        public void WHEN_AddressId_is_Null_SHOULD_throw_ArgumentException()
        {
            //Arrange
            var customerAddressViewService = _container.CreateInstance <CustomerAddressViewService>();
            var param = new DeleteAddressParam
            {
                Scope      = GetRandom.String(32),
                CustomerId = Guid.NewGuid(),
            };

            //Act
            var ex = Assert.ThrowsAsync <ArgumentException>(() => customerAddressViewService.DeleteAddressAsync(param));

            //Assert
            ex.Message.Should().ContainEquivalentOf("AddressId");
        }
Exemplo n.º 3
0
        public void WHEN_Scope_is_Empty_SHOULD_throw_ArgumentException(string scope)
        {
            //Arrange
            var customerAddressViewService = _container.CreateInstance <CustomerAddressViewService>();
            var param = new DeleteAddressParam
            {
                Scope      = scope,
                CustomerId = Guid.NewGuid(),
                AddressId  = Guid.NewGuid()
            };

            //Act
            var ex = Assert.ThrowsAsync <ArgumentException>(() => customerAddressViewService.DeleteAddressAsync(param));

            //Assert
            ex.Message.Should().ContainEquivalentOf("Scope");
        }