Exemplo n.º 1
0
        public void Creating_a_new_allowedstate_object_with_no_actions_should_correctly_set_properties()
        {
            var expectedName = "Test";
            var state        = new AllowedState(expectedName);

            Assert.AreEqual(expectedName, state.Name);
            Assert.IsNotNull(state.AllowedActions);
            Assert.AreEqual(0, state.AllowedActions.Count);
        }
Exemplo n.º 2
0
    public void Initialize()
    {
        StateController.AddPieka(this);


        System.Attribute[] att = (System.Attribute[])GetType().GetCustomAttributes(true);


        foreach (System.Attribute attribute in att)
        {
            if (attribute is AllowedState)
            {
                AllowedState allowedState = (AllowedState)attribute;
                isInActiveState = false;
                allowedStates.Add(allowedState.Name);
            }
        }

        MethodInfo[] methods = GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);

        foreach (MethodInfo m in methods)
        {
            System.Attribute[] attributes = (System.Attribute[])m.GetCustomAttributes(true);


            foreach (System.Attribute attribute in attributes)
            {
                if (attribute is OnEvent)
                {
                    OnEvent onEventMethod = (OnEvent)attribute;



                    if (m.GetParameters().Length == 2)
                    {
                        PMEvent del = (PMEvent)Delegate.CreateDelegate(typeof(PMEvent), this, m);
                        events.Add(new PairEventString(onEventMethod.Name, del));
                    }
                    else
                    {
                        PMEventLite del = (PMEventLite)Delegate.CreateDelegate(typeof(PMEventLite), this, m);
                        eventsLite.Add(new PairEventLiteString(onEventMethod.Name, del));
                    }



                    //	SEventSystem.Register ( onEventMethod.Name, (PMEvent)PMEvent.CreateDelegate( typeof(PMEvent), m ) );
                }
            }
        }
        RegisterAll();
        OnStateChange(StateController.GetActiveState());
    }
Exemplo n.º 3
0
        public void Creating_a_new_allowedstate_object_with_string_actions_should_correctly_set_properties()
        {
            var expectedName   = "Test";
            var expectedAction = "TestAction";

            var state = new AllowedState(expectedName, expectedAction);

            Assert.AreEqual(expectedName, state.Name);
            Assert.IsNotNull(state.AllowedActions);
            Assert.AreEqual(1, state.AllowedActions.Count);
            Assert.IsTrue(state.AllowedActions.ContainsKey(expectedAction));
            Assert.IsNull(state.AllowedActions[expectedAction]);
        }
Exemplo n.º 4
0
        public void Creating_a_new_allowedstate_object_with_a_list_of_action_objects_should_correctly_set_properties()
        {
            var expectedName   = "Test";
            var expectedAction = new TestAction();

            var state = new AllowedState(expectedName, new List <IAllowedAction> {
                expectedAction
            });

            Assert.AreEqual(expectedName, state.Name);
            Assert.IsNotNull(state.AllowedActions);
            Assert.AreEqual(1, state.AllowedActions.Count);
            Assert.IsTrue(state.AllowedActions.ContainsKey(expectedAction.Name));
            Assert.IsNotNull(state.AllowedActions[expectedAction.Name]);
        }