Esempio n. 1
0
        public void WHEN_Customer_is_Null_SHOULD_throw_ArgumentException()
        {
            //Arrange
            var membershipViewService = _container.CreateInstance <MembershipViewService>();

            var param = new GetCustomerChangePasswordViewModelParam
            {
                CultureInfo = TestingExtensions.GetRandomCulture(),
                Scope       = GetRandom.String(32),
            };

            //Act
            var ex = Assert.ThrowsAsync <ArgumentException>(() => membershipViewService.GetChangePasswordViewModelAsync(param));

            //Assert
            ex.Message.Should().ContainEquivalentOf("Customer");
        }
Esempio n. 2
0
        public async Task WHEN_passing_valid_arguments_SHOULD_create_viewmodel()
        {
            //Arrange
            var customer = MockCustomerFactory.CreateRandom();
            var expectedPasswordLength   = GetRandom.PositiveInt();
            var expectedPasswordNonAlpha = GetRandom.PositiveInt();

            var param = new GetCustomerChangePasswordViewModelParam
            {
                CultureInfo = TestingExtensions.GetRandomCulture(),
                Scope       = GetRandom.String(32),
                CustomerId  = customer.Id,
            };
            var membershipViewService = _container.CreateInstance <MembershipViewService>();

            membershipViewService.Membership = _container.Get <IMembershipProxy>();

            _container.GetMock <MembershipProvider>()
            .SetupGet(m => m.MinRequiredPasswordLength)
            .Returns(expectedPasswordLength)
            .Verifiable();

            _container.GetMock <MembershipProvider>()
            .SetupGet(m => m.MinRequiredNonAlphanumericCharacters)
            .Returns(expectedPasswordNonAlpha)
            .Verifiable("Regex must be based on this value");

            var customerRepository = new Mock <ICustomerRepository>();

            customerRepository.Setup(r => r.GetCustomerByIdAsync(It.IsAny <GetCustomerByIdParam>()))
            .ReturnsAsync(customer);

            //Act
            var viewModel = await membershipViewService.GetChangePasswordViewModelAsync(param);

            //Assert
            viewModel.Should().NotBeNull("This view model should never be null");
            viewModel.MinRequiredPasswordLength.Should().Be(expectedPasswordLength);
            viewModel.MinRequiredNonAlphanumericCharacters.Should().Be(expectedPasswordNonAlpha);
            viewModel.PasswordRegexPattern.Should().NotBeNull();

            _container.GetMock <IMembershipProxy>().VerifyAll();
        }
        /// <summary>
        /// Get the view Model to display a Change Password Form and Form result
        /// </summary>
        /// <param name="param">Builder params <see cref="GetCustomerChangePasswordViewModelParam"/></param>
        /// <returns>
        /// The view model to display the Change Password Form
        /// </returns>
        public virtual async Task <ChangePasswordViewModel> GetChangePasswordViewModelAsync(GetCustomerChangePasswordViewModelParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException("param");
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException("param.CultureInfo");
            }
            if (param.CustomerId == Guid.Empty)
            {
                throw new ArgumentException("param.CustomerId");
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException("changePasswordParam.Scope");
            }

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

            return(GetChangePasswordViewModel(new GetChangePasswordViewModelParam
            {
                Customer = customer,
                CultureInfo = param.CultureInfo,
            }));
        }