Esempio n. 1
0
        public void Should_call_dispose_action_once()
        {
            var x = 0;
            var d = new ActionDisposable(() => x++);

            x.Should().Be(0);

            d.Dispose();

            x.Should().Be(1);

            d.Dispose();

            x.Should().Be(1);
        }
Esempio n. 2
0
        public void DisposeNativeResourcesDisposed_Dispose()
        {
            var nativeResourcesDisposed = false;
            var instance = new ActionDisposable(null, () => nativeResourcesDisposed = true);

            instance.Dispose();
            Assert.True(nativeResourcesDisposed);
        }
Esempio n. 3
0
        public void DisposeManagedResources_Dispose()
        {
            var managedResourcesDisposed = false;
            var instance = new ActionDisposable(() => managedResourcesDisposed = true);

            instance.Dispose();
            Assert.True(managedResourcesDisposed);
        }
Esempio n. 4
0
        public void DisposesWithAction()
        {
            bool   onLeaveCalled = false;
            Action onLeave       = () => { onLeaveCalled = true; };

            var disposable = new ActionDisposable(() => { }, onLeave);

            Assert.False(onLeaveCalled);

            disposable.Dispose();
            Assert.True(onLeaveCalled);
        }
Esempio n. 5
0
        public void ExecuteActionWhenDisposed()
        {
            // Arrange
            var flag             = false;
            var action           = new Action(() => flag = true);
            var actionDisposable = new ActionDisposable(action);

            // Act
            actionDisposable.Dispose();

            // Assert
            flag.Should().BeTrue();
        }
Esempio n. 6
0
        public void Constructor_no_actions_no_exceptions()
        {
            var instance = new ActionDisposable(null);

            instance.Dispose();
        }
Esempio n. 7
0
        public void HandleNavigated(ShellNavigatedEventArgs args)
        {
            _waitingForWindow?.Dispose();
            _waitingForWindow = null;

            // we don't want to fire Navigated until shell is attached to an actual window
            if (_shell.Window == null || _shell.CurrentPage == null)
            {
                _shell.PropertyChanged += WaitForWindowToSet;
                var shellContent = _shell?.CurrentItem?.CurrentItem?.CurrentItem;

                if (shellContent != null)
                {
                    shellContent.ChildAdded += WaitForWindowToSet;
                }

                _waitingForWindow = new ActionDisposable(() =>
                {
                    _shell.PropertyChanged -= WaitForWindowToSet;
                    if (shellContent != null)
                    {
                        shellContent.ChildAdded -= WaitForWindowToSet;
                    }
                });

                void WaitForWindowToSet(object sender, EventArgs e)
                {
                    if (_shell.Window != null &&
                        _shell.CurrentPage != null)
                    {
                        _waitingForWindow?.Dispose();
                        _waitingForWindow = null;

                        _shell.CurrentItem?.SendAppearing();
                        HandleNavigated(args);
                    }
                }

                return;
            }

            if (AccumulateNavigatedEvents)
            {
                if (_accumulatedEvent == null)
                {
                    _accumulatedEvent = args;
                }
            }
            else
            {
                _accumulatedEvent = null;
                BaseShellItem baseShellItem = _shell.CurrentItem?.CurrentItem?.CurrentItem;

                if (baseShellItem != null)
                {
                    baseShellItem.OnAppearing(() =>
                    {
                        FireNavigatedEvents(args, _shell);
                    });
                }
                else
                {
                    FireNavigatedEvents(args, _shell);
                }

                void FireNavigatedEvents(ShellNavigatedEventArgs a, Shell shell)
                {
                    Navigated?.Invoke(this, args);
                    // reset active page route tree
                    Routing.ClearImplicitPageRoutes();
                    Routing.RegisterImplicitPageRoutes(_shell);
                }
            }
        }