示例#1
0
        public static string VerifyRecordCountMatchForPocoType(Type pocoType, NPoco.Database db)
        {
            if (db == null)
            {
                return("No database. Run RecreateData");
            }
            string tableName = pocoType.Name + (pocoType.Name.StartsWith("Objects") ? "" : "s");

            //InMemoryCompositeKeyObjects
            var imList = typeof(TestData).GetProperty("InMemory" + tableName).GetValue(null, null);

            int imCount = 0;

            if (imList is IEnumerable)
            {
                var enumerator = ((IEnumerable)imList).GetEnumerator();
                while (enumerator.MoveNext())
                {
                    imCount += 1;
                }
            }

            int dbCount = db.ExecuteScalar <int>("SELECT COUNT(*) FROM " + tableName + ";");

            if (imCount != dbCount)
            {
                return(" For test of " + tableName + ": In Memory Count = " + imCount + "; but Db Count = " + dbCount);
            }
            if (imCount == 0)
            {
                return(" For test of " + tableName + ": In Memory and Db have no items.");
            }
            return("");
        }