Esempio n. 1
0
        public void UnboundParameterException_ThrowIfOpen_Negative()
        {
            var f = (Expression <Func <int, int> >)(x => x + 1);

            UnboundParameterException.ThrowIfOpen(f, "Oops");

            Assert.IsTrue(true);
        }
Esempio n. 2
0
        public void UnboundParameterException_ThrowIfOpen_Positive()
        {
            var f = (Expression <Func <int, int> >)(x => x + 1);

            AssertEx.ThrowsException <UnboundParameterException>(() => UnboundParameterException.ThrowIfOpen(f.Body, "Oops"), ex =>
            {
                Assert.AreSame(f.Body, ex.Expression);
                Assert.IsTrue(f.Parameters.SequenceEqual(ex.Parameters));
            });
        }
Esempio n. 3
0
        public void UnboundParameterException_Simple()
        {
            var e  = Expression.Constant(42);
            var p  = new[] { Expression.Parameter(typeof(int)) };
            var ex = new UnboundParameterException("Oops", e, p);

            Assert.IsTrue(ex.Message.StartsWith("Oops"));
            Assert.AreSame(e, ex.Expression);
            Assert.IsTrue(p.SequenceEqual(ex.Parameters));
        }
Esempio n. 4
0
        public void UnboundParameterException_Serialize()
        {
            var ex = new UnboundParameterException("Oops", Expression.Constant(42), new[] { Expression.Parameter(typeof(int)) });

            var ms = new MemoryStream();

            new BinaryFormatter().Serialize(ms, ex);
            ms.Position = 0;

            var err = (UnboundParameterException) new BinaryFormatter().Deserialize(ms);

            Assert.IsNotNull(err);
            Assert.AreEqual(ex.Message, err.Message);
        }
Esempio n. 5
0
 public void UnboundParameterException_ArgumentChecking()
 {
     AssertEx.ThrowsException <ArgumentNullException>(() => new UnboundParameterException("", expression: null, Array.Empty <ParameterExpression>()), ex => Assert.AreEqual("expression", ex.ParamName));
     AssertEx.ThrowsException <ArgumentNullException>(() => new UnboundParameterException("", Expression.Constant(42), parameters: null), ex => Assert.AreEqual("parameters", ex.ParamName));
     AssertEx.ThrowsException <ArgumentNullException>(() => UnboundParameterException.ThrowIfOpen(expression: null, ""), ex => Assert.AreEqual("expression", ex.ParamName));
 }
Esempio n. 6
0
 private static void CheckOpenParameters(Expression expression)
 {
     UnboundParameterException.ThrowIfOpen(expression, "The specified expression contains unbound parameters and cannot be funcletized or evaluated.");
 }