using System; using NUnit.Framework; namespace CoreTests { internal class NotificationCenterTests { enum TestingNotificationType { TestEvent } class TestingNotification : GenericNotification { } class TestingNotificationCenter : GenericNotificationCenter { } 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);*/ } } }