XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEToolBox

【WPF】XFE工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Media;
using System.Windows.Threading;
using XFEToolBox.Tools.VideoStudio;

namespace VideoStudio.Validation;
internal static partial class Program
{
    private static async Task AssetSelectionTests(string[] paths)
    {
        using (var library = new MediaLibrary())
        {
            var asset = await library.ImportAsync(ffmpeg, ffprobe, paths[0], default);
            var lookup = new HashSet<MediaAsset> { asset }; int originalHash = asset.GetHashCode();
            PropertyChangedEventHandler listener = (_, _) => { };
            asset.PropertyChanged += listener; asset.PreviewNote = "thumbnail update"; asset.NotifyPreviewReady();
            await library.WaitForPreviewsAsync();
            Check(originalHash == asset.GetHashCode() && lookup.Contains(asset), "media identity stays stable across thumbnail loading and binding subscriptions");
            asset.PropertyChanged -= listener;
        }
        var page = new MainPage(); var vm = (MainPageViewModel)page.DataContext;
        vm.FfmpegPath = ffmpeg; vm.FfprobePath = ffprobe; page.Playback.IsMuted = true;
        var window = TestWindow(page); window.Show(); await Dispatcher.Yield(DispatcherPriority.ApplicationIdle);
        try
        {
            await vm.ImportAssetsAsync(paths.Take(2));
            var bin = (ListBox)page.FindName("AssetList"); var first = vm.Assets[0]; var second = vm.Assets[1];
            bin.SetCurrentValue(ListBox.SelectedItemProperty, second);
            await Dispatcher.Yield(DispatcherPriority.ApplicationIdle);
            Check(ReferenceEquals(vm.SelectedAsset, second) && ReferenceEquals(bin.SelectedItem, second), "selecting second bin item updates view model and visible selection");
            await vm.WaitForAssetPreviewsAsync();
            for (int i = 0; i < 20; i++) { first.PreviewNote = "refresh " + i; first.NotifyPreviewReady(); second.NotifyPreviewReady(); vm.RefreshEditor(); vm.FollowSequencePlayback(i / 30d); }
            await Dispatcher.Yield(DispatcherPriority.ApplicationIdle);
            Check(ReferenceEquals(bin.SelectedItem, second) && bin.SelectedItems.Count == 1, "thumbnail refresh and playback ticks do not select the top material again");
            vm.SelectedClip = null; vm.SelectedClip = vm.Clips.First(c => c.Kind == MediaKind.Video);
            vm.EditName = "renamed timeline clip"; vm.ApplyClipPropertiesCommand.Execute(null); vm.UndoCommand.Execute(null);
            await Dispatcher.Yield(DispatcherPriority.ApplicationIdle);
            Check(ReferenceEquals(vm.SelectedAsset, second) && ReferenceEquals(bin.SelectedItem, second), "timeline selection, inspector edits and undo do not override independent bin selection");
            CollectionViewSource.GetDefaultView(vm.Assets).MoveCurrentTo(first);
            await Dispatcher.Yield(DispatcherPriority.ApplicationIdle);
            Check(ReferenceEquals(bin.SelectedItem, second), "collection-view current item cannot force bin back to first asset");
            bin.SelectedItems.Add(first); await Dispatcher.Yield(DispatcherPriority.ApplicationIdle);
            first.NotifyPreviewReady(); second.NotifyPreviewReady(); vm.RefreshEditor();
            await Dispatcher.Yield(DispatcherPriority.ApplicationIdle);
            Check(bin.SelectedItems.Count == 2 && bin.SelectedItems.Contains(first) && bin.SelectedItems.Contains(second), "extended multi-selection survives bound preview notifications");
            bin.SetCurrentValue(ListBox.SelectedItemProperty, first);
            var pendingImport = vm.ImportAssetsAsync(paths.Skip(2));
            bin.SetCurrentValue(ListBox.SelectedItemProperty, second);
            await pendingImport; await Dispatcher.Yield(DispatcherPriority.ApplicationIdle);
            Check(ReferenceEquals(vm.SelectedAsset, second) && ReferenceEquals(bin.SelectedItem, second), "finishing background import preserves a newer user selection");
            Save(page, "independent-bin-selection.png");
            await vm.WaitForAssetPreviewsAsync();
        }
        finally { vm.HasUnsavedChanges = false; window.Close(); }
    }
}