예제 #1
0
        public void when_first_child_is_running_second_child_is_supressed()
        {
            Init();

            var time = new MyTimeData();

            var mockChild1 = new Mock <IMyBehaviourTreeNode>();

            mockChild1
            .Setup(m => m.Tick(time))
            .Returns(MyBehaviourTreeStatus.Running);

            var mockChild2 = new Mock <IMyBehaviourTreeNode>();

            testObject.AddChild(mockChild1.Object);
            testObject.AddChild(mockChild2.Object);

            Assert.Equal(MyBehaviourTreeStatus.Running, testObject.Tick(time));

            mockChild1.Verify(m => m.Tick(time), Times.Once());
            mockChild2.Verify(m => m.Tick(time), Times.Never());
        }
        public void runs_the_first_node_if_it_succeeds()
        {
            Init();

            var time = new MyTimeData();

            var mockChild1 = new Mock <IMyBehaviourTreeNode>();

            mockChild1
            .Setup(m => m.Tick(time))
            .Returns(MyBehaviourTreeStatus.Success);

            var mockChild2 = new Mock <IMyBehaviourTreeNode>();

            testObject.AddChild(mockChild1.Object);
            testObject.AddChild(mockChild2.Object);

            Assert.Equal(MyBehaviourTreeStatus.Success, testObject.Tick(time));

            mockChild1.Verify(m => m.Tick(time), Times.Once());
            mockChild2.Verify(m => m.Tick(time), Times.Never());
        }
        public void can_run_all_children_in_order()
        {
            Init();

            var time = new MyTimeData();

            var callOrder = 0;

            var mockChild1 = new Mock <IMyBehaviourTreeNode>();

            mockChild1
            .Setup(m => m.Tick(time))
            .Returns(MyBehaviourTreeStatus.Success)
            .Callback(() =>
            {
                Assert.Equal(1, ++callOrder);
            });

            var mockChild2 = new Mock <IMyBehaviourTreeNode>();

            mockChild2
            .Setup(m => m.Tick(time))
            .Returns(MyBehaviourTreeStatus.Success)
            .Callback(() =>
            {
                Assert.Equal(2, ++callOrder);
            });

            testObject.AddChild(mockChild1.Object);
            testObject.AddChild(mockChild2.Object);

            Assert.Equal(MyBehaviourTreeStatus.Success, testObject.Tick(time));

            Assert.Equal(2, callOrder);

            mockChild1.Verify(m => m.Tick(time), Times.Once());
            mockChild2.Verify(m => m.Tick(time), Times.Once());
        }
    public void DeSerialize(Dictionary <string, object> dic)
    {
        if (dic == null)
        {
            Debug.LogError("OriginalProjectData dic.DeSerialize(dic), dic = null");
            return;
        }
        data    = new OriginalInputData();
        version = new MyTimeData();
        foreach (string key in dic.Keys)
        {
            switch (key)
            {
            case "id":
                id = MyJsonTool.getStringValue(dic, key);
                break;

            case "meta":
                meta = MyJsonTool.getStringValue(dic, key);
                break;

            case "data":
            {
                object obj = MyJsonTool.getValue(dic, key);
                data.isOld = false;
                if (dic.ContainsKey("version") == false)
                {
                    data.isOld = true;
                }
                data.DeSerialize(obj as Dictionary <string, object>);
            }
            break;

            case "name":
                name = MyJsonTool.getStringValue(dic, key);
                break;

            case "description":
                description = MyJsonTool.getStringValue(dic, key);
                break;

            case "priceIdList":
                priceIdList = MyJsonTool.getStringListValue(dic, key);
                break;

            case "tempId":
                tempId = MyJsonTool.getIntValue(dic, key);
                break;

            case "idNew":
                isNew = MyJsonTool.getBoolValue(dic, key);
                //isNew = false;
                break;

            case "version":
            {
                object obj = MyJsonTool.getValue(dic, key);
                version.DeSerialize(obj as Dictionary <string, object>);
                //isNew = false;
            }
            break;

            default:
                break;
            }
        }
    }
 public OriginalProjectData()
 {
     version = new MyTimeData(DateTime.Now);
 }