Exemple #1
0
        public void StringConversion()
        {
            var emily = TestPerson.CreateEmily();

            emily.Name = "X";
            using (var expr = ActiveExpression.Create(p1 => p1.Name.Length + 1, emily))
                Assert.AreEqual("({C} /* {X} */.Name /* \"X\" */.Length /* 1 */ + {C} /* 1 */) /* 2 */", expr.ToString());
        }
        public void StringConversion()
        {
            var john  = TestPerson.CreateJohn();
            var emily = TestPerson.CreateEmily();

            using (var expr = ActiveExpression.Create((p1, p2) => CombinePeople(p1, p2), john, emily))
                Assert.AreEqual($"{{C}} /* {this} */.CombinePeople({{C}} /* {john} */, {{C}} /* {emily} */) /* {expr.Value} */", expr.ToString());
        }
Exemple #3
0
        public void ValueShortCircuiting()
        {
            var john  = TestPerson.CreateJohn();
            var emily = TestPerson.CreateEmily();

            using (var expr = ActiveExpression.Create((p1, p2) => p1.Name.Length > 1 || p2.Name.Length > 3, john, emily))
                Assert.IsTrue(expr.Value);
            Assert.AreEqual(0, emily.NameGets);
        }
Exemple #4
0
        public void ThreeArgumentStringConversion()
        {
            var john    = TestPerson.CreateJohn();
            var emily   = TestPerson.CreateEmily();
            var charles = new TestPerson("Charles");

            using (var expr = ActiveExpression.Create((a, b, c) => a + b + c, john, emily, charles))
                Assert.AreEqual("(({C} /* {John} */ + {C} /* {Emily} */) /* {John Emily} */ + {C} /* {Charles} */) /* {John Emily Charles} */", expr.ToString());
        }
        public void StringConversion()
        {
            var john = TestPerson.CreateJohn();

            john.Name = "X";
            var emily = TestPerson.CreateEmily();

            emily.Name = "Y";
            using (var expr = ActiveExpression.Create((p1, p2) => p1.Name == null ? p1 : p2, john, emily))
                Assert.AreEqual($"(({{C}} /* {john} */.Name /* \"X\" */ == {{C}} /* null */) /* False */ ? {{C}} /* {john} */ : {{C}} /* {emily} */) /* {emily} */", expr.ToString());
        }
Exemple #6
0
        public void StringConversion()
        {
            var emily = TestPerson.CreateEmily();

            emily.Name = "X";
            var people = new ObservableCollection <TestPerson> {
                emily
            };

            using (var expr = ActiveExpression.Create(p1 => p1[0].Name.Length + 1, people))
                Assert.AreEqual($"({{C}} /* {people} */[{{C}} /* 0 */] /* {{X}} */.Name /* \"X\" */.Length /* 1 */ + {{C}} /* 1 */) /* 2 */", expr.ToString());
        }
        public void ConsistentHashCode()
        {
            int hashCode1, hashCode2;
            var john  = TestPerson.CreateJohn();
            var emily = TestPerson.CreateEmily();

            using (var expr = ActiveExpression.Create((p1, p2) => CombinePeople(p1, p2), john, emily))
                hashCode1 = expr.GetHashCode();
            using (var expr = ActiveExpression.Create((p1, p2) => CombinePeople(p1, p2), john, emily))
                hashCode2 = expr.GetHashCode();
            Assert.IsTrue(hashCode1 == hashCode2);
        }
        public void ConsistentHashCode()
        {
            int hashCode1, hashCode2;
            var john  = TestPerson.CreateJohn();
            var emily = TestPerson.CreateEmily();

            using (var expr = ActiveExpression.Create((p1, p2) => p1.Name.Length > 0 ? p1.Name : p2.Name, john, emily))
                hashCode1 = expr.GetHashCode();
            using (var expr = ActiveExpression.Create((p1, p2) => p1.Name.Length > 0 ? p1.Name : p2.Name, john, emily))
                hashCode2 = expr.GetHashCode();
            Assert.IsTrue(hashCode1 == hashCode2);
        }
        public void ActuallyAProperty()
        {
            var emily = TestPerson.CreateEmily();

            using (var expr = ActiveExpression.Create(Expression.Lambda <Func <string> >(Expression.Call(Expression.Constant(emily), typeof(TestPerson).GetRuntimeProperty(nameof(TestPerson.Name)).GetMethod))))
            {
                Assert.IsNull(expr.Fault);
                Assert.AreEqual("Emily", expr.Value);
                emily.Name = "E";
                Assert.IsNull(expr.Fault);
                Assert.AreEqual("E", expr.Value);
            }
        }
Exemple #10
0
        public void ManualCreation()
        {
            var people = new List <TestPerson>()
            {
                TestPerson.CreateEmily()
            };

            using (var expr = ActiveExpression.Create(Expression.Lambda <Func <string> >(Expression.MakeMemberAccess(Expression.MakeIndex(Expression.Constant(people), typeof(List <TestPerson>).GetRuntimeProperties().First(p => p.GetIndexParameters().Length > 0), new Expression[] { Expression.Constant(0) }), typeof(TestPerson).GetRuntimeProperty(nameof(TestPerson.Name))))))
            {
                Assert.IsNull(expr.Fault);
                Assert.AreEqual("Emily", expr.Value);
            }
        }
        public void FaultPropagationTest()
        {
            var john = TestPerson.CreateJohn();

            john.Name = null;
            var emily = TestPerson.CreateEmily();

            using (var expr = ActiveExpression.Create((p1, p2) => p1.Name.Length > 0 ? p1.Name : p2.Name, john, emily))
            {
                Assert.IsNotNull(expr.Fault);
                john.Name = "John";
                Assert.IsNull(expr.Fault);
            }
        }
        public void ArgumentFaultPropagation()
        {
            var john  = TestPerson.CreateJohn();
            var emily = TestPerson.CreateEmily();

            using (var expr = ActiveExpression.Create(() => CombinePeople(john.Name.Length > 3 ? john : null, emily)))
            {
                Assert.IsNull(expr.Fault);
                john.Name = null;
                Assert.IsNotNull(expr.Fault);
                john.Name = "John";
                Assert.IsNull(expr.Fault);
            }
        }
        public void Equals()
        {
            var john  = TestPerson.CreateJohn();
            var emily = TestPerson.CreateEmily();

            using (var expr1 = ActiveExpression.Create((p1, p2) => CombinePeople(p1, p2), john, emily))
                using (var expr2 = ActiveExpression.Create((p1, p2) => CombinePeople(p1, p2), john, emily))
                    using (var expr3 = ActiveExpression.Create((p1, p2) => ReversedCombinePeople(p1, p2), john, emily))
                        using (var expr4 = ActiveExpression.Create((p1, p2) => CombinePeople(p1, p2), emily, john))
                        {
                            Assert.IsTrue(expr1.Equals(expr2));
                            Assert.IsFalse(expr1.Equals(expr3));
                            Assert.IsFalse(expr1.Equals(expr4));
                        }
        }
Exemple #14
0
        public void FaultPropagation()
        {
            var john  = TestPerson.CreateJohn();
            var emily = TestPerson.CreateEmily();

            using (var expr = ActiveExpression.Create((p1, p2) => p1.Name.ToString() ?? p2.Name.ToString(), john, emily))
            {
                Assert.IsNull(expr.Fault);
                john.Name = null;
                Assert.IsNotNull(expr.Fault);
                emily.Name = null;
                john.Name  = "John";
                Assert.IsNull(expr.Fault);
            }
        }
Exemple #15
0
        public void Equals()
        {
            var john  = TestPerson.CreateJohn();
            var emily = TestPerson.CreateEmily();

            using (var expr1 = ActiveExpression.Create(p1 => p1.Name != null || p1.Name.Length > 0, john))
                using (var expr2 = ActiveExpression.Create(p1 => p1.Name != null || p1.Name.Length > 0, john))
                    using (var expr3 = ActiveExpression.Create(p1 => p1.Name == null && p1.Name.Length == 0, john))
                        using (var expr4 = ActiveExpression.Create(p1 => p1.Name != null || p1.Name.Length > 0, emily))
                        {
                            Assert.IsTrue(expr1.Equals(expr2));
                            Assert.IsFalse(expr1.Equals(expr3));
                            Assert.IsFalse(expr1.Equals(expr4));
                        }
        }
        public void Equals()
        {
            var john  = TestPerson.CreateJohn();
            var emily = TestPerson.CreateEmily();

            using (var expr1 = ActiveExpression.Create((p1, p2) => p1.Name.Length > 0 ? p1.Name : p2.Name, john, emily))
                using (var expr2 = ActiveExpression.Create((p1, p2) => p1.Name.Length > 0 ? p1.Name : p2.Name, john, emily))
                    using (var expr3 = ActiveExpression.Create((p1, p2) => p2.Name.Length > 0 ? p2.Name : p1.Name, john, emily))
                        using (var expr4 = ActiveExpression.Create((p1, p2) => p1.Name.Length > 0 ? p1.Name : p2.Name, emily, john))
                        {
                            Assert.IsTrue(expr1.Equals(expr2));
                            Assert.IsFalse(expr1.Equals(expr3));
                            Assert.IsFalse(expr1.Equals(expr4));
                        }
        }
Exemple #17
0
        public void Equals()
        {
            var john  = TestPerson.CreateJohn();
            var emily = TestPerson.CreateEmily();

            using (var expr1 = ActiveExpression.Create(p1 => p1.Name ?? string.Empty, john))
                using (var expr2 = ActiveExpression.Create(p1 => p1.Name ?? string.Empty, john))
                    using (var expr3 = ActiveExpression.Create(p1 => p1.Name ?? "Another String", john))
                        using (var expr4 = ActiveExpression.Create(p1 => p1.Name ?? string.Empty, emily))
                        {
                            Assert.IsTrue(expr1.Equals(expr2));
                            Assert.IsFalse(expr1.Equals(expr3));
                            Assert.IsFalse(expr1.Equals(expr4));
                        }
        }
Exemple #18
0
        public void Inequality()
        {
            var john  = TestPerson.CreateJohn();
            var emily = TestPerson.CreateEmily();

            using (var expr1 = ActiveExpression.Create(p1 => p1.Name.Length + 2, john))
                using (var expr2 = ActiveExpression.Create(p1 => p1.Name.Length + 2, john))
                    using (var expr3 = ActiveExpression.Create(p1 => p1.Name.Length - 2, john))
                        using (var expr4 = ActiveExpression.Create(p1 => p1.Name.Length + 2, emily))
                        {
                            Assert.IsFalse(expr1 != expr2);
                            Assert.IsTrue(expr1 != expr3);
                            Assert.IsTrue(expr1 != expr4);
                        }
        }
Exemple #19
0
        public void ThreeArgumentInequality()
        {
            var john    = TestPerson.CreateJohn();
            var emily   = TestPerson.CreateEmily();
            var charles = new TestPerson("Charles");

            using (var expr1 = ActiveExpression.Create((a, b, c) => a + b + c, john, emily, charles))
                using (var expr2 = ActiveExpression.Create((a, b, c) => a + b + c, john, emily, charles))
                    using (var expr3 = ActiveExpression.Create((a, b, c) => a + c + b, john, emily, charles))
                        using (var expr4 = ActiveExpression.Create((a, b, c) => a + b + c, charles, emily, john))
                        {
                            Assert.IsFalse(expr1 != expr2);
                            Assert.IsTrue(expr1 != expr3);
                            Assert.IsTrue(expr1 != expr4);
                        }
        }
Exemple #20
0
        public void FaultPropagation()
        {
            var john  = TestPerson.CreateJohn();
            var emily = TestPerson.CreateEmily();

            using (var expr = ActiveExpression.Create((p1, p2) => p1.Name.Length > 0 || p2.Name.Length > 0, john, emily))
            {
                Assert.IsNull(expr.Fault);
                john.Name = null;
                Assert.IsNotNull(expr.Fault);
                emily.Name = null;
                john.Name  = string.Empty;
                Assert.IsNotNull(expr.Fault);
                emily.Name = "Emily";
                Assert.IsNull(expr.Fault);
            }
        }
Exemple #21
0
        public void ObjectChanges()
        {
            var john = TestPerson.CreateJohn();
            var men  = new ObservableCollection <TestPerson> {
                john
            };
            var emily = TestPerson.CreateEmily();
            var women = new ObservableCollection <TestPerson> {
                emily
            };

            using (var expr = ActiveExpression.Create((p1, p2) => (p1.Count > 0 ? p1 : p2)[0], men, women))
            {
                Assert.AreSame(john, expr.Value);
                men.Clear();
                Assert.AreSame(emily, expr.Value);
            }
        }
Exemple #22
0
        public void PropertyChanges()
        {
            var john   = TestPerson.CreateJohn();
            var emily  = TestPerson.CreateEmily();
            var values = new BlockingCollection <int>();

            using (var expr = ActiveExpression.Create((p1, p2) => p1.Name.Length + p2.Name.Length, john, emily))
            {
                var disconnect = expr.OnPropertyChanged(ae => ae.Value, value => values.Add(value));
                values.Add(expr.Value);
                john.Name  = "J";
                emily.Name = "E";
                john.Name  = "John";
                john.Name  = "J";
                emily.Name = "Emily";
                emily.Name = "E";
                disconnect();
            }
            Assert.IsTrue(new int[] { 9, 6, 2, 5, 2, 6, 2 }.SequenceEqual(values));
        }
Exemple #23
0
        public void Inequality()
        {
            var john = TestPerson.CreateJohn();
            var men  = new List <TestPerson> {
                john, null
            };
            var emily = TestPerson.CreateEmily();
            var women = new List <TestPerson> {
                emily, null
            };

            using (var expr1 = ActiveExpression.Create(p1 => p1[0], men))
                using (var expr2 = ActiveExpression.Create(p1 => p1[0], men))
                    using (var expr3 = ActiveExpression.Create(p1 => p1[1], men))
                        using (var expr4 = ActiveExpression.Create(p1 => p1[0], women))
                        {
                            Assert.IsFalse(expr1 != expr2);
                            Assert.IsTrue(expr1 != expr3);
                            Assert.IsTrue(expr1 != expr4);
                        }
        }
        public void PropertyChanges()
        {
            var john   = TestPerson.CreateJohn();
            var emily  = TestPerson.CreateEmily();
            var values = new BlockingCollection <string>();

            using (var expr = ActiveExpression.Create((p1, p2) => string.IsNullOrEmpty(p1.Name) ? p2.Name : p1.Name, john, emily))
            {
                var disconnect = expr.OnPropertyChanged(ae => ae.Value, value => values.Add(value));
                values.Add(expr.Value);
                john.Name  = "J";
                john.Name  = "John";
                john.Name  = null;
                emily.Name = "E";
                emily.Name = "Emily";
                emily.Name = null;
                emily.Name = "Emily";
                john.Name  = "John";
                disconnect();
            }
            Assert.IsTrue(new string[] { "John", "J", "John", "Emily", "E", "Emily", null, "Emily", "John" }.SequenceEqual(values));
        }
Exemple #25
0
        public void ThreeArgumentValueChanges()
        {
            var john    = TestPerson.CreateJohn();
            var emily   = TestPerson.CreateEmily();
            var charles = new TestPerson("Charles");
            var values  = new BlockingCollection <string>();

            using (var expr = ActiveExpression.Create((a, b, c) => $"{a.Name} {b.Name} {c.Name}", john, emily, charles))
            {
                var disconnect = expr.OnPropertyChanged(ae => ae.Value, value => values.Add(value));
                values.Add(expr.Value);
                john.Name    = "J";
                emily.Name   = "E";
                charles.Name = "C";
                disconnect();
            }
            Assert.IsTrue(new string[]
            {
                "John Emily Charles",
                "J Emily Charles",
                "J E Charles",
                "J E C"
            }.SequenceEqual(values));
        }