namespace NavisworksTransport.UnitTests
{
    /// <summary>
    /// UIStateManager基础功能测试
    /// 只包含可以在控制台环境下稳定运行的纯逻辑测试
    /// </summary>
    [TestClass]
    public class UIStateManagerBasicTests
    {
        private UIStateManager _uiStateManager;

        [TestInitialize]
        public void Setup()
        {
            _uiStateManager = UIStateManager.Instance;
        }

        [TestCleanup]
        public void Cleanup()
        {
            // 不释放单例UIStateManager
        }

        #region 单例模式测试

        [TestMethod]
        public void Instance_ShouldReturnSameInstanceForMultipleCalls()
        {
            // Arrange & Act
            var instance1 = UIStateManager.Instance;
            var instance2 = UIStateManager.Instance;

            // Assert
            Assert.AreSame(instance1, instance2, "UIStateManager应该返回相同的单例实例");
        }

        [TestMethod]
        public void Instance_ShouldNotBeNull()
        {
            // Arrange & Act
            var instance = UIStateManager.Instance;

            // Assert
            Assert.IsNotNull(instance, "UIStateManager实例不应该为null");
        }

        #endregion

        #region 基础属性测试

        [TestMethod]
        public void PendingOperationsCount_ShouldBeNonNegative()
        {
            // Arrange & Act
            var count = _uiStateManager.PendingOperationsCount;

            // Assert
            Assert.IsTrue(count >= 0, "待处理操作数量应该是非负数");
        }

        #endregion

        #region 队列管理基础测试

        [TestMethod]
        public void QueueUIUpdate_WithNullOperation_ShouldNotThrow()
        {
            // Act & Assert
            // 传入null操作不应该抛出异常，应该被安全忽略
            _uiStateManager.QueueUIUpdate(null);
            Assert.IsTrue(true, "传入null的队列操作应该被安全忽略");
        }

        [TestMethod]
        public void QueueUIUpdate_WithValidOperation_ShouldAccept()
        {
            // Arrange
            var executed = false;

            // Act
            _uiStateManager.QueueUIUpdate(() => executed = true);

            // Assert
            // 这里主要验证方法调用不会抛出异常
            Assert.IsTrue(true, "有效的队列操作应该被接受");
        }

        [TestMethod]
        public void ClearUpdateQueue_ShouldNotThrow()
        {
            // Arrange
            _uiStateManager.QueueUIUpdate(() => { });

            // Act & Assert
            _uiStateManager.ClearUpdateQueue();
            Assert.IsTrue(true, "清空队列操作应该成功完成");
        }

        #endregion

        #region 优先级测试

        [TestMethod]
        public void QueueUIUpdate_WithPriority_ShouldAcceptOperation()
        {
            // Act & Assert
            _uiStateManager.QueueUIUpdate(() => { }, UIUpdatePriority.High);
            _uiStateManager.QueueUIUpdate(() => { }, UIUpdatePriority.Normal);
            _uiStateManager.QueueUIUpdate(() => { }, UIUpdatePriority.Low);
            _uiStateManager.QueueUIUpdate(() => { }, UIUpdatePriority.Critical);
            
            Assert.IsTrue(true, "所有优先级的队列操作都应该被接受");
        }

        #endregion
    }
}