Beispiel #1
0
        private static Condition MakeCondition(Stack <Condition> conds, Stack <int> ops)
        {
            int       op    = ops.Pop();
            Condition right = conds.Pop();
            Condition left  = conds.Pop();

            if (op >= 0)
            {
                FakeCondition l = (FakeCondition)left;
                FakeCondition r = (FakeCondition)right;
                return(new SimpleCondition(l.Value, r.Value, (Relation)op));
            }
            if (left is FakeCondition)
            {
                throw new Exception("Invalid condition type");
            }
            if (right is FakeCondition)
            {
                throw new Exception("Invalid condition type");
            }
            if (op == -1)
            {
                return(new AndCondition(left, right));
            }
            if (op == -2)
            {
                return(new OrCondition(left, right));
            }
            throw new Exception("Invalid opeation priority " + op);
        }
        public static void History()
        {
            var fake = new Fake {
                IsTrueOrNull = false
            };

            using var condition = new FakeCondition(fake);
            CollectionAssert.AreEqual(new bool?[] { false }, condition.History.Select(x => x.State));

            fake.IsTrueOrNull = true;
            CollectionAssert.AreEqual(new bool?[] { false, true }, condition.History.Select(x => x.State));

            fake.IsTrueOrNull = null;
            CollectionAssert.AreEqual(new bool?[] { false, true, null }, condition.History.Select(x => x.State));
        }
        public static void IsSatisfied()
        {
            var fake = new Fake {
                IsTrueOrNull = false
            };

            using var condition = new FakeCondition(fake);
            Assert.AreEqual(false, condition.IsSatisfied);

            fake.IsTrueOrNull = true;
            Assert.AreEqual(true, condition.IsSatisfied);

            fake.IsTrueOrNull = null;
            Assert.AreEqual(null, condition.IsSatisfied);

            fake.IsTrueOrNull = false;
            Assert.AreEqual(false, condition.IsSatisfied);
        }
        public static void Notifies()
        {
            var fake = new Fake {
                IsTrueOrNull = false
            };

            using var condition = new FakeCondition(fake);
            var argses = new List <PropertyChangedEventArgs>();

            condition.PropertyChanged += (sender, args) => argses.Add(args);

            fake.IsTrueOrNull = true;
            Assert.AreEqual(1, argses.Count);

            fake.IsTrueOrNull = false;
            Assert.AreEqual(2, argses.Count);

            fake.IsTrueOrNull = null;
            Assert.AreEqual(3, argses.Count);
        }
        public void HistoryNegated()
        {
            var fake = new Fake {
                IsTrueOrNull = false
            };

            using (var condition = new FakeCondition(fake))
            {
                using (var negated = condition.Negate())
                {
                    CollectionAssert.AreEqual(new bool?[] { false }, condition.History.Select(x => x.State));
                    CollectionAssert.AreEqual(new bool?[] { true }, negated.History.Select(x => x.State));

                    fake.IsTrueOrNull = true;
                    CollectionAssert.AreEqual(new bool?[] { false, true }, condition.History.Select(x => x.State));
                    CollectionAssert.AreEqual(new bool?[] { true, false }, negated.History.Select(x => x.State));

                    fake.IsTrueOrNull = null;
                    CollectionAssert.AreEqual(new bool?[] { false, true, null }, condition.History.Select(x => x.State));
                    CollectionAssert.AreEqual(new bool?[] { true, false, null }, negated.History.Select(x => x.State));
                }
            }
        }