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;
}
|