Exemplo n.º 1
0
        public void UrlTokenIsExpired()
        {
            IUrlTokenStore store = new HttpCacheUrlTokenStore();

            QueryStringUrlTokenUrlProvider<TestIdUrlToken> provider = new QueryStringUrlTokenUrlProvider<TestIdUrlToken>()
            {
                QueryStringKey = "t",
                Url = new Uri("http://tastycodes.com/")
            };

            TestIdUrlToken token = new TestIdUrlToken();
            Uri url = provider.UrlFromToken(token, store);
            token = provider.TokenFromUrl(url, store);
            Assert.IsFalse(token.IsExpired);

            token = new TestIdUrlToken()
            {
                Expires = DateTime.UtcNow.AddHours(-1)
            };

            url = provider.UrlFromToken(token, store);
            token = provider.TokenFromUrl(url, store);
            Assert.IsTrue(token.IsExpired);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Query string URL token URL provider tests.
        /// </summary>
        protected virtual void QueryStringUrlTokenUrlProvider()
        {
            TestIdUrlToken source = new TestIdUrlToken();
            var provider = new QueryStringUrlTokenUrlProvider<TestIdUrlToken>() { QueryStringKey = "tc", Url = new Uri("http://tastycodes.com/") };
            Uri url = provider.UrlFromToken(source);

            TestIdUrlToken result = provider.TokenFromUrl(url);

            Assert.IsNotNull(result);
            Assert.AreEqual(source.Id, result.Id);
        }