示例#1
0
        public void TestOfTest_Case01()
        {
            using (var db = new BlogDbContext(dbName)) {
                List <string> logs   = new List <string>();
                var           logger = new CommandExecutingLoggerProvider(logs.Add);
                logger.AddTo(db);

                var contents = db.Articles.OrderBy(x => x.Content).Select(x => x.Title).ToList();
                CollectionAssert.AreEqual(new[] { "Article2", "Article1", "Article3" }, contents);

                var log       = logs.Single(x => x.Contains("SELECT"));
                var selecters = Regex.Match(log, @"SELECT\s+(.*?)\s+FROM").Groups[1].Value;
                Assert.IsFalse(selecters.Contains("Content"));
            }
        }
示例#2
0
        public void Case03()
        {
            using (var db = new BlogDbContext(dbName)) {
                List <string> logs   = new List <string>();
                var           logger = new CommandExecutingLoggerProvider(logs.Add);
                logger.AddTo(db);

                var articlesSelector = Thunk.Create <Auther, IEnumerable <Article> >(x => x.Articles);
                var articles         = db.Authers.SelectMany(articlesSelector.Expression).Select(x => x.Title).ToList();
                CollectionAssert.AreEquivalent(new[] { "Article1", "Article2", "Article3" }, articles);

                foreach (var item in logs)
                {
                    TestContext.WriteLine(item);
                    TestContext.WriteLine("");
                }

                Assert.AreEqual(1, logs.Count(s => s.Contains("SELECT")));
            }
        }
示例#3
0
        public void Case05()
        {
            using (var db = new BlogDbContext(dbName)) {
                List <string> logs   = new List <string>();
                var           logger = new CommandExecutingLoggerProvider(logs.Add);
                logger.AddTo(db);

                var cond1    = Thunk.Create((Article x) => x.Content.Length < 10);
                var cond2    = Thunk.Create((Article x) => x.Content.Length > 8);
                var cond     = cond1.AndAlso(cond2).WithParams((Article x) => default(bool));
                var articles = db.Articles.Where(cond.Expression).Select(x => x.Title).ToList();

                foreach (var item in logs)
                {
                    TestContext.WriteLine(item);
                    TestContext.WriteLine("");
                }

                CollectionAssert.AreEquivalent(new[] { "Article2", }, articles);
                Assert.AreEqual(1, logs.Count(s => s.Contains("SELECT")));
            }
        }
示例#4
0
        public void Case02()
        {
            using (var db = new BlogDbContext(dbName)) {
                List <string> logs   = new List <string>();
                var           logger = new CommandExecutingLoggerProvider(logs.Add);
                logger.AddTo(db);

                var contentSelector = Thunk.Create((Article x) => x.Content);
                var resultSelector  = Thunk.Create((Article x) => "XXX " + x.Title + " XXX");

                var contents = db.Articles.OrderBy(contentSelector.Expression).Select(resultSelector.Expression).ToList();
                CollectionAssert.AreEqual(new[] { "XXX Article2 XXX", "XXX Article1 XXX", "XXX Article3 XXX" }, contents);

                foreach (var item in logs)
                {
                    TestContext.WriteLine(item);
                    TestContext.WriteLine("");
                }

                var log       = logs.Single(x => x.Contains("SELECT"));
                var selecters = Regex.Match(log, @"SELECT\s+(.*?)\s+FROM").Groups[1].Value;
                Assert.IsTrue(selecters.Contains("XXX"));
            }
        }