public virtual async Task <IHttpActionResult> UserMetadata()
        {
            var getParam = new GetUserMetadataParam
            {
                CustomerId          = ComposerContext.CustomerId,
                CultureInfo         = ComposerContext.CultureInfo,
                Scope               = ComposerContext.Scope,
                IsAuthenticated     = ComposerContext.IsAuthenticated,
                EncryptedCustomerId = ComposerContext.GetEncryptedCustomerId()
            };

            var vm = await MembershipViewService.GetUserMetadataModel(getParam);

            return(Ok(vm));
        }
Пример #2
0
        public async Task WHEN_Customer_is_Null_SHOULD_create_view_model_with_empty_bag()
        {
            //Arrange
            var isAuthenticated = GetRandom.Boolean();
            var cultureInfo     = TestingExtensions.GetRandomCulture();

            var expectedLoginUrl = _container.Get <IMyAccountUrlProvider>().GetLoginUrl(new BaseUrlParameter
            {
                CultureInfo = cultureInfo
            });

            var expectedMyAccountUrl = _container.Get <IMyAccountUrlProvider>().GetMyAccountUrl(new BaseUrlParameter
            {
                CultureInfo = cultureInfo
            });

            var membershipViewService = _container.CreateInstance <MembershipViewService>();

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

            var getParam = new GetUserMetadataParam
            {
                Scope               = GetRandom.String(32),
                CustomerId          = GetRandom.Guid(),
                CultureInfo         = cultureInfo,
                EncryptedCustomerId = GetRandom.String(64),
                IsAuthenticated     = isAuthenticated
            };

            //Act
            var viewModel = await membershipViewService.GetUserMetadataModel(getParam);

            //Assert
            viewModel.Should().NotBeNull("This view model should never be null");
            viewModel.IsAuthenticated.Should().Be(isAuthenticated);
            if (isAuthenticated)
            {
                viewModel.Url.Should().Be(expectedMyAccountUrl, "Because logged in user are invited to their account");
            }
            else
            {
                viewModel.Url.Should().Be(expectedLoginUrl, "Because logged out user are invited to log in");
            }
            viewModel.Bag.Should().BeEmpty("No PropertyBag to load from");
        }
        /// <summary>
        /// Get the view Model to display User information
        /// </summary>
        /// <returns>
        /// The view model to display the User information
        /// </returns>
        public virtual async Task <UserMetadataViewModel> GetUserMetadataModel(GetUserMetadataParam param)
        {
            var urlParam = new BaseUrlParameter {
                CultureInfo = param.CultureInfo
            };

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

            var viewModel = ViewModelMapper.MapTo <UserMetadataViewModel>(customer, param.CultureInfo) ?? new UserMetadataViewModel();

            viewModel.IsAuthenticated     = param.IsAuthenticated;
            viewModel.EncryptedCustomerId = param.EncryptedCustomerId;
            viewModel.Url         = viewModel.IsAuthenticated ? MyAccountUrlProvider.GetMyAccountUrl(urlParam) : MyAccountUrlProvider.GetLoginUrl(urlParam);
            viewModel.RegisterUrl = MyAccountUrlProvider.GetCreateAccountUrl(urlParam);
            return(viewModel);
        }
Пример #4
0
        public async Task WHEN_passing_valid_arguments_SHOULD_create_viewmodel()
        {
            //Arrange
            var isAuthenticated = GetRandom.Boolean();
            var firstName       = GetRandom.String(32);
            var lastName        = GetRandom.String(32);
            var cultureInfo     = TestingExtensions.GetRandomCulture();

            var composerContext = new Mock <IComposerContext>();

            composerContext
            .SetupGet(c => c.IsAuthenticated)
            .Returns(isAuthenticated);

            _container.Use(composerContext);

            var customerRepository = new Mock <ICustomerRepository>();

            customerRepository
            .Setup(c => c.GetCustomerByIdAsync(It.IsAny <GetCustomerByIdParam>()))
            .ReturnsAsync(new Customer
            {
                FirstName = firstName,
                LastName  = lastName
            });

            _container.Use(customerRepository);

            var expectedLoginUrl = _container.Get <IMyAccountUrlProvider>().GetLoginUrl(new BaseUrlParameter
            {
                CultureInfo = cultureInfo
            });

            var expectedMyAccountUrl = _container.Get <IMyAccountUrlProvider>().GetMyAccountUrl(new BaseUrlParameter
            {
                CultureInfo = cultureInfo
            });

            var membershipViewService = _container.CreateInstance <MembershipViewService>();

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

            var getParam = new GetUserMetadataParam
            {
                Scope               = GetRandom.String(32),
                CustomerId          = GetRandom.Guid(),
                CultureInfo         = cultureInfo,
                EncryptedCustomerId = GetRandom.String(64),
                IsAuthenticated     = isAuthenticated
            };

            //Act
            var viewModel = await membershipViewService.GetUserMetadataModel(getParam);

            //Assert
            viewModel.Should().NotBeNull("This view model should never be null");
            viewModel.IsAuthenticated.Should().Be(isAuthenticated);

            if (isAuthenticated)
            {
                viewModel.Url.Should().Be(expectedMyAccountUrl, "Because logged in user are invited to their account");
            }
            else
            {
                viewModel.Url.Should().Be(expectedLoginUrl, "Because logged out user are invited to log in");
            }

            viewModel.FirstName.Should().Be(firstName);
            viewModel.LastName.Should().Be(lastName);
        }