Пример #1
0
        public void WithoutSuppress_NotificationsHappen()
        {
            var testLocator     = new InternalLocator();
            var originalLocator = testLocator.Internal;

            int    numberNotifications = 0;
            Action notificationAction  = () => numberNotifications++;

            testLocator.RegisterResolverCallbackChanged(notificationAction);

            testLocator.SetLocator(new ModernDependencyResolver());
            testLocator.SetLocator(new ModernDependencyResolver());

            // 2 for the changes, 1 for the callback being immediately called.
            Assert.Equal(3, numberNotifications);

            testLocator.SetLocator(originalLocator);
        }
Пример #2
0
        public void WithResolver_NotificationsDontHappen()
        {
            int    numberNotifications = 0;
            Action notificationAction  = () => numberNotifications++;

            var testLocator = new InternalLocator();

            testLocator.RegisterResolverCallbackChanged(notificationAction);

            using (testLocator.Internal.WithResolver())
            {
                using (testLocator.Internal.WithResolver())
                {
                }
            }

            // 1 due to the fact the callback is called when we register.
            Assert.Equal(1, numberNotifications);
        }
Пример #3
0
        public void WithSuppression_NotificationsDontHappen()
        {
            var testLocator     = new InternalLocator();
            var originalLocator = testLocator.Internal;

            using (testLocator.SuppressResolverCallbackChangedNotifications())
            {
                int    numberNotifications = 0;
                Action notificationAction  = () => numberNotifications++;

                testLocator.RegisterResolverCallbackChanged(notificationAction);

                testLocator.SetLocator(new ModernDependencyResolver());
                testLocator.SetLocator(new ModernDependencyResolver());

                Assert.Equal(0, numberNotifications);

                testLocator.SetLocator(originalLocator);
            }
        }