Example #1
0
        public ActionResult SharedWishListTitle(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(View("SharedWishListHeaderBlade"));
            }

            var param = SharedWishListTokenizer.DecryptToken(id);

            if (param == null)
            {
                return(HttpNotFound());
            }

            var vm = CustomerViewService.GetAccountHeaderViewModelAsync(new GetAccountHeaderViewModelParam
            {
                Scope       = param.Scope,
                CultureInfo = ComposerContext.CultureInfo,
                CustomerId  = param.CustomerId
            }).Result;

            if (vm == null)
            {
                return(HttpNotFound());
            }

            return(View("SharedWishListHeaderContainer", vm));
        }
Example #2
0
        public void WHEN_token_format_is_wrong_SHOULD_return_null()
        {
            //Arrange
            var token = GetRandom.String(17);

            //Act
            var tokenDto = SharedWishListTokenizer.DecryptToken(token);

            //Assert
            tokenDto.Should().BeNull("token is in the wrong format");
        }
Example #3
0
        public void WHEN_token_is_invalid_SHOULD_throw_ArgumentException(string token)
        {
            //Arrange

            //Act
            var ex = Assert.Throws <ArgumentException>(() => SharedWishListTokenizer.DecryptToken(token));

            //Assert
            ex.Should().NotBeNull();
            ex.ParamName.Should().NotBeNullOrWhiteSpace();
        }
        public void WHEN_token_is_null_SHOULD_throw_ArgumentNullException()
        {
            //Arrange
            SharedWishListToken param = null;

            //Act
            var ex = Assert.Throws <ArgumentNullException>(() => SharedWishListTokenizer.GenerateToken(param));

            //Assert
            ex.Should().NotBeNull();
            ex.ParamName.Should().NotBeNullOrWhiteSpace();
        }
        public void WHEN_token_ok_SHOULD_return_encrypted_token()
        {
            //Arrange
            SharedWishListToken param = new SharedWishListToken
            {
                CustomerId = Guid.NewGuid(),
                Scope      = GetRandom.String(6)
            };

            //Act
            var token = SharedWishListTokenizer.GenerateToken(param);

            //Assert
            token.Should().NotBeNullOrWhiteSpace();
            token.Should().NotContainEquivalentOf(param.CustomerId.ToString());
            token.Should().NotContainEquivalentOf(param.Scope);
        }
        public void WHEN_CustomerId_is_invalid_SHOULD_throw_ArgumentNullException()
        {
            //Arrange
            SharedWishListToken param = new SharedWishListToken
            {
                CustomerId = Guid.Empty,
                Scope      = GetRandom.String(6)
            };

            //Act
            var ex = Assert.Throws <ArgumentException>(() => SharedWishListTokenizer.GenerateToken(param));

            //Assert
            ex.Should().NotBeNull();
            ex.ParamName.Should().NotBeNullOrWhiteSpace();
            ex.Message.Should().NotBeNullOrWhiteSpace();
        }
Example #7
0
        public void WHEN_token_is_valid_SHOULD_return_dto(string scope)
        {
            //Arrange
            var param = new SharedWishListToken
            {
                CustomerId = Guid.NewGuid(),
                Scope      = scope
            };

            var token = SharedWishListTokenizer.GenerateToken(param);

            //Act
            var dto = SharedWishListTokenizer.DecryptToken(token);

            //Assert
            dto.Should().NotBeNull();
            dto.CustomerId.Should().Be(param.CustomerId);
            dto.Scope.Should().Be(param.Scope);
        }
Example #8
0
        public ActionResult SharedWishList(string id, XhtmlDocument emptyWishListContent)
        {
            if (string.IsNullOrEmpty(id))
            {
                return(HttpNotFound());
            }

            var param = SharedWishListTokenizer.DecryptToken(id);

            if (param == null)
            {
                return(HttpNotFound());
            }

            var customerStatus = CustomerViewService.GetAccountStatusViewModelAsync(new GetAccountStatusViewModelParam
            {
                CultureInfo = ComposerContext.CultureInfo,
                Scope       = param.Scope,
                CustomerId  = param.CustomerId
            }).Result;

            if (customerStatus == null || customerStatus.Status == AccountStatusEnum.Inactive)
            {
                return(HttpNotFound());
            }

            var vm = WishLisViewService.GetWishListViewModelAsync(new GetCartParam
            {
                BaseUrl     = RequestUtils.GetBaseUrl(Request).ToString(),
                CultureInfo = ComposerContext.CultureInfo,
                CartName    = CartConfiguration.WishlistCartName,
                Scope       = param.Scope,
                CustomerId  = param.CustomerId
            }).Result;

            if (vm != null && vm.TotalQuantity == 0 && emptyWishListContent != null)
            {
                return(View("SharedWishListContainer", new { TotalQuantity = 0, EmptyContent = emptyWishListContent.Body }));
            }

            return(View("SharedWishListContainer", vm));
        }
        public virtual string GetShareUrl(GetShareWishListUrlParam parameters)
        {
            using (ThreadDataManager.EnsureInitialize())
            {
                var token = SharedWishListTokenizer.GenerateToken(new SharedWishListToken
                {
                    CustomerId = parameters.CustomerId,
                    Scope      = parameters.Scope
                });

                var pagesConfiguration   = SiteConfiguration.GetPagesConfiguration(parameters.CultureInfo, WebsiteContext.WebsiteId);
                var shareWishListPageUrl = PageService.GetPageUrl(pagesConfiguration.SharedWishListPageId,
                                                                  parameters.CultureInfo);
                var url = $"{shareWishListPageUrl}?id={token}";
                var uri = new Uri(
                    new Uri(parameters.BaseUrl, UriKind.Absolute),
                    new Uri(url, UriKind.Relative));

                return(uri.ToString());
            }
        }