借助网络配置,控制Modbus工具的日志显示,避免卡死界面
智能大石头 authored at 2021-12-11 22:09:19
1.67 KiB
XCoder
using System;
using System.ComponentModel;
using Avalonia.Media;
using NewLife.XCoder.Models;
using Xunit;

namespace XCoder.App.Tests;

/// <summary>结构化日志条目测试</summary>
public class LogEntryTests
{
    [Fact]
    [DisplayName("日志类别映射为设计稿中的短标签")]
    public void KindLabel_UsesShortLabels()
    {
        var time = new DateTime(2026, 1, 2, 3, 4, 5, 678);

        Assert.Equal("INF", new LogEntry(time, LogKind.Info, "").KindLabel);
        Assert.Equal("TX", new LogEntry(time, LogKind.Tx, "").KindLabel);
        Assert.Equal("RX", new LogEntry(time, LogKind.Rx, "").KindLabel);
        Assert.Equal("SYS", new LogEntry(time, LogKind.System, "").KindLabel);
        Assert.Equal("WARN", new LogEntry(time, LogKind.Warning, "").KindLabel);
        Assert.Equal("ERR", new LogEntry(time, LogKind.Error, "").KindLabel);
        Assert.Equal("03:04:05.678", new LogEntry(time, LogKind.Info, "").TimeText);
    }

    [Fact]
    [DisplayName("日志类别颜色与设计稿一致")]
    public void KindBrush_UsesDesignColors()
    {
        var time = DateTime.Now;

        Assert.Equal(Color.Parse("#5FD0FF"), GetColor(new LogEntry(time, LogKind.Tx, "")));
        Assert.Equal(Color.Parse("#6EE7A8"), GetColor(new LogEntry(time, LogKind.Rx, "")));
        Assert.Equal(Color.Parse("#7C93AC"), GetColor(new LogEntry(time, LogKind.System, "")));
        Assert.Equal(Color.Parse("#FFCF6E"), GetColor(new LogEntry(time, LogKind.Warning, "")));
        Assert.Equal(Color.Parse("#FF8A8A"), GetColor(new LogEntry(time, LogKind.Error, "")));
    }

    private static Color GetColor(LogEntry entry) => Assert.IsAssignableFrom<ISolidColorBrush>(entry.KindBrush).Color;
}