Exemple #1
0
        public void GetPosts_Should_Return_list_of_Posts()
        {
            var sql = "SELECT COUNT(ID) From wp_posts";
            var baseCount = new CodingHorror(provider, sql)
                .ExecuteScalar<int>();
            var posts = repo.GetPosts();

            Assert.Equal(baseCount, posts.Count());
        }
Exemple #2
0
        public void All_Should_Return_Correct_count_of_Posts()
        {
            var sql = "SELECT COUNT(ID) From wp_posts";
            var baseCount = new CodingHorror(provider, sql).ExecuteScalar<int>();

            var allCount = repo.All<Post>().Count();

            Assert.Equal(baseCount, allCount);
        }
Exemple #3
0
        public void Can_Connect_To_DB()
        {
            var sql = "SELECT ID From wp_posts LIMIT 1";
            bool connected = false;
            using (IDataReader query = new CodingHorror(provider, sql).ExecuteReader()) {
                connected = query.Read();

            }

            Assert.True(connected, "Can't connect to MySQL DB");
        }
 static void DropTestTable(IDataProvider provider)
 {
     var qry = new CodingHorror(provider, "DROP TABLE SubSonicTests");
     try
     {
         qry.Execute();
     }
     catch
     {
         //nada
     }
 }
        public SimpleRepositoryTests()
        {
            _provider = ProviderFactory.GetProvider("WestWind");
            //_provider = ProviderFactory.GetProvider(new SQLitey().Connection,"System.Data.SQLite");
            //_provider = ProviderFactory.GetProvider(@"server=localhost;database=SubSonic;user id=root; password=;","MySql.Data.MySqlClient");

            _repo = new SimpleRepository(_provider, SimpleRepositoryOptions.RunMigrations);
            try
            {
                var qry = new CodingHorror(_provider, "DROP TABLE Shwerkos").Execute();
            }
            catch { }
        }
        static void DropTestTable(IDataProvider provider)
        {
            var qry = new CodingHorror(provider, "DROP TABLE SubSonicTests");

            try
            {
                qry.Execute();
            }
            catch
            {
                //nada
            }
        }
        public SimpleRepositoryTests()
        {
            _provider = ProviderFactory.GetProvider("WestWind");
            //_provider = ProviderFactory.GetProvider(new SQLitey().Connection,"System.Data.SQLite");
            //_provider = ProviderFactory.GetProvider(@"server=localhost;database=SubSonic;user id=root; password=;","MySql.Data.MySqlClient");

            _repo = new SimpleRepository(_provider, SimpleRepositoryOptions.RunMigrations);
            try
            {
                var qry = new CodingHorror(_provider, "DROP TABLE Shwerkos").Execute();
            }
            catch { }
        }
        public void Migration_MigrateToDb_Should_Save_Schema_To_MySQL()
        {
            var provider = ProviderFactory.GetProvider(TestConfiguration.MySqlTestConnectionString, DbClientTypeName.MySqlClient);

            DropTestTable(provider);
            var assembly = Assembly.GetExecutingAssembly();

            provider.MigrateToDatabase <SubSonicTest>(assembly);

            //query it to make sure it's there
            var qry = new CodingHorror(provider, "SELECT * FROM SubSonicTests").ExecuteTypedList <SubSonicTest>();

            Assert.Empty(qry);
        }
        public SimpleRepositoryTests(IDataProvider provider)
        {
            _provider = provider;

            _repo = new SimpleRepository(_provider, SimpleRepositoryOptions.RunMigrations);
            try
            {
                var qry = new CodingHorror(_provider, "DROP TABLE Shwerkos").Execute();
            }
            catch { }

            try
            {
                new CodingHorror(_provider, "DROP TABLE DummyForDeletes").Execute();
            }
            catch { }
        }
        public void Migration_MigrateToDb_Should_Save_Schema_To_SqlLite()
        {

            if (!File.Exists(TestConfiguration.SQLiteMigrationsFilePath))
                throw new InvalidOperationException("Can't find the DB");
            string connString = TestConfiguration.SQLiteMigrationsConnectionString;

            var provider = ProviderFactory.GetProvider(connString, DbClientTypeName.SqlLite);

            DropTestTable(provider);
            var assembly = Assembly.GetExecutingAssembly();
            provider.MigrateToDatabase<SubSonicTest>(assembly);

            //query it to make sure it's there
            var qry = new CodingHorror(provider, "SELECT * FROM SubSonicTests").ExecuteTypedList<SubSonicTest>();
            Assert.Equal(0, qry.Count);
        }
Exemple #11
0
        public void Migration_MigrateToDb_Should_Save_Schema_To_SqlLite()
        {
            if (!File.Exists(TestConfiguration.SQLiteMigrationsFilePath))
            {
                throw new InvalidOperationException("Can't find the DB");
            }
            string connString = TestConfiguration.SQLiteMigrationsConnectionString;

            var provider = ProviderFactory.GetProvider(connString, DbClientTypeName.SqlLite);

            DropTestTable(provider);
            var assembly = Assembly.GetExecutingAssembly();

            provider.MigrateToDatabase <SubSonicTest>(assembly);

            //query it to make sure it's there
            var qry = new CodingHorror(provider, "SELECT * FROM SubSonicTests").ExecuteTypedList <SubSonicTest>();

            Assert.Empty(qry);
        }
Exemple #12
0
        public ActionResult Search(string q)
        {
            var model = new ArchiveViewModel(new List<Post>());
            model.Categories = Hana.Model.Category.All().ToList();
            if (!String.IsNullOrEmpty(q))
            {
                //id is the query term
                //I know you won't like this
                //but that's OK -it's my blog :)
                var posts = new CodingHorror(ProviderFactory.GetProvider("Hana"), @"SELECT TOP 30
                Posts.PostID, Posts.Title, Posts.Body, Posts.Excerpt,
                Posts.Author, Posts.PublishedOn,Posts.Slug, Posts.Tags, Posts.CommentCount
                FROM dbo.SearchPosts(@p0) as t0
                INNER JOIN Posts on Posts.PostID=t0.PostID
                ORDER BY t0.Rank DESC", q).ExecuteTypedList<Post>();

                model = new ArchiveViewModel(posts);
                model.SearchTerm = q;
                if (Request.IsAjaxRequest())
                {
                    return View("PostSummaryList", model.PostList);
                }
                return View(model);
            }
            return View();
        }
        public SimpleRepositoryTests(IDataProvider provider)
        {
            _provider = provider;
            _provider.Log = Console.Out;

            _repo = new SimpleRepository(_provider, SimpleRepositoryOptions.RunMigrations);
            try
            {
                var qry = new CodingHorror(_provider, "DROP TABLE Shwerkos").Execute();
            }
            catch { }

            try
            {
                new CodingHorror(_provider, "DROP TABLE DummyForDeletes").Execute();
            }
            catch { }

            try
            {
                new CodingHorror(_provider, "DROP TABLE Shwerko2s").Execute();
            }
            catch { }

            try
            {
                new CodingHorror(_provider, "DROP TABLE NonAutoIncrementingIdWithDefaultSettings").Execute();
            }
            catch { }
        }
        public void Migration_MigrateToDb_Should_Save_Schema_To_MySQL()
        {
            var provider = ProviderFactory.GetProvider(TestConfiguration.MySqlTestConnectionString, DbClientTypeName.MySql);
            DropTestTable(provider);
            var assembly = Assembly.GetExecutingAssembly();
            provider.MigrateToDatabase<SubSonicTest>(assembly);

            //query it to make sure it's there
            var qry = new CodingHorror(provider, "SELECT * FROM SubSonicTests").ExecuteTypedList<SubSonicTest>();
            Assert.Equal(0, qry.Count);
        }
Exemple #15
0
        public void GetPosts_Should_Return_list_of_Posts_by_status()
        {
            var sql = "SELECT COUNT(ID) From wp_posts where post_status='publish'";
            var baseCount = new CodingHorror(provider, sql)
                .ExecuteScalar<int>();
            var posts = repo.GetPosts()
                .Where(x=>x.Status==Post.Status_Published);

            Assert.Equal(baseCount, posts.Count());
        }