Beispiel #1
0
 /// <summary>
 /// Undo the latest change.
 /// </summary>
 public void Undo()
 {
     root.Undo();
 }
        public void MoveTrackSegmentTest(int preTestFrameNumber, int preTestTrackIndex, int segmentViewModelIndex, bool isSelectedSegmentPreMove, int newTrackNumber, int newStartFrame)
        {
            SetupViewModel(useRealUndoService: true);

            IScriptVideoContext svc = _scriptVideoContextMock.Object;

            if (svc.FrameNumber != preTestFrameNumber)
            {
                svc.FrameNumber = preTestFrameNumber;
            }

            _viewModel.SelectedTrack = _viewModel.TimelineTrackCollection[preTestTrackIndex];

            SegmentViewModelBase segmentToMove = _timelineSegmentProvidingViewModel.SegmentViewModels[segmentViewModelIndex];

            Assert.Equal(isSelectedSegmentPreMove, segmentToMove == _viewModel.TimelineSegmentProvidingViewModel.SelectedSegment);

            int originalTrackNumber = segmentToMove.TrackNumber;
            int originalStartFrame  = segmentToMove.StartFrame;
            int originalEndFrame    = segmentToMove.EndFrame;
            int newEndFrame         = newStartFrame + segmentToMove.FrameDuration - 1;

            // Key frame tests
            int startFrameOffset = newStartFrame - originalStartFrame;

            int[] originalKeyFrameNumbers = segmentToMove.KeyFrameViewModels.Select(kfvm => kfvm.FrameNumber).ToArray();

            _viewModel.MoveTrackSegment(segmentToMove, newTrackNumber, newStartFrame);
            Assert.Equal(newTrackNumber, segmentToMove.TrackNumber);
            Assert.Equal(newStartFrame, segmentToMove.StartFrame);
            Assert.Equal(newEndFrame, segmentToMove.EndFrame);

            Assert.Equal(1, _viewModel.TimelineSegments.Count(segment => segment == segmentToMove));

            Assert.DoesNotContain(segmentToMove, _viewModel.TimelineTrackCollection[originalTrackNumber].TrackSegments);
            Assert.Contains(segmentToMove, _viewModel.TimelineTrackCollection[newTrackNumber].TrackSegments);

            // Key frame tests
            for (int i = 0; i < segmentToMove.KeyFrameViewModels.Count; i++)
            {
                Assert.Equal(originalKeyFrameNumbers[i] + startFrameOffset, segmentToMove.KeyFrameViewModels[i].FrameNumber);
            }

            if (isSelectedSegmentPreMove)
            {
                Assert.False(segmentToMove == _viewModel.TimelineSegmentProvidingViewModel.SelectedSegment);
            }

            Assert.True(_undoRoot.CanUndo);
            _undoRoot.Undo();

            Assert.Equal(originalTrackNumber, segmentToMove.TrackNumber);
            Assert.Equal(originalStartFrame, segmentToMove.StartFrame);
            Assert.Equal(originalEndFrame, segmentToMove.EndFrame);

            Assert.Equal(1, _viewModel.TimelineSegments.Count(segment => segment == segmentToMove));

            Assert.DoesNotContain(segmentToMove, _viewModel.TimelineTrackCollection[newTrackNumber].TrackSegments);
            Assert.Contains(segmentToMove, _viewModel.TimelineTrackCollection[originalTrackNumber].TrackSegments);

            // Key frame tests
            for (int i = 0; i < segmentToMove.KeyFrameViewModels.Count; i++)
            {
                Assert.Equal(originalKeyFrameNumbers[i], segmentToMove.KeyFrameViewModels[i].FrameNumber);
            }

            Assert.Equal(isSelectedSegmentPreMove, segmentToMove == _viewModel.TimelineSegmentProvidingViewModel.SelectedSegment);
        }