Ejemplo n.º 1
0
        public IEnumerator Match()
        {
            GameObject             objectOne      = new GameObject();
            GameObject             objectTwo      = new GameObject();
            UnityEventListenerMock ruleOneMatched = new UnityEventListenerMock();
            UnityEventListenerMock ruleTwoMatched = new UnityEventListenerMock();

            RulesMatcher.Element elementOne = new RulesMatcher.Element()
            {
                Rule = CreateRule(objectOne)
            };
            RulesMatcher.Element elementTwo = new RulesMatcher.Element()
            {
                Rule = CreateRule(objectTwo)
            };

            elementOne.Matched.AddListener(ruleOneMatched.Listen);
            elementTwo.Matched.AddListener(ruleTwoMatched.Listen);

            RulesMatcherElementObservableList elements = containingObject.AddComponent <RulesMatcherElementObservableList>();

            yield return(null);

            subject.Elements = elements;

            elements.Add(elementOne);
            elements.Add(elementTwo);

            Assert.IsFalse(ruleOneMatched.Received);
            Assert.IsFalse(ruleTwoMatched.Received);

            subject.Match(objectOne);

            Assert.IsTrue(ruleOneMatched.Received);
            Assert.IsFalse(ruleTwoMatched.Received);

            ruleOneMatched.Reset();
            ruleTwoMatched.Reset();

            subject.Match(objectTwo);

            Assert.IsFalse(ruleOneMatched.Received);
            Assert.IsTrue(ruleTwoMatched.Received);

            Object.DestroyImmediate(objectOne);
            Object.DestroyImmediate(objectTwo);
        }
Ejemplo n.º 2
0
        public void Match()
        {
            GameObject             objectOne      = new GameObject();
            GameObject             objectTwo      = new GameObject();
            UnityEventListenerMock ruleOneMatched = new UnityEventListenerMock();
            UnityEventListenerMock ruleTwoMatched = new UnityEventListenerMock();

            RulesMatcher.Element elementOne = new RulesMatcher.Element()
            {
                rule = CreateRule(objectOne)
            };
            RulesMatcher.Element elementTwo = new RulesMatcher.Element()
            {
                rule = CreateRule(objectTwo)
            };

            elementOne.Matched.AddListener(ruleOneMatched.Listen);
            elementTwo.Matched.AddListener(ruleTwoMatched.Listen);

            subject.elements.Add(elementOne);
            subject.elements.Add(elementTwo);

            Assert.IsFalse(ruleOneMatched.Received);
            Assert.IsFalse(ruleTwoMatched.Received);

            subject.Match(objectOne);

            Assert.IsTrue(ruleOneMatched.Received);
            Assert.IsFalse(ruleTwoMatched.Received);

            ruleOneMatched.Reset();
            ruleTwoMatched.Reset();

            subject.Match(objectTwo);

            Assert.IsFalse(ruleOneMatched.Received);
            Assert.IsTrue(ruleTwoMatched.Received);

            Object.DestroyImmediate(objectOne);
            Object.DestroyImmediate(objectTwo);
        }