Example #1
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);
            }
        }
Example #2
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);
            }
        }
Example #3
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);
            }
        }
Example #4
0
        public void CanSaveAndGetByContent()
        {
            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);

                // FIXME: goes too fast and bam, errors, first is blah
                rurl = new RedirectUrl
                {
                    ContentKey    = _textpage.Key,
                    Url           = "durg",
                    CreateDateUtc = rurl.CreateDateUtc.AddSeconds(1) // ensure time difference
                };
                repo.Save(rurl);
                scope.Complete();

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

            using (IScope scope = provider.CreateScope())
            {
                IRedirectUrlRepository repo  = CreateRepository(provider);
                IRedirectUrl[]         rurls = repo.GetContentUrls(_textpage.Key).ToArray();
                scope.Complete();

                Assert.AreEqual(2, rurls.Length);
                Assert.AreEqual("durg", rurls[0].Url);
                Assert.AreEqual("blah", rurls[1].Url);
            }
        }
Example #5
0
        public void CanSaveAndDelete()
        {
            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);

                rurl = new RedirectUrl
                {
                    ContentKey = _otherpage.Key,
                    Url        = "durg"
                };
                repo.Save(rurl);
                scope.Complete();

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

            using (IScope scope = provider.CreateScope())
            {
                IRedirectUrlRepository repo = CreateRepository(provider);
                repo.DeleteContentUrls(_textpage.Key);
                scope.Complete();

                IEnumerable <IRedirectUrl> rurls = repo.GetContentUrls(_textpage.Key);

                Assert.AreEqual(0, rurls.Count());
            }
        }
 public void Register(string url, Guid contentKey, string culture = null)
 {
     using (var scope = ScopeProvider.CreateScope())
     {
         var redir = _redirectUrlRepository.Get(url, contentKey, culture);
         if (redir != null)
         {
             redir.CreateDateUtc = DateTime.UtcNow;
         }
         else
         {
             redir = new RedirectUrl {
                 Key = Guid.NewGuid(), Url = url, ContentKey = contentKey, Culture = culture
             }
         };
         _redirectUrlRepository.Save(redir);
         scope.Complete();
     }
 }