using System;
using System.Collections.Generic;
using CncModels.Entity;
using CncService;
using CncWebApi.Controllers;
using Xunit;
namespace CncWebApi.Tests
{
///
/// ScreenConfigController单元测试
/// 大屏卡片配置 + 筛选配置
///
[Collection("Database")]
public class ScreenConfigControllerTests
{
private readonly ScreenConfigController _controller;
public ScreenConfigControllerTests()
{
TestDb.TruncateAll();
_controller = ControllerFactory.CreateScreenConfigController();
}
#region 卡片配置
#region GetConfigs - 配置列表
///
/// 测试:空数据库返回空配置列表
///
[Fact]
public void GetConfigs_EmptyDb_ShouldReturnEmpty()
{
var result = _controller.GetConfigs();
var response = ControllerFactory.Extract>(result);
ControllerFactory.AssertSuccess(response);
Assert.NotNull(response.Data);
}
#endregion
#region UpdateConfig - 编辑卡片
///
/// 测试:编辑卡片配置成功
///
[Fact]
public void UpdateConfig_ValidEntity_ShouldSuccess()
{
// 先插入一条配置
int configId = InsertScreenConfig("test_card", "测试卡片");
var result = _controller.UpdateConfig(configId, new ScreenConfig
{
CardKey = "test_card",
CardType = "stat",
Title = "已改名",
Metric = "count",
SortOrder = 1,
IsEnabled = 1
});
ControllerFactory.AssertSuccess(ControllerFactory.Extract