Пример #1
0
        public static void XrefAddNewAndDeleteTest()
        {
            SQLiteRegistrar.Register("Crawlers");
            Db.TryEnsureSchema("Crawlers");
            string testUri = "http://monkey.cxm/bananas?are=yummy&random=".RandomLetters(4);


            Cr.Url url      = Cr.Url.FromUri(testUri);
            int    tagCount = url.Tags.Count;

            OutFormat("UrlId={0}: Initial Tag count {1}: ", ConsoleColor.Cyan, url.Id, tagCount);
            foreach (Cr.Tag tag in url.Tags)
            {
                OutFormat("\t{0}", ConsoleColor.Cyan, tag.Value);
            }

            Cr.Tag newTag = url.Tags.AddNew();
            newTag.Value = "value_".RandomString(6);

            url.Save();

            OutFormat("Tag count after AddNew {0}", ConsoleColor.Yellow, url.Tags.Count);
            Expect.AreEqual(tagCount + 1, url.Tags.Count);
            Cr.Url check = Cr.Url.FromUri(url.ToString());
            Expect.AreEqual(url.ToString(), check.ToString());
            Expect.AreEqual(url.Id, check.Id);
            Expect.AreEqual(url.Tags.Count, check.Tags.Count);

            long id = url.Id.Value;

            url.Delete();
            Cr.UrlTagCollection xref = Cr.UrlTag.Where(c => c.Id == id);
            Expect.AreEqual(0, xref.Count);
        }
Пример #2
0
        public static void XrefAddToBothSidesTest()
        {
            SQLiteRegistrar.Register("Crawlers");
            Db.TryEnsureSchema("Crawlers");
            string testUri = "http://monkey.cxm/some/path?querystring=".RandomLetters(6);

            Cr.Url url = Cr.Url.FromUri(testUri);
            Cr.Tag tag = new Cr.Tag();
            tag.Value = "TheTag";

            url.Tags.Add(tag);
            Expect.AreEqual(1, url.Tags.Count);

            url.Save();

            Cr.Url check = Cr.Url.FromUri(testUri);
            Expect.AreEqual(1, check.Tags.Count);

            Expect.IsTrue(check.Tags.Contains(tag));

            check.Tags.Remove(tag);

            Expect.AreEqual(0, check.Tags.Count);

            Cr.Url checkAgain = Cr.Url.FromUri(testUri);
            Expect.AreEqual(0, checkAgain.Tags.Count);

            tag.Urls.Add(check);
            tag.Save();

            check.Tags.Reload();
            Expect.AreEqual(1, check.Tags.Count);
            Expect.IsTrue(check.Tags.Contains(tag));
        }
Пример #3
0
        public static void FromUriShouldReturnSameUrlIfSameUri()
        {
            SQLiteRegistrar.Register("Crawlers");
            Db.TryEnsureSchema("Crawlers");

            string uri = "http://monkey.cxm/some/path/here?querystring=value";

            Cr.Url url  = Cr.Url.FromUri(uri);
            Cr.Url url2 = Cr.Url.FromUri(uri);

            Expect.IsTrue(url.Equals(url2));
        }