public void TestGarbageCollectionForNamedStaticMethod() { Messenger.Reset(); TestRecipient.Reset(); _recipient = new TestRecipient(WeakActionTestCase.PublicStaticMethod); _recipientReference = new WeakReference(_recipient); Assert.AreEqual(null, TestRecipient.ContentStatic); Assert.IsTrue(_recipientReference.IsAlive); const string message = "Hello world"; Messenger.Default.Send(message); Assert.AreEqual(message, TestRecipient.ContentStatic); _recipient = null; GC.Collect(); Assert.IsFalse(_recipientReference.IsAlive); }
public void TestMessengerRegisteringForMessageBaseWhileSending() { MessageService.Reset(); TestRecipient.Reset(); var list = new List <TestRecipient2>(); for (var index = 0; index < 10; index++) { list.Add(new TestRecipient2(true)); } MessageService.Default.Send(new Message <string>(TestContentString)); Assert.AreEqual(null, TestRecipient.LastReceivedString); Assert.AreEqual(0, TestRecipient.ReceivedStringMessages); MessageService.Default.Send(new Message <string>(TestContentStringNested)); Assert.AreEqual(TestContentStringNested, TestRecipient.LastReceivedString); Assert.AreEqual(10, TestRecipient.ReceivedStringMessages); }
public void TestOldMessengerRegisteringForMessageBaseWhileSending() { Messenger.Reset(); TestRecipient.Reset(); var list = new List <TestRecipient2>(); for (var index = 0; index < 10; index++) { list.Add(new TestRecipient4()); } Messenger.Default.Broadcast(new GenericMessage <string>(TestContentString)); Assert.AreEqual(null, TestRecipient.LastReceivedString); Assert.AreEqual(0, TestRecipient.ReceivedStringMessages); Messenger.Default.Broadcast(new GenericMessage <string>(TestContentStringNested)); Assert.AreEqual(TestContentStringNested, TestRecipient.LastReceivedString); Assert.AreEqual(20, TestRecipient.ReceivedStringMessages); }