public void TestBoolDelegateMultipleDelegates()
        {
            CVar cvarBool = new CVar("bool", false);

            cvarBool.AddDelegate(delegate(CVar cvar)
            {
                m_result.Add("delegate1 " + cvar.BoolValue);
            });
            cvarBool.AddDelegate(delegate(CVar cvar)
            {
                m_result.Add("delegate2 " + cvar.BoolValue);
            });
            cvarBool.AddDelegate(delegate(CVar cvar)
            {
                m_result.Add("delegate3 " + cvar.BoolValue);
            });

            Execute("bool 0");
            AssertList(m_result);

            Execute("bool 1");
            AssertList(m_result,
                       "delegate1 True",
                       "delegate2 True",
                       "delegate3 True"
                       );
        }
        public void TestBoolDelegateRemoveAllDelegatesInLoop()
        {
            CVarChangedDelegate del1 = delegate(CVar cvar)
            {
                m_result.Add("delegate1 " + cvar.BoolValue);
            };

            CVarChangedDelegate del2 = delegate(CVar cvar)
            {
                m_result.Add("delegate2 " + cvar.BoolValue);
            };
            CVarChangedDelegate del3 = delegate(CVar cvar)
            {
                m_result.Add("delegate3 " + cvar.BoolValue);
                cvar.RemoveDelegates(del1.Target);
            };

            CVar cvarBool = new CVar("bool", false);

            cvarBool.AddDelegate(del3);
            cvarBool.AddDelegate(del2);
            cvarBool.AddDelegate(del1);

            Execute("bool 1");
            AssertList(m_result,
                       "delegate3 True"
                       );
            m_result.Clear();
        }
        public void TestBoolDelegateRemoveMultipleDelegates()
        {
            CVarChangedDelegate del1 = delegate(CVar cvar)
            {
                m_result.Add("delegate1 " + cvar.BoolValue);
            };
            CVarChangedDelegate del2 = delegate(CVar cvar)
            {
                m_result.Add("delegate2 " + cvar.BoolValue);
            };
            CVarChangedDelegate del3 = delegate(CVar cvar)
            {
                m_result.Add("delegate3 " + cvar.BoolValue);
            };

            CVar cvarBool = new CVar("bool", false);

            cvarBool.AddDelegate(del1);
            cvarBool.AddDelegate(del2);
            cvarBool.AddDelegate(del3);

            Execute("bool 0");
            AssertList(m_result);
            m_result.Clear();

            Execute("bool 1");
            AssertList(m_result,
                       "delegate1 True",
                       "delegate2 True",
                       "delegate3 True"
                       );
            m_result.Clear();

            cvarBool.RemoveDelegate(del3);
            Execute("bool 0");
            AssertList(m_result,
                       "delegate1 False",
                       "delegate2 False"
                       );
            m_result.Clear();

            cvarBool.RemoveDelegate(del2);
            Execute("bool 1");
            AssertList(m_result,
                       "delegate1 True"
                       );
            m_result.Clear();

            cvarBool.RemoveDelegate(del1);
            Execute("bool 0");
            AssertList(m_result);
        }
        public void TestBoolDefaultDelegate()
        {
            CVar cvarBool = new CVar("bool", false);

            Execute("bool 1");

            cvarBool.AddDelegate(delegate(CVar cvar)
            {
                m_result.Add(cvar.Name + " " + cvar.BoolValue);
            });

            Execute("reset bool");
            AssertList(m_result, "bool False");
        }
        public void TestStringDefaultDelegate()
        {
            CVar cvarString = new CVar("string", "This is string");

            Execute("string \"This another string\"");

            cvarString.AddDelegate(delegate(CVar cvar)
            {
                m_result.Add(cvar.Name + " \"" + cvar.Value + "\"");
            });

            Execute("reset string");
            AssertList(m_result, "string \"This is string\"");
        }
        public void TestFloatDefaultDelegate()
        {
            CVar cvarFloat = new CVar("float", 3.14f);

            Execute("float -3.14");

            cvarFloat.AddDelegate(delegate(CVar cvar)
            {
                m_result.Add(cvar.Name + " " + cvar.FloatValue);
            });

            Execute("reset float");
            AssertList(m_result, "float 3.14");
        }
        public void TestIntDefaultDelegate()
        {
            CVar cvarInt = new CVar("int", 10);

            Execute("int 20");

            cvarInt.AddDelegate(delegate(CVar cvar)
            {
                m_result.Add(cvar.Name + " " + cvar.IntValue);
            });

            Execute("reset int");
            AssertList(m_result, "int 10");
        }
        public void TestDelegates()
        {
            bool delegateCalled = false;

            CVar cvar = new CVar("var", "Default value");
            cvar.AddDelegate(delegate(CVar v)
            {
                delegateCalled = true;
            });

            Execute("bind v 'var value'");

            TapKeys(KeyCode.V);
            Assert.IsTrue(delegateCalled);
        }
Exemple #9
0
        public void TestDelegates()
        {
            bool delegateCalled = false;

            CVar cvar = new CVar("var", "Default value");

            cvar.AddDelegate(delegate(CVar v)
            {
                delegateCalled = true;
            });

            Execute("bind v 'var value'");

            TapKeys(KeyCode.V);
            Assert.IsTrue(delegateCalled);
        }
Exemple #10
0
    public void TestDelegate()
    {
        CVar boolVar = new CVar("bool", true);

        boolVar.AddDelegate(delegate(CVar cvar)
        {
            AddResult("bool " + (bool)cvar);
        });

        CVar intVar = new CVar("int", 10);

        intVar.AddDelegate(delegate(CVar cvar)
        {
            AddResult("int " + (int)cvar);
        });

        CVar floatVar = new CVar("float", 3.14f);

        floatVar.AddDelegate(delegate(CVar cvar)
        {
            AddResult("float " + (float)cvar);
        });

        CVar stringVar = new CVar("string", "value");

        stringVar.AddDelegate(delegate(CVar cvar)
        {
            AddResult("string " + (string)cvar);
        });

        boolVar.BoolValue = false;
        AssertResult("bool False");

        boolVar.BoolValue = true;
        AssertResult("bool True");

        intVar.IntValue = 20;
        AssertResult("int 20");

        floatVar.FloatValue = 6.28f;
        AssertResult("float 6.28");

        stringVar.Value = "new value";
        AssertResult("string new value");
    }
Exemple #11
0
        public void TestDelegatesOperationCommand()
        {
            string delegateValue = null;

            CVar cvar = new CVar("var", false);

            cvar.AddDelegate(delegate(CVar v)
            {
                delegateValue = v.BoolValue.ToString();
            });

            Execute("bind v +var");

            PressKeys(KeyCode.V);
            Assert.AreEqual("True", delegateValue);

            ReleaseKeys(KeyCode.V);
            Assert.AreEqual("False", delegateValue);
        }
        public void TestDelegatesOperationCommand()
        {
            string delegateValue = null;

            CVar cvar = new CVar("var", false);
            cvar.AddDelegate(delegate(CVar v)
            {
                delegateValue = v.BoolValue.ToString();
            });

            Execute("bind v +var");

            PressKeys(KeyCode.V);
            Assert.AreEqual("True", delegateValue);

            ReleaseKeys(KeyCode.V);
            Assert.AreEqual("False", delegateValue);
        }