RPC远程过程调用,二进制封装,提供高吞吐低延迟的高性能RPC框架
大石头 authored at 2022-08-10 13:26:19
1.15 KiB
NewLife.Remoting
using System;
using System.ComponentModel;
using NewLife.Remoting;
using Xunit;

namespace XUnitTest;

public class ApiAttributeTests
{
    [Fact]
    [DisplayName("构造函数设置Name")]
    public void Constructor_SetsName()
    {
        var attr = new ApiAttribute("test/action");

        Assert.Equal("test/action", attr.Name);
    }

    [Fact]
    [DisplayName("空名称")]
    public void Constructor_EmptyName()
    {
        var attr = new ApiAttribute("");

        Assert.Equal("", attr.Name);
    }

    [Fact]
    [DisplayName("Name属性可读写")]
    public void Name_CanBeSetAndGet()
    {
        var attr = new ApiAttribute("initial");
        attr.Name = "modified";

        Assert.Equal("modified", attr.Name);
    }

    [Fact]
    [DisplayName("验证AttributeUsage")]
    public void AttributeUsage_AllowsClassAndMethod()
    {
        var usage = (AttributeUsageAttribute)Attribute.GetCustomAttribute(typeof(ApiAttribute), typeof(AttributeUsageAttribute))!;

        Assert.True(usage.ValidOn.HasFlag(AttributeTargets.Class));
        Assert.True(usage.ValidOn.HasFlag(AttributeTargets.Method));
        Assert.False(usage.AllowMultiple);
    }
}