Пример #1
0
        public void WeakEventManager_NullEventManager()
        {
            //Arrange
            WeakEventManager unassignedEventManager = null;

            //Act

            //Assert
            Assert.Throws <NullReferenceException>(() => unassignedEventManager.HandleEvent(null, null, nameof(TestEvent)));
        }
Пример #2
0
        public void HandleEvent()
        {
            tlog.Debug(tag, $"HandleEvent START");
            try
            {
                var testingTarget = new WeakEventManager();
                Assert.IsNotNull(testingTarget, "Can't create success object WeakEventManager.");
                visibilityChangedEventHandler = (o, e) => { };
                testingTarget.AddEventHandler <VisibilityChangedEventArgs>("visibilityChangedEventHandler", visibilityChangedEventHandler);
                eventHandler = (o, e) => { };
                testingTarget.AddEventHandler("eventHandler", eventHandler);
                testingTarget.HandleEvent(null, new EventArgs(), "eventHandler");
                testingTarget.HandleEvent(null, new VisibilityChangedEventArgs(), "visibilityChangedEventHandler");
            }
            catch (Exception e)
            {
                Assert.Fail("Catch exception: " + e.Message.ToString());
            }

            tlog.Debug(tag, $"HandleEvent END");
        }
        public void WeakEventManager_UnassignedEventManager()
        {
            //Arrange
            var  unassignedEventManager = new WeakEventManager();
            bool didEventFire           = false;

            TestEvent += HandleTestEvent;
            void HandleTestEvent(object sender, EventArgs e) => didEventFire = true;

            //Act
            unassignedEventManager.HandleEvent(null, null, nameof(TestEvent));

            //Assert
            Assert.IsFalse(didEventFire);
            TestEvent -= HandleTestEvent;
        }
        public void WeakEventManagerTEventArgs_UnassignedEventManager()
        {
            //Arrange
            var  unassignedEventManager = new WeakEventManager <string>();
            bool didEventFire           = false;

            TestStringEvent += HandleTestEvent;
            void HandleTestEvent(object?sender, string e) => didEventFire = true;

            //Act
#pragma warning disable CS8625 //Cannot convert null literal to non-nullable reference type
            unassignedEventManager.HandleEvent(null, null, nameof(TestStringEvent));
#pragma warning enable CS8625

            //Assert
            Assert.IsFalse(didEventFire);
            TestStringEvent -= HandleTestEvent;
        }
Пример #5
0
            void ConfigurationChanged(object sender, EventArgs e)
            {
                if (IsDuo)
                {
                    _helper?.Update();
                }

                bool wasLandscape = IsLandscape;

                Update();

                bool screenChanged = false;

                if (wasLandscape != IsLandscape)
                {
                    screenChanged = true;
                }

                if (_mainActivity != null)
                {
                    using (DisplayMetrics display = _mainActivity.Resources.DisplayMetrics)
                    {
                        var scalingFactor = display.Density;
                        _pixelScreenSize = new Size(display.WidthPixels, display.HeightPixels);
                        var newSize = new Size(_pixelScreenSize.Width / scalingFactor, _pixelScreenSize.Height / scalingFactor);

                        if (newSize != ScaledScreenSize)
                        {
                            ScaledScreenSize = newSize;
                            screenChanged    = true;
                        }
                    }
                }

                if (screenChanged)
                {
                    _onScreenChangedEventManager.HandleEvent(this, e, nameof(OnScreenChanged));
                }
            }
Пример #6
0
 /// <summary>
 /// Raise a CanExecute change event.
 /// </summary>
 public void RaiseCanExecuteChanged() => weakEventManager.HandleEvent(this, EventArgs.Empty, nameof(CanExecuteChanged));
Пример #7
0
 void OnCurrentSizeChanged(object sender, Windows.UI.Core.WindowSizeChangedEventArgs e)
 {
     _onScreenChangedEventManager.HandleEvent(this, EventArgs.Empty, nameof(OnScreenChanged));
 }
Пример #8
0
 void OnDeviceInfoChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
 {
     _onScreenChangedEventManager.HandleEvent(this, e, nameof(OnScreenChanged));
 }
Пример #9
0
 void OnDeviceInfoChanged(object sender, DisplayInfoChangedEventArgs e)
 {
     _onScreenChangedEventManager.HandleEvent(this, e, nameof(OnScreenChanged));
 }
 void OnTestEvent()
 {
     _weakEventManager.HandleEvent(this, EventArgs.Empty, nameof(TestEvent));
 }