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

namespace XCoder.App.Tests;

/// <summary>MD5 计算测试</summary>
public class Md5ServiceTests
{
    [Fact]
    [DisplayName("32 位 MD5 与标准值一致")]
    public void Compute32_KnownValue()
        => Assert.Equal("900150983cd24fb0d6963f7d28e17f72", Md5Service.Compute32("abc"));

    [Fact]
    [DisplayName("16 位 MD5 是 32 位的中间 16 位")]
    public void Compute16_IsMiddlePart()
    {
        var hash32 = Md5Service.Compute32("abc");
        var hash16 = Md5Service.Compute16("abc");

        Assert.Equal(16, hash16.Length);
        Assert.Equal(hash32.Substring(8, 16), hash16);
    }

    [Fact]
    [DisplayName("批量计算跳过空行并保持顺序")]
    public void Batch_SkipsEmptyLines()
    {
        var list = Md5Service.Batch("abc\n\n  \r\nabc");

        Assert.Equal(2, list.Count);
        Assert.All(list, e => Assert.Equal("900150983cd24fb0d6963f7d28e17f72", e.Hash32));
    }

    [Fact]
    [DisplayName("空输入返回空结果")]
    public void Batch_Null_ReturnsEmpty()
        => Assert.Empty(Md5Service.Batch(null));

    [Fact]
    [DisplayName("格式化输出为原文 / 32 / 16 三列")]
    public void Format_ThreeColumns()
    {
        var text = Md5Service.Format(Md5Service.Batch("abc"));
        var parts = text.Split('\t');

        Assert.Equal(3, parts.Length);
        Assert.Equal("abc", parts[0]);
        Assert.Equal(32, parts[1].Length);
        Assert.Equal(16, parts[2].Length);
    }
}