123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- using System;
- using NUnit.Framework;
- namespace CoreTests
- {
- internal class NotificationCenterTests
- {
- enum TestingNotificationType
- {
- TestEvent
- }
- class TestingNotification : GenericNotification<TestingNotificationType>
- {
- }
- class TestingNotificationCenter : GenericNotificationCenter<TestingNotificationType, TestingNotification>
- {
- }
- const TestingNotificationType testNotificationType = TestingNotificationType.TestEvent;
- void TestDelegate(TestingNotification note)
- {
- //Do nothing
- }
- [SetUp]
- public void SetUp()
- {
- TestingNotificationCenter.Reset_USE_ONLY_FOR_UNIT_TESTS();
- }
- [TearDown]
- public void TearDown()
- {
- }
- [Test]
- public void CreateOneDelegate()
- {
- /*TestingNotificationCenter.AddListener(TestDelegate, testNotificationType);
- Assert.AreEqual(TestingNotificationCenter.GetListenerCount(testNotificationType), 1);
- Assert.AreEqual(TestingNotificationCenter.GetTotalListenersCount(), 1);*/
- }
- [Test]
- public void CreateOneDelegateAndRemoveIt()
- {
- /*TestingNotificationCenter.AddListener(TestDelegate, testNotificationType);
- TestingNotificationCenter.RemoveListener(TestDelegate, testNotificationType);
- Assert.AreEqual(TestingNotificationCenter.GetListenerCount(testNotificationType), 0);
- Assert.AreEqual(TestingNotificationCenter.GetTotalListenersCount(), 0);*/
- }
- [Test]
- //[ExpectedException(typeof(AssertionFailedException))]
- public void TryAddingDuplicateDeligates()
- {
- #if !DEBUG
- Assert.Fail("This test required DEBUG to be defined");
- #endif
- TestingNotificationCenter.AddListener(TestDelegate, testNotificationType);
- TestingNotificationCenter.AddListener(TestDelegate, testNotificationType);
- }
- [Test]
- public void TryRemovingDeligateMoreThanOnce()
- {
- TestingNotificationCenter.AddListener(TestDelegate, testNotificationType);
- TestingNotificationCenter.RemoveListener(TestDelegate, testNotificationType);
- TestingNotificationCenter.RemoveListener(TestDelegate, testNotificationType);
- /*Assert.AreEqual(TestingNotificationCenter.GetListenerCount(testNotificationType), 0);
- Assert.AreEqual(TestingNotificationCenter.GetTotalListenersCount(), 0);*/
- }
- [Test]
- public void TestNotificationPosting()
- {
- int invocations = 0;
- TestingNotificationCenter.OnNotificationDelegate notificationDelegate = (note) =>
- {
- ++invocations;
- };
- TestingNotificationCenter.AddListener(notificationDelegate, testNotificationType);
- TestingNotificationCenter.Post(testNotificationType);
- /*Assert.AreEqual(1, invocations);
- TestingNotificationCenter.Post(testNotificationType);
- Assert.AreEqual(2, invocations);*/
- }
- [Test]
- public void TestNotificationPostingAfterRemoving()
- {
- int invocations = 0;
- TestingNotificationCenter.OnNotificationDelegate notificationDelegate = (note) =>
- {
- ++invocations;
- };
- TestingNotificationCenter.AddListener(notificationDelegate, testNotificationType);
- TestingNotificationCenter.Post(testNotificationType);
- /*Assert.AreEqual(1, invocations);
- TestingNotificationCenter.RemoveListener(notificationDelegate, testNotificationType);
- TestingNotificationCenter.Post(testNotificationType);
- Assert.AreEqual(1, invocations);*/
- }
- }
- }
|