コード例 #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);
        }
コード例 #2
0
ファイル: ActionDisposableTests.cs プロジェクト: DoBi/Smaragd
        public void DisposeNativeResourcesDisposed_Dispose()
        {
            var nativeResourcesDisposed = false;
            var instance = new ActionDisposable(null, () => nativeResourcesDisposed = true);

            instance.Dispose();
            Assert.True(nativeResourcesDisposed);
        }
コード例 #3
0
ファイル: ActionDisposableTests.cs プロジェクト: DoBi/Smaragd
        public void DisposeManagedResources_Dispose()
        {
            var managedResourcesDisposed = false;
            var instance = new ActionDisposable(() => managedResourcesDisposed = true);

            instance.Dispose();
            Assert.True(managedResourcesDisposed);
        }
コード例 #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);
        }
コード例 #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();
        }
コード例 #6
0
ファイル: ActionDisposableTests.cs プロジェクト: DoBi/Smaragd
        public void Constructor_no_actions_no_exceptions()
        {
            var instance = new ActionDisposable(null);

            instance.Dispose();
        }
コード例 #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);
                }
            }
        }