[fix]修正UdpServer在接收广播时连续启动接收的错误,在StarAgent中,此时可能收到广播包,SocketFlags是Broadcast,需要清空,否则报错“参考的对象类型不支持尝试的操作”; 无需设置SocketOptionName.PacketInformation,在ReceiveMessageFromAsync时会自动设置,并且支持ipv6;
石头 编写于 2024-10-10 00:36:00 石头 提交于 2024-10-10 00:45:43
X
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XCode.DataAccessLayer;
using Xunit;

namespace XUnitTest.XCode.Model
{
    public class ModelResolverTests
    {
        [Fact]
        public void Test1()
        {
            var mr = new ModelResolver();

            Assert.Equal("Class", mr.GetName("class"));
            Assert.Equal("Class", mr.GetName("CLASS"));

            Assert.Equal("Class", mr.GetName("$class"));
            Assert.Equal("Class", mr.GetName("(class)"));
            Assert.Equal("Class", mr.GetName("(class)"));
            Assert.Equal("Classid", mr.GetName("class id"));
            Assert.Equal("Classid", mr.GetName("class  id"));
            Assert.Equal("ClassId", mr.GetName("class/id"));
            Assert.Equal("ClassId", mr.GetName("class\\id"));

            Assert.Equal("ClassId", mr.GetName("class_id"));
            Assert.Equal("ClassId", mr.GetName("CLASS_ID"));
        }

        [Fact]
        public void UnderlineTest()
        {
            var mr = new ModelResolver
            {
                Underline = true
            };

            Assert.Equal("Class", mr.GetName("class"));
            Assert.Equal("Class", mr.GetName("CLASS"));

            Assert.Equal("Class", mr.GetName("$class"));
            Assert.Equal("Class", mr.GetName("(class)"));
            Assert.Equal("Class", mr.GetName("(class)"));
            Assert.Equal("Classid", mr.GetName("class id"));
            Assert.Equal("Classid", mr.GetName("class  id"));
            Assert.Equal("Class_id", mr.GetName("class/id"));
            Assert.Equal("Class_id", mr.GetName("class\\id"));

            Assert.Equal("Class_id", mr.GetName("class_id"));
            Assert.Equal("Class_id", mr.GetName("CLASS_ID"));
        }

        [Fact]
        public void CamelTest()
        {
            var mr = new ModelResolver
            {
                Camel = false
            };

            Assert.Equal("class", mr.GetName("class"));
            Assert.Equal("CLASS", mr.GetName("CLASS"));

            Assert.Equal("class", mr.GetName("$class"));
            Assert.Equal("class", mr.GetName("(class)"));
            Assert.Equal("class", mr.GetName("(class)"));
            Assert.Equal("classid", mr.GetName("class id"));
            Assert.Equal("classid", mr.GetName("class  id"));
            Assert.Equal("classid", mr.GetName("class/id"));
            Assert.Equal("classid", mr.GetName("class\\id"));

            Assert.Equal("classid", mr.GetName("class_id"));
            Assert.Equal("CLASSID", mr.GetName("CLASS_ID"));
        }

        [Fact]
        public void UnderlineCamelTest()
        {
            var mr = new ModelResolver
            {
                Underline = true,
                Camel = false
            };

            Assert.Equal("class", mr.GetName("class"));
            Assert.Equal("CLASS", mr.GetName("CLASS"));

            Assert.Equal("class", mr.GetName("$class"));
            Assert.Equal("class", mr.GetName("(class)"));
            Assert.Equal("class", mr.GetName("(class)"));
            Assert.Equal("classid", mr.GetName("class id"));
            Assert.Equal("classid", mr.GetName("class  id"));
            Assert.Equal("class_id", mr.GetName("class/id"));
            Assert.Equal("class_id", mr.GetName("class\\id"));

            Assert.Equal("class_id", mr.GetName("class_id"));
            Assert.Equal("CLASS_ID", mr.GetName("CLASS_ID"));
        }
    }
}