基于WebView2实现的Win11桌面框架,利用插件自定义
Moli
2026-05-02 b4858d19fbad69810d211270bc5b280bf9909ea5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Microsoft.Extensions.Logging.Abstractions;
using Moli.Desktop.Configuration;
using Moli.Desktop.Diagnostics;
using Moli.Desktop.Host;
using Moli.Desktop.Plugins;
 
namespace Moli.Desktop.Tests.Host;
 
public class DefaultContentInstallerTests
{
    [Fact]
    public async Task InstallAsync_CopiesSamplesAndSeedsRegistryAndLayouts()
    {
        var root = Path.Combine(Path.GetTempPath(), "Moli.Desktop.Tests", Guid.NewGuid().ToString("N"));
        var paths = new DesktopPaths(Path.Combine(root, "app"), Path.Combine(root, "local"));
        var diagnostics = new DiagnosticsService(paths, NullLogger<DiagnosticsService>.Instance);
        var configuration = new JsonConfigurationService(paths, diagnostics);
        var installer = new DefaultContentInstaller(paths, configuration, diagnostics);
 
        await installer.InstallAsync();
 
        Assert.True(File.Exists(Path.Combine(paths.PluginDirectory, "sample.wallpaper", "plugin.json")));
        Assert.True(File.Exists(Path.Combine(paths.PluginDirectory, "sample.clock", "index.html")));
        Assert.True(File.Exists(Path.Combine(paths.PluginDirectory, "sample.system-info", "index.html")));
 
        var registry = await configuration.LoadPluginRegistryAsync();
        Assert.Contains(registry.Plugins, item => item.Id == new PluginId("sample.wallpaper") && item.State == PluginState.Enabled);
        Assert.Contains(registry.Plugins, item => item.Id == new PluginId("sample.clock") && item.State == PluginState.Enabled);
        Assert.Contains(registry.Plugins, item => item.Id == new PluginId("sample.system-info") && item.State == PluginState.Enabled);
 
        var layout = await configuration.LoadLayoutAsync();
        Assert.Contains(layout.Instances, item => item.PluginId == new PluginId("sample.clock"));
        Assert.Contains(layout.Instances, item => item.PluginId == new PluginId("sample.system-info"));
        Assert.DoesNotContain(layout.Instances, item => item.PluginId == new PluginId("sample.wallpaper"));
    }
}