public ComplexDelegateTestObject GetBottomChild()
 {
     if (this.Children == null || this.Children.Count == 0)
     {
         return(this);
     }
     else
     {
         ComplexDelegateTestObject childWithMostChildren = this.Children.OrderByDescending(c => c.Children != null ? c.Children.Count : 0).First() as ComplexDelegateTestObject;
         return(childWithMostChildren.GetBottomChild());
     }
 }
Exemplo n.º 2
0
		[Test] public void ComplexDelegates()
		{
			ComplexDelegateTestObject data = new ComplexDelegateTestObject(new[]
			{
				new ComplexDelegateTestObject(),
				new ComplexDelegateTestObject(new[]
				{
					new ComplexDelegateTestObject(),
					new ComplexDelegateTestObject()
				})
			});
			ComplexDelegateTestObject dataPart = data.Children[1] as ComplexDelegateTestObject;
			ComplexDelegateTestObject fireChild;

			// Make sure the event test setup works as expected under normal conditions
			{
				fireChild = data.GetBottomChild();

				Assert.IsFalse(data.EventReceived);
				fireChild.FireEvent();
				Assert.IsTrue(data.EventReceived);

				data.ResetAllEventsReceived();
				Assert.IsFalse(data.EventReceived);
			}

			// See if everything works as expected in a regular clone
			{
				// Does the cloning itself work as expected?
				ComplexDelegateTestObject dataResultFull = data.DeepClone();
				Assert.AreSame(null, dataResultFull.Parent);
				Assert.AreEqual(2, dataResultFull.Children.Count);
				Assert.AreEqual(2, dataResultFull.Children[1].Children.Count);
				Assert.IsTrue(dataResultFull.CheckChildIntegrity());
				Assert.IsFalse(data.AnyReferenceEquals(dataResultFull));

				// Does event handling work as expected?
				fireChild = dataResultFull.GetBottomChild();

				Assert.IsFalse(dataResultFull.EventReceived);
				Assert.IsFalse(data.EventReceived);
				fireChild.FireEvent();
				Assert.IsTrue(dataResultFull.EventReceived);
				Assert.IsFalse(data.EventReceived);

				dataResultFull.ResetAllEventsReceived();
				Assert.IsFalse(dataResultFull.EventReceived);
			}

			// See if everything works as expected in a partial clone
			{
				// Does the cloning itself work as expected?
				ComplexDelegateTestObject dataResultPart = dataPart.DeepClone();
				Assert.AreSame(null, dataResultPart.Parent);
				Assert.AreEqual(2, dataResultPart.Children.Count);
				Assert.IsTrue(dataResultPart.CheckChildIntegrity());
				Assert.IsFalse(dataPart.AnyReferenceEquals(dataResultPart));

				// Does event handling work as expected?
				fireChild = dataResultPart.GetBottomChild();

				Assert.IsFalse(dataResultPart.EventReceived);
				Assert.IsFalse(data.EventReceived);
				fireChild.FireEvent();
				Assert.IsTrue(dataResultPart.EventReceived);
				Assert.IsFalse(data.EventReceived);

				dataResultPart.ResetAllEventsReceived();
				Assert.IsFalse(dataResultPart.EventReceived);
			}
		}
 public void ListenTo(ComplexDelegateTestObject other)
 {
     other.SomeEvent += this.ReceiveEvent;
 }
		public void ListenTo(ComplexDelegateTestObject other)
		{
			other.SomeEvent += this.ReceiveEvent;
		}