Exemplo n.º 1
0
        public void SumTestMethod()
        {
            DelegateExample _newInstance = new DelegateExample();

            _newInstance.PerformCalculationVar = _newInstance.PerformSumMethod;
            Assert.AreEqual <int>(_newInstance.PerformSumMethod(0, int.MaxValue), _newInstance.PerformCalculationVar(0, int.MaxValue));
            Assert.AreEqual <int>(_newInstance.PerformSumMethod(int.MinValue, int.MaxValue), _newInstance.PerformCalculationVar(int.MinValue, int.MaxValue));
        }
Exemplo n.º 2
0
        public void PerformSumMethodCalledTest()
        {
            DelegateExample _newInstance = new DelegateExample();
            int             _Called      = 0;
            object          _sender      = null;
            EventArgs       _args        = null;

            _newInstance.PerformSumMethodCalled += (x, y) => { _Called++; _sender = x; _args = y; };
            //_newInstance.PerformSumMethodCalled = (x, y) => { _Called++; _sender = x; _args = y; }; // The event 'DelegateExample.PerformSumMethodCalled' can only appear on the left hand side of += or -= (except when used from within the type 'DelegateExample')
            //_newInstance.PerformSumMethodCalled(this, EventArgs.Empty); //The event 'DelegateExample.PerformSumMethodCalled' can only appear on the left hand side of += or -= (except when used from within the type 'DelegateExample')
            Assert.AreEqual <int>(0, _Called);
            _newInstance.PerformSumMethod(1, 2);
            Assert.AreEqual <int>(1, _Called);
            Assert.AreSame(_newInstance, _sender);
            Assert.AreSame(_args, EventArgs.Empty);
        }