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();
        }
예제 #4
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);
        }
        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());
            }
        }