public IRedirectUrl GetMostRecentRedirectUrl(string url)
 {
     using (var scope = ScopeProvider.CreateScope(autoComplete: true))
     {
         return(_redirectUrlRepository.GetMostRecentUrl(url));
     }
 }
Beispiel #2
0
        public void CanSaveAndGet()
        {
            IScopeProvider provider = ScopeProvider;

            using (IScope scope = provider.CreateScope())
            {
                IRedirectUrlRepository repo = CreateRepository(provider);
                var rurl = new RedirectUrl
                {
                    ContentKey = _textpage.Key,
                    Url        = "blah"
                };
                repo.Save(rurl);
                scope.Complete();

                Assert.AreNotEqual(0, rurl.Id);
            }

            using (IScope scope = provider.CreateScope())
            {
                IRedirectUrlRepository repo = CreateRepository(provider);
                IRedirectUrl           rurl = repo.GetMostRecentUrl("blah");
                scope.Complete();

                Assert.IsNotNull(rurl);
                Assert.AreEqual(_textpage.Id, rurl.ContentId);
            }
        }
Beispiel #3
0
        public void CanSaveAndGetWithCulture()
        {
            string culture = "en";

            using (IScope scope = ScopeProvider.CreateScope())
            {
                IRedirectUrlRepository repo = CreateRepository(ScopeProvider);
                var rurl = new RedirectUrl
                {
                    ContentKey = _textpage.Key,
                    Url        = "blah",
                    Culture    = culture
                };
                repo.Save(rurl);
                scope.Complete();

                Assert.AreNotEqual(0, rurl.Id);
            }

            using (IScope scope = ScopeProvider.CreateScope())
            {
                IRedirectUrlRepository repo = CreateRepository(ScopeProvider);
                IRedirectUrl           rurl = repo.GetMostRecentUrl("blah");
                scope.Complete();

                Assert.IsNotNull(rurl);
                Assert.AreEqual(_textpage.Id, rurl.ContentId);
                Assert.AreEqual(culture, rurl.Culture);
            }
        }
Beispiel #4
0
        public void CanSaveAndGetMostRecentForCulture()
        {
            string cultureA = "en";
            string cultureB = "de";

            Assert.AreNotEqual(_textpage.Id, _otherpage.Id);

            using (IScope scope = ScopeProvider.CreateScope())
            {
                IRedirectUrlRepository repo = CreateRepository(ScopeProvider);
                var rurl = new RedirectUrl
                {
                    ContentKey = _textpage.Key,
                    Url        = "blah",
                    Culture    = cultureA
                };
                repo.Save(rurl);
                scope.Complete();

                Assert.AreNotEqual(0, rurl.Id);

                // FIXME: too fast = same date = key violation?
                // and... can that happen in real life?
                // we don't really *care* about the IX, only supposed to make things faster...
                // BUT in realife we AddOrUpdate in a trx so it should be safe, always
                rurl = new RedirectUrl
                {
                    ContentKey    = _otherpage.Key,
                    Url           = "blah",
                    CreateDateUtc = rurl.CreateDateUtc.AddSeconds(1), // ensure time difference
                    Culture       = cultureB
                };
                repo.Save(rurl);
                scope.Complete();

                Assert.AreNotEqual(0, rurl.Id);
            }

            using (IScope scope = ScopeProvider.CreateScope())
            {
                IRedirectUrlRepository repo = CreateRepository(ScopeProvider);
                IRedirectUrl           rurl = repo.GetMostRecentUrl("blah", cultureA);
                scope.Complete();

                Assert.IsNotNull(rurl);
                Assert.AreEqual(_textpage.Id, rurl.ContentId);
                Assert.AreEqual(cultureA, rurl.Culture);
            }
        }