예제 #1
0
        public void AdditiveDelegates()
        {
            SimpleDelegateTestObject source = new SimpleDelegateTestObject();
            SimpleDelegateTestObject target = new SimpleDelegateTestObject();
            SimpleDelegateTestObject neutral = new SimpleDelegateTestObject();
            neutral.ListenTo(target);

            {
                // Does the neutral object receive events?
                target.FireEvent();
                Assert.IsTrue(neutral.PopEventReceived());

                source.DeepCopyTo(target);

                // Does it still receive them after copying the source onto it?
                target.FireEvent();
                Assert.IsTrue(neutral.PopEventReceived());
            }

            {
                source.ListenTo(source);

                // Does the source receive its own events?
                source.FireEvent();
                Assert.IsTrue(source.PopEventReceived());
                Assert.IsFalse(source.PopEventReceived());

                source.DeepCopyTo(target);

                // Do both neutral object and target itself receive both target events?
                target.FireEvent();
                Assert.IsTrue(neutral.PopEventReceived());
                Assert.IsFalse(neutral.PopEventReceived());
                Assert.IsTrue(target.PopEventReceived());
                Assert.IsFalse(target.PopEventReceived());
                Assert.IsFalse(source.PopEventReceived());
            }
        }
예제 #2
0
		[Test] public void SimpleDelegates()
		{
			SimpleDelegateTestObject source = new SimpleDelegateTestObject();
			SimpleDelegateTestObject target;
			source.ListenTo(source);
				
			// Does the event work as expected?
			source.FireEvent();
			Assert.IsTrue(source.PopEventReceived());

			target = source.DeepClone();

			// Does the cloned event work the same?
			target.FireEvent();
			Assert.IsFalse(source.PopEventReceived());
			Assert.IsTrue(target.PopEventReceived());
		}