Beispiel #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);
        }
Beispiel #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));
        }
Beispiel #3
0
        static UserTestTools()
        {
            SQLiteRegistrar.Register <User>();
            Db.TryEnsureSchema <User>();

            ClearAllUserInfo();
        }
Beispiel #4
0
        public void ShouldRetrievePortEighty()
        {
            SQLiteRegistrar.Register("Crawlers");
            Db.TryEnsureSchema("Crawlers");

            Cr.Port _80 = Cr.Port.OneWhere(c => c.Value == 80);
            Expect.IsNotNull(_80);
        }
Beispiel #5
0
        private static Database RegisterSQLiteForConnection(string newConnectionName)
        {
            Dao.ProxyConnection(typeof(Item), newConnectionName);
            SQLiteRegistrar.Register <Item>();
            Database reproduceIn = Db.For(newConnectionName);//_.Db[newConnectionName];

            SetupSQLiteDatabase(reproduceIn);
            return(reproduceIn);
        }
Beispiel #6
0
        public void AddYourActionHere()
        {
            SQLiteRegistrar.Register("Analytics");
            ImageCollection images = Image.Top(10, c => c.Id >= 1, Order.By <ImageColumns>(c => c.Id, SortOrder.Descending));

            foreach (Image image in images)
            {
                Out(image.UrlOfUrlId.ToString());
            }
        }
        public static void RegisterDb()
        {
            SQLiteDatabase db = new SQLiteDatabase();

            Db.For <Secure.Application>(db);
            Db.For <Account>(UserAccountsDatabase.Default);
            Db.TryEnsureSchema <Secure.Application>(db);
            SQLiteRegistrar.Register <Secure.Application>();
            _registeredDb = true;
        }
Beispiel #8
0
        public void UrlShouldToStringCorrectly()
        {
            SQLiteRegistrar.Register <Url>();
            Db.TryEnsureSchema <Url>();

            Url test = Url.FromUri("http://twitter.github.com/bootstrap/base-css.html#tables");

            Out(test.ToString());
            Expect.AreEqual("http://twitter.github.com/bootstrap/base-css.html#tables", test.ToString());
        }
        static UserTestTools()
        {
            SQLiteDatabase db = new SQLiteDatabase(RuntimeSettings.ProcessDataFolder, "TestUsers");

            Db.For <User>(db);
            SQLiteRegistrar.Register <User>();
            Db.TryEnsureSchema <User>();

            ClearAllUserInfo();
        }
Beispiel #10
0
        public void ShouldNotCreateDupeUrl()
        {
            SQLiteRegistrar.Register(Dao.ConnectionName(typeof(Url)));
            Db.TryEnsureSchema <Url>();

            string uri         = "http://www.funnycatpix.com/";
            Url    funnycatpix = Url.FromUri(uri, true);
            Url    check       = Url.FromUri(uri, true);

            Expect.AreEqual(funnycatpix, check);
            Expect.AreEqual(funnycatpix.Id, check.Id);
        }
Beispiel #11
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));
        }
Beispiel #12
0
        private static void GetProviderAndPendingConfirmation(out DaoMembershipProvider provider, out User user, out Account account)
        {
            SQLiteRegistrar.Register("Users");
            Db.TryEnsureSchema("Users");

            user = UserTestTools.GetTestUser();

            provider = new DaoMembershipProvider();
            account  = Account.Create(user, "test", "test");
            Expect.IsNotNull(account.Id);
            Expect.IsTrue(account.Id > 0);
            Expect.IsFalse(account.IsConfirmed.Value);
        }
Beispiel #13
0
        public DatabaseInitializationResult Initialize()
        {
            DatabaseInitializationResult result = base.Initialize("Encryption");

            if (result.Success)
            {
                result.Initializer = this;
                SQLiteRegistrar.Register(result.Database.ServiceProvider);
            }
            else
            {
                throw result.Exception;
            }

            return(result);
        }
Beispiel #14
0
        public void CrawlForImages()
        {
            ConnectionStringSettings s = new ConnectionStringSettings();

            s.ProviderName = SQLiteRegistrar.SQLiteFactoryAssemblyQualifiedName();

            string path = Prompt("Please enter the path to the Analytics database");

            s.ConnectionString = string.Format("Data Source={0};Version=3;", path);

            DefaultConnectionStringResolver.Instance.Resolver = (cn) =>
            {
                if (cn.Equals(Image.ConnectionName(typeof(Image))))
                {
                    OutFormat("Resolved connectionString {0}", s.ConnectionString);
                    return(s);
                }

                OutFormat("Couldn't resolve connectionString for connectionName {0}", cn);
                return(null);
            };
            SQLiteRegistrar.Register <Image>();

            ImageCrawler crawler = new ImageCrawler();

            crawler.OnImageFound = (u, src) =>
            {
                string url = u.ToString();
                OutFormat("Url: {0}\r\n", ConsoleColor.Cyan, url);
                OutFormat("Src: {0}\r\n", ConsoleColor.Green, src);
            };

            crawler.ActionChanged += (cr, args) =>
            {
                OutFormat("{0}::{1}", args.OldAction.ToString(), args.NewAction.ToString());
            };

            string startUrl = Prompt("Enter the starting url");

            crawler.Name = startUrl;
            Crawler data = new Crawler();

            data.Name    = startUrl;
            data.RootUrl = startUrl;
            data.Save();
            crawler.Crawl(startUrl);
        }
Beispiel #15
0
        public BamServer(BamConf conf)
        {
            _responders       = new HashSet <IResponder>();
            _respondersByName = new Dictionary <string, IResponder>();
            Initialized      += HandlePostInitialization;
            SetConf(conf);
            BindEventListeners(conf);
            EnableDao          = true;
            EnableServiceProxy = true;

            SQLiteRegistrar.RegisterFallback();

            AppDomain.CurrentDomain.DomainUnload += (s, a) =>
            {
                Stop();
            };
        }
Beispiel #16
0
        public override ConnectionStringResolveResult ResolveConnectionString(string connectionName)
        {
            try
            {
                Args.ThrowIfNull(VaultFile, "VaultFile");

                ConnectionStringSettings s = new ConnectionStringSettings();
                s.ProviderName     = SQLiteRegistrar.SQLiteFactoryAssemblyQualifiedName();
                s.ConnectionString = string.Format("Data Source={0};Version=3;", VaultFile.FullName);

                return(new ConnectionStringResolveResult(s));
            }
            catch (Exception ex)
            {
                return(new ConnectionStringResolveResult(null, ex));
            }
        }
Beispiel #17
0
        public void ImageCrawlerCreateMineShouldSetRootUrlAndName()
        {
            Dictionary <string, string> testSettings = new Dictionary <string, string>();
            string setAppNameTo = "TheMonkey";

            testSettings.Add("ApplicationName", setAppNameTo);
            DefaultConfiguration.SetAppSettings(testSettings);
            SQLiteRegistrar.Register(Dao.ConnectionName(typeof(Url)));
            Db.TryEnsureSchema <Url>();

            string appName = DefaultConfiguration.GetAppSetting("ApplicationName", "BAD");
            string rootUrl = "http://www.flickr.com/galleries/";

            Expect.IsFalse(appName.Equals("BAD"), "ApplicationName was not set in the config file");

            ImageCrawler c = (ImageCrawler)ImageCrawler.CreateMine(rootUrl);

            Expect.AreEqual(appName, setAppNameTo);
            Expect.AreEqual(appName, c.Name);
            Expect.AreEqual(rootUrl, c.Root);
        }
Beispiel #18
0
        public static void ShouldRecreateSchemaSQLite()
        {
            Database reproduceIn = RegisterSQLiteForConnection("ReproSchemaSQLite");

            DropAllTables(reproduceIn);
            Incubator sp = reproduceIn.ServiceProvider;

            SQLiteRegistrar.Register(reproduceIn.ServiceProvider);

            SchemaWriter writer = sp.GetNew <SchemaWriter>();

            Expect.IsTrue(writer is SQLiteSqlStringBuilder);
            Expect.IsTrue(writer.WriteSchemaScript <Item>(), "WriteSchemaScript returned false instead of true");
            Exception e;
            bool      executeResult = writer.TryExecute(reproduceIn, out e);

            Expect.IsNull(e, e == null ? "" : e.Message); // no exception should have occurred

            Expect.IsTrue(executeResult, "TryExecute returned false instead of true");

            Expect.IsFalse(writer.WriteSchemaScript <Item>(), "WriteSchemaScript returned true instead of false");
        }
Beispiel #19
0
        public void ClassifierTest()
        {
            SQLiteRegistrar.Register <Feature>();
            Db.EnsureSchema <Feature>();

            When.A <NaiveBayesClassifier>("is trained", (classifer) =>
            {
                classifer.Train("The quick brown fox jumps over the lazy dog", "good");
                classifer.Train("make quick money in the online casino", "bad");
            })
            .TheTest
            .ShouldPass(because =>
            {
                Classifier classifier = because.ObjectUnderTest <Classifier>();
                long quickGood        = classifier.FeatureCount("quick", "good");
                long quickBad         = classifier.FeatureCount("quick", "bad");
                because.ItsTrue("The good count of 'quick' is " + quickGood, quickGood > 0);
                because.ItsTrue("The bad count of 'quick' is " + quickBad, quickBad > 0);
            })
            .SoBeHappy(c =>
            {
            })
            .UnlessItFailed();
        }
 public static void RegisterDb()
 {
     SQLiteRegistrar.Register <Application>();
     Db.TryEnsureSchema <Application>();
     _registeredDb = true;
 }
Beispiel #21
0
 public static void OutputSQLiteName()
 {
     SQLiteRegistrar.OutputAssemblyQualifiedName();
 }
Beispiel #22
0
 private static void Init()
 {
     SQLiteRegistrar.Register <Url>();
     Db.TryEnsureSchema <Url>();
 }
Beispiel #23
0
 private void Register()
 {
     SQLiteRegistrar.Register(this);
     Infos.Add(new DatabaseInfo(this));
 }