예제 #1
0
        public async Task WHEN_passing_valid_arguments_SHOULD_create_viewmodel()
        {
            //Arrange
            var customer = MockCustomerFactory.CreateRandom();

            var mockedCustomerRepository = new Mock <ICustomerRepository>();

            mockedCustomerRepository.Setup(r => r.GetCustomerByIdAsync(It.Is <GetCustomerByIdParam>(p => p.CustomerId == customer.Id)))
            .ReturnsAsync(customer);
            _container.Use(mockedCustomerRepository);

            var expectedStatus = TestingExtensions.GetRandomEnum <MyAccountStatus>();
            var param          = new GetUpdateAccountViewModelParam
            {
                Status      = expectedStatus,
                CultureInfo = TestingExtensions.GetRandomCulture(),
                CustomerId  = customer.Id,
                ReturnUrl   = GetRandom.WwwUrl(),
                Scope       = GetRandom.String(32)
            };
            var customerViewService = _container.CreateInstance <CustomerViewService>();

            //Act
            var viewModel = await customerViewService.GetUpdateAccountViewModelAsync(param);

            //Assert
            viewModel.Should().NotBeNull("This view model should never be null");
            viewModel.Status.Should().Be(expectedStatus.ToString("G"), "Because we render the status as a string for HBS message switch");
            viewModel.ReturnUrl.Should().Be(param.ReturnUrl);
            viewModel.Email.Should().Be(customer.Email);
            viewModel.FirstName.Should().Be(customer.FirstName);
            viewModel.LastName.Should().Be(customer.LastName);
        }
예제 #2
0
        public async Task WHEN_Status_is_NULL_SHOULD_create_view_model_with_empty_status(MyAccountStatus?status)
        {
            //Arrange
            var customer = MockCustomerFactory.CreateRandom();

            var mockedCustomerRepository = new Mock <ICustomerRepository>();

            mockedCustomerRepository.Setup(r => r.GetCustomerByIdAsync(It.Is <GetCustomerByIdParam>(p => p.CustomerId == customer.Id)))
            .ReturnsAsync(customer);
            _container.Use(mockedCustomerRepository);

            var param = new GetUpdateAccountViewModelParam
            {
                Status      = status,
                CultureInfo = TestingExtensions.GetRandomCulture(),
                CustomerId  = customer.Id,
                ReturnUrl   = GetRandom.WwwUrl(),
                Scope       = GetRandom.String(32)
            };
            var customerViewService = _container.CreateInstance <CustomerViewService>();

            //Act
            var viewModel = await customerViewService.GetUpdateAccountViewModelAsync(param);

            //Assert
            viewModel.Status.Should().BeEmpty();
        }
        protected virtual UpdateAccountViewModel GetUpdateAccountViewModel(GetUpdateAccountViewModelParam param, Customer customer)
        {
            var viewModel = ViewModelMapper.MapTo <UpdateAccountViewModel>(customer, param.CultureInfo);

            viewModel.Status    = param.Status.HasValue ? param.Status.Value.ToString("G") : string.Empty;
            viewModel.ReturnUrl = param.ReturnUrl;
            viewModel.Languages = GetPreferredLanguageViewModel(param.CultureInfo, customer.Language);

            return(viewModel);
        }
예제 #4
0
        public void WHEN_Customer_is_Null_SHOULD_throw_ArgumentException()
        {
            //Arrange
            var customerViewService = _container.CreateInstance <CustomerViewService>();
            var param = new GetUpdateAccountViewModelParam
            {
                Status      = TestingExtensions.GetRandomEnum <MyAccountStatus>(),
                CultureInfo = TestingExtensions.GetRandomCulture(),
                ReturnUrl   = GetRandom.WwwUrl(),
                Scope       = GetRandom.String(32)
            };

            //Act
            var ex = Assert.ThrowsAsync <ArgumentException>(() => customerViewService.GetUpdateAccountViewModelAsync(param));

            //Assert
            ex.Message.Should().ContainEquivalentOf("Customer");
        }
        public virtual ActionResult UpdateAccount()
        {
            var urlParam = new BaseUrlParameter
            {
                CultureInfo = ComposerContext.CultureInfo
            };
            var changePasswordUrl = MyAccountUrlProvider.GetChangePasswordUrl(urlParam);
            var addressListUrl    = MyAccountUrlProvider.GetAddressListUrl(urlParam);

            var param = new GetUpdateAccountViewModelParam
            {
                Scope       = ComposerContext.Scope,
                CultureInfo = ComposerContext.CultureInfo,
                CustomerId  = ComposerContext.CustomerId
            };

            var viewModel = CustomerViewService.GetUpdateAccountViewModelAsync(param).Result;

            viewModel.ChangePasswordUrl = changePasswordUrl;
            viewModel.AddressListUrl    = addressListUrl;

            return(View("UpdateAccountBlade", viewModel));
        }
예제 #6
0
        /// <summary>
        /// Update the account informations.
        /// </summary>
        /// <param name="param">Builder params <see cref="UpdateAccountParam"/></param>
        /// <returns></returns>
        public async virtual Task <UpdateAccountViewModel> UpdateAccountAsync(UpdateAccountParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(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 (string.IsNullOrWhiteSpace(param.Email))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Email)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.FirstName))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.FirstName)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.LastName))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.LastName)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.PreferredLanguage))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.PreferredLanguage)), nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param));
            }

            var customer = await CustomerRepository.GetCustomerByIdAsync(new GetCustomerByIdParam
            {
                Scope       = param.Scope,
                CustomerId  = param.CustomerId,
                CultureInfo = param.CultureInfo
            }).ConfigureAwait(false);

            if (customer == null)
            {
                return(null);
            }

            UpdateCustomerInfo(customer, param);

            var updateUserParam = new UpdateUserParam
            {
                Customer = customer,
                Scope    = param.Scope
            };

            var updatedCustomer = await CustomerRepository.UpdateUserAsync(updateUserParam).ConfigureAwait(false);

            var getUpdateAccountViewModelParam = new GetUpdateAccountViewModelParam
            {
                Status      = MyAccountStatus.Success,
                CultureInfo = param.CultureInfo,
                ReturnUrl   = param.ReturnUrl
            };

            return(GetUpdateAccountViewModel(getUpdateAccountViewModelParam, updatedCustomer));
        }
예제 #7
0
        /// <summary>
        /// Gets the <see cref="UpdateAccountViewModel"/> to display the UpdateAccount Form or Form result
        /// </summary>
        /// <param name="param">Builder params <see cref="GetUpdateAccountViewModelParam"/></param>
        /// <returns></returns>
        public async virtual Task <UpdateAccountViewModel> GetUpdateAccountViewModelAsync(GetUpdateAccountViewModelParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(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 (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param));
            }

            var customer = await CustomerRepository.GetCustomerByIdAsync(new GetCustomerByIdParam
            {
                CultureInfo = param.CultureInfo,
                CustomerId  = param.CustomerId,
                Scope       = param.Scope
            }).ConfigureAwait(false);

            return(GetUpdateAccountViewModel(param, customer));
        }