[Test] public void StaticDelegates() { SimpleDelegateTestObject source = new SimpleDelegateTestObject(); SimpleDelegateTestObject target; bool staticEventReceived = false; source.SomeEvent += delegate (object sender, EventArgs e) { staticEventReceived = true; }; // Does the static event work as expected? source.FireEvent(); Assert.IsTrue(staticEventReceived); staticEventReceived = false; target = source.DeepClone(); // We expect static events to not be cloned due to conceptual ownership inversion in delegates target.FireEvent(); Assert.IsFalse(staticEventReceived); // The source should still trigger it though. source.FireEvent(); Assert.IsTrue(staticEventReceived); }
[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()); }