Exemplo n.º 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UndoManager"/> class.
 /// </summary>
 /// <param name="root">The <see cref="UndoRoot"/> to use for undo/redo actions.</param>
 /// <param name="setModified">An action called whenever a change is made.</param>
 public UndoManager(UndoRoot root, Action setModified)
 {
     this.root                   = root;
     this.setModified            = setModified;
     this.root.UndoStackChanged += UndoStackChanged;
     this.root.RedoStackChanged += RedoStackChanged;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UndoManager"/> class.
 /// </summary>
 /// <param name="root">The <see cref="UndoRoot"/> to use for undo/redo actions.</param>
 /// <param name="setModified">An action called whenever a change is made.</param>
 public UndoManager(UndoRoot root, Action setModified)
 {
     this.root = root;
     this.setModified = setModified;
     this.root.UndoStackChanged += UndoStackChanged;
     this.root.RedoStackChanged += RedoStackChanged;
 }
Exemplo n.º 3
0
        public void UndoService_Uses_WeakReferences()
        {
            // Create a root, but don't keep any references to the object that it is for.
            UndoRoot      undoRoot = null;
            WeakReference wrDoc    = GetWeakReference(out undoRoot);

            // Confirm the object is still alive.
            Assert.IsNotNull(undoRoot);
            Assert.IsTrue(wrDoc.IsAlive);

            // Force a GC to collect the document used for the undo root.
            // Don't do this in normal code... this is just for testing.
            GC.Collect(1, GCCollectionMode.Forced, true);

            // Confirm the RootDocument was collected.
            // This shows that we're not leaking memory via the UndoService's _Roots dictionary.
            Assert.IsFalse(wrDoc.IsAlive);
            Assert.IsNull(wrDoc.Target);


            // Inline function.
            // This method is part of UndoService_Uses_WeakReferences.
            // Code is in a separate method so that the variables are properly scoped
            // which allows the GC call to work properly.
            WeakReference GetWeakReference(out UndoRoot undoRoot)
            {
                var document = new RootDocument();          // Constructed, but not returned.

                undoRoot = UndoService.Current[document];   // This creates a weakly referenced undo root.
                return(new WeakReference(document));        // Return a weak reference so that we can test if the document was collected.
            }
        }
Exemplo n.º 4
0
        public MaskingVideoOverlayViewModelTests()
        {
            _scriptVideoContextMock = new Mock <IScriptVideoContext>();
            _scriptVideoContextMock.Setup(svc => svc.HasVideo).Returns(true);
            _scriptVideoContextMock.Setup(svc => svc.FrameNumber).Returns(0);
            _scriptVideoContextMock.Setup(svc => svc.IsVideoPlaying).Returns(false);
            _scriptVideoContextMock.Setup(svc => svc.VideoFrameCount).Returns(241);
            _scriptVideoContextMock.Setup(svc => svc.SeekableVideoFrameCount).Returns(240);
            _scriptVideoContextMock.Setup(svc => svc.VideoFrameSize).Returns(new SizeI(628, 472));

            _scriptVideoServiceMock = new Mock <IScriptVideoService>();
            _scriptVideoServiceMock.Setup(svs => svs.GetContextReference()).Returns(_scriptVideoContextMock.Object);

            _mockMaskingProject = MockProjectFactory.CreateMockMaskingProject();
            _projectServiceMock = new Mock <IProjectService>();
            _projectServiceMock.Setup(ps => ps.Project).Returns(_mockMaskingProject);

            _undoServiceMock = new Mock <IUndoService>();
            _undoServiceMock.Setup(us => us[It.IsAny <object>()]).Returns((object root) =>
            {
                if (_undoRoot?.Root != root)
                {
                    _undoRoot = new UndoRoot(root);
                }
                return(_undoRoot);
            });

            _undoChangeFactoryMock = new Mock <IChangeFactory>();

            _systemDialogServiceMock = new Mock <ISystemDialogService>();
            _systemDialogServiceMock.Setup(sds => sds.ShowErrorDialog(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Exception>()))
            .Callback <string, string, Exception>((dialogTextParam, dialogCaptionParam, exceptionParam) =>
            {
                throw exceptionParam ?? new Exception(dialogTextParam);
            });

            _clipboardServiceMock = new Mock <IClipboardService>();

            _applicationCommands = new ApplicationCommands();

            _viewModel = new MaskingVideoOverlayViewModel(_scriptVideoServiceMock.Object, _undoServiceMock.Object, _undoChangeFactoryMock.Object, _applicationCommands, _projectServiceMock.Object, _systemDialogServiceMock.Object, _clipboardServiceMock.Object);
        }
        private void SetupViewModel(bool useRealUndoService = false)
        {
            _currentScriptVideoFrameNumber = 0;

            _scriptVideoServiceMock = new Mock <IScriptVideoService>();
            _scriptVideoServiceMock.SetupAdd(svs => svs.FrameChanged    += It.IsAny <EventHandler <FrameChangedEventArgs> >());
            _scriptVideoServiceMock.SetupRemove(svs => svs.FrameChanged -= It.IsAny <EventHandler <FrameChangedEventArgs> >());

            _scriptVideoContextMock = new Mock <IScriptVideoContext>();
            _scriptVideoContextMock.Setup(svc => svc.HasVideo).Returns(true);

            _scriptVideoContextMock.SetupGet(svc => svc.FrameNumber).Returns(() => _currentScriptVideoFrameNumber);
            _scriptVideoContextMock.SetupSet(svc => svc.FrameNumber = It.IsAny <int>()).Callback <int>(value =>
            {
                int previousFrameNumber        = _currentScriptVideoFrameNumber;
                _currentScriptVideoFrameNumber = value;
                _scriptVideoServiceMock.Raise(svs => svs.FrameChanged += null, new FrameChangedEventArgs(previousFrameNumber, _currentScriptVideoFrameNumber));
            });

            _scriptVideoContextMock.Setup(svc => svc.IsVideoPlaying).Returns(false);
            _scriptVideoContextMock.Setup(svc => svc.VideoFrameCount).Returns(400);
            _scriptVideoContextMock.Setup(svc => svc.SeekableVideoFrameCount).Returns(399);
            _scriptVideoContextMock.Setup(svc => svc.VideoFrameSize).Returns(new SizeI(640, 480));

            _scriptVideoServiceMock.Setup(svs => svs.GetContextReference()).Returns(_scriptVideoContextMock.Object);

            _timelineCommands    = new TimelineCommands();
            _applicationCommands = new ApplicationCommands();

            if (useRealUndoService)
            {
                _undoService = UndoService.Current;
                _undoService.Clear();
                _undoChangeFactory = new ChangeFactory();
            }
            else
            {
                Mock <IUndoService>   undoServiceMock;
                Mock <IChangeFactory> undoChangeFactoryMock;

                undoServiceMock = new Mock <IUndoService>();
                undoServiceMock.Setup(us => us[It.IsAny <object>()]).Returns((object root) =>
                {
                    if (_undoRoot?.Root != root)
                    {
                        _undoRoot = new UndoRoot(root);
                    }
                    return(_undoRoot);
                });
                _undoService = undoServiceMock.Object;

                undoChangeFactoryMock = new Mock <IChangeFactory>();
                _undoChangeFactory    = undoChangeFactoryMock.Object;
            }

            _clipboardServiceMock = new Mock <IClipboardService>();
            _dialogServiceMock    = new Mock <IDialogService>();

            _timelineSegmentProvidingViewModel = new MockTimelineSegmentProvidingViewModel(GenerateTestSegmentModels(), _scriptVideoServiceMock.Object, _undoService, _undoChangeFactory, _clipboardServiceMock.Object, _applicationCommands);

            if (useRealUndoService)
            {
                _undoRoot = _undoService[_timelineSegmentProvidingViewModel];
            }

            _viewModel = new VideoTimelineViewModel(_scriptVideoServiceMock.Object, _undoService, _undoChangeFactory, _clipboardServiceMock.Object, _dialogServiceMock.Object, _timelineCommands)
            {
                TimelineSegmentProvidingViewModel = _timelineSegmentProvidingViewModel
            };
            _scriptVideoContextMock.Object.FrameNumber = 0;
        }