XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEExtension.NetCore.ServerInteractive

[DLL] Server interaction extension, including user identity verification and querying in conjunction with AutoConfig

公开
关注 0 Fork 0 Star 0
UTF-8
using XFEExtension.NetCore.AutoConfig;
using XFEExtension.NetCore.CyberComm;
using XFEExtension.NetCore.ServerInteractive.TServer.Profiles;
using Xunit;

namespace XFEExtension.NetCore.ServerInteractive.Test;

public sealed class ServerProfileTests
{
    [Fact]
    public void ServerProfileRoundTripsThroughAutoConfig()
    {
        var directory = Path.Combine(Path.GetTempPath(), "XFEServerProfileTests", Guid.NewGuid().ToString("N"));
        var originalPath = ServerProfile.ProfilePath;
        var originalExtension = ServerProfile.ProfileExtension;
        var originalCurrent = ServerProfile.Current;
        try
        {
            ServerProfile.ProfilePath = Path.Combine(directory, nameof(ServerProfile));
            ServerProfile.ProfileExtension = string.Empty;
            ServerProfile.Current = new ServerProfile();
            ServerProfile.ListenUrls = new ProfileList<string>(["http://127.0.0.1:4301/"]);
            ServerProfile.ShutdownTimeoutSeconds = 23;
            ServerProfile.TransportLimits = new CyberCommLimitOptions
            {
                MaxConnections = 321,
                MaxConnectionsPerIp = 21,
                CloseTimeout = TimeSpan.FromSeconds(7)
            };
            ServerProfile.SaveProfile();

            Assert.True(File.Exists(Path.Combine(directory, $"{nameof(ServerProfile)}.xpf")));

            ServerProfile.Current = new ServerProfile();
            ServerProfile.LoadProfile();

            Assert.Equal(["http://127.0.0.1:4301/"], ServerProfile.ListenUrls);
            Assert.Equal(23, ServerProfile.ShutdownTimeoutSeconds);
            Assert.Equal(321, ServerProfile.TransportLimits.MaxConnections);
            Assert.Equal(21, ServerProfile.TransportLimits.MaxConnectionsPerIp);
            Assert.Equal(TimeSpan.FromSeconds(7), ServerProfile.CreateTransportLimits().CloseTimeout);
        }
        finally
        {
            ServerProfile.ProfilePath = originalPath;
            ServerProfile.ProfileExtension = originalExtension;
            ServerProfile.Current = originalCurrent;
            if (Directory.Exists(directory))
                Directory.Delete(directory, true);
        }
    }
}