Beispiel #1
0
        /// <summary>
        /// Create a new Address for the given customer
        /// </summary>
        /// <param name="createAddressParam">Service call params <see cref="CreateAddressParam"/></param>
        /// <returns>
        /// The created Address and a status representing a possible cause of errors.
        /// </returns>
        public virtual async Task <EditAddressViewModel> CreateAddressAsync(CreateAddressParam createAddressParam)
        {
            if (createAddressParam == null)
            {
                throw new ArgumentNullException("createAddressParam");
            }
            if (createAddressParam.CultureInfo == null)
            {
                throw new ArgumentException("createAddressParam.CultureInfo");
            }
            if (createAddressParam.CustomerId == Guid.Empty)
            {
                throw new ArgumentException("createAddressParam.CustomerId");
            }
            if (createAddressParam.EditAddress == null)
            {
                throw new ArgumentException("createAddressParam.EditAddress");
            }
            if (string.IsNullOrWhiteSpace(createAddressParam.Scope))
            {
                throw new ArgumentException("createAddressParam.Scope");
            }

            var createdAddress = await CustomerAddressRepository
                                 .CreateAddressAsync(createAddressParam.CustomerId,
                                                     ConvertToAddress(new Address(), createAddressParam.EditAddress), createAddressParam.Scope)
                                 .ConfigureAwait(false);

            if (createAddressParam.EditAddress.IsPreferredShipping || createAddressParam.EditAddress.IsPreferredBilling)
            {
                await SetDefaultAddressAsync(new SetDefaultAddressParam
                {
                    AddressId  = createdAddress.Id,
                    CustomerId = createAddressParam.CustomerId,
                    Scope      = createAddressParam.Scope
                }).ConfigureAwait(false);
            }

            return(await GetEditAddressViewModel(new GetEditAddressViewModelParam
            {
                Address = createdAddress,
                Status = MyAccountStatus.Success,
                ReturnUrl = createAddressParam.ReturnUrl,
                IsUpdating = false,
                CultureInfo = createAddressParam.CultureInfo
            }).ConfigureAwait(false));
        }
        public void WHEN_EditAddress_is_Null_SHOULD_throw_ArgumentException()
        {
            //Arrange
            var customerAddressViewService = _container.CreateInstance <CustomerAddressViewService>();
            var param = new CreateAddressParam
            {
                ReturnUrl   = GetRandom.String(32),
                Scope       = GetRandom.String(32),
                CultureInfo = TestingExtensions.GetRandomCulture(),
                CustomerId  = Guid.NewGuid(),
            };

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

            //Assert
            ex.Message.Should().ContainEquivalentOf("EditAddress");
        }
        public void WHEN_CultureInfo_is_Empty_SHOULD_throw_ArgumentException(CultureInfo cultureInfo)
        {
            //Arrange
            var customerAddressViewService = _container.CreateInstance <CustomerAddressViewService>();
            var param = new CreateAddressParam
            {
                ReturnUrl   = GetRandom.String(32),
                Scope       = GetRandom.String(32),
                CustomerId  = Guid.NewGuid(),
                EditAddress = new EditAddressRequest(),
                CultureInfo = cultureInfo
            };

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

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