Esempio n. 1
0
        public void CanCompileInjectedEvilCode()
        {
            var evilCode =
                @"new DoEvil();
            }

            private class DoEvil
            {
            public DoEvil()
            {
                new System.IO.DirectoryInfo(""c colon backslash"").Delete(true);
            }
            //";

            var compiler = new CachingLinqCompiler(typeof(TestModel));
            compiler.GetCompiledQuery(evilCode, new object[0]);
        }
Esempio n. 2
0
        public void CanCompileAllQueries()
        {
            int failedQueries = 0;
            for (int i = 0; i < allQueries.Length; i++)
            {
                try
                {
                    var target = new CachingLinqCompiler(typeof(TestModel));
                    var args = new object[] { "a string", 42 };
                    target.GetCompiledQuery(allQueries[i], args);

                }
                catch (Exception ex)
                {
                    failedQueries++;
                    Console.WriteLine("Query id {0} failed", i);
                    Console.WriteLine(ex);
                }
            }
            Assert.AreEqual(0, failedQueries);
        }
Esempio n. 3
0
 public void RepeatedQueryIsCompiledWhenCompilationIsForced()
 {
     var target = new CachingLinqCompiler(typeof(TestModel));
     target.ForceCompilation = true;
     var query = allQueries[0];
     var args = new object[] { "a" };
     Assert.AreEqual(0, target.CompilerInvocations);
     target.GetCompiledQuery(query, args);
     Assert.AreEqual(1, target.CompilerInvocations);
     target.GetCompiledQuery(query, args);
     Assert.AreEqual(2, target.CompilerInvocations);
 }
Esempio n. 4
0
 public void RepeatedQueryIsCachedWhenParametersDiffer()
 {
     var target = new CachingLinqCompiler(typeof(TestModel));
     var query = FirstCustomersNameStartingWithArg0;
     Assert.AreEqual(0, target.CompilerInvocations);
     target.GetCompiledQuery(query, new object[] { "H" });
     Assert.AreEqual(1, target.CompilerInvocations);
     target.GetCompiledQuery(query, new object[] { "R" });
     Assert.AreEqual(1, target.CompilerInvocations);
 }
Esempio n. 5
0
 public void CompilationFailsWhenPassedNullArgument()
 {
     var args = new object[] { null };
     var compiler = new CachingLinqCompiler(typeof(TestModel));
     compiler.GetCompiledQuery(FirstCustomersNameStartingWithArg0, args);
 }