Beispiel #1
0
        /// <summary>
        ///   Carry out an action on any following or "inner" BehaviorNodes
        ///   meeting a given criteria.
        /// </summary>
        /// <param name = "search"></param>
        public void ForFollowingBehavior(BehaviorSearch search)
        {
            var follower = this.FirstOrDefault(search.Matching);

            if (follower != null)
            {
                search.OnFound(follower);
            }
            else
            {
                search.OnMissing();
            }
        }
        public void find_the_follower_positive()
        {
            var found = MockRepository.GenerateMock<Action<BehaviorNode>>();
            var missing = MockRepository.GenerateMock<Action>();
            var search = new BehaviorSearch(n => ReferenceEquals(n, node3)){
                OnFound = found,
                OnMissing = missing
            };

            node1.ForFollowingBehavior(search);

            found.AssertWasCalled(x => x.Invoke(node3));
            missing.AssertWasNotCalled(x => x.Invoke());
        }
        public void find_the_follower_negative()
        {
            var found = MockRepository.GenerateMock<Action<BehaviorNode>>();
            var missing = MockRepository.GenerateMock<Action>();
            var search = new BehaviorSearch(n => false)
            {
                OnFound = found,
                OnMissing = missing
            };

            node1.ForFollowingBehavior(search);

            found.AssertWasNotCalled(x => x.Invoke(null), x => x.IgnoreArguments());
            missing.AssertWasCalled(x => x.Invoke());
        }