You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
haoliang-net/tests/CncService.Tests/SystemLogServiceTests.cs

57 lines
1.6 KiB
C#

using System;
using CncModels.Constants;
using CncModels.Dto;
using CncModels.Dto.Log;
using CncService;
using CncService.Impl;
using Xunit;
namespace CncService.Tests
{
/// <summary>
/// SystemLogService 系统日志测试
/// 测试场景:分页查询、参数校验
/// </summary>
[Collection("Database")]
public class SystemLogServiceTests : IDisposable
{
private readonly SystemLogService _service;
public SystemLogServiceTests()
{
TestDb.TruncateAll();
_service = ServiceFactory.CreateSystemLogService();
}
public void Dispose()
{
TestDb.TruncateAll();
}
[Fact]
public void GetList__()
{
var result = _service.GetList(new SystemLogQuery { Page = 1, PageSize = 20 });
Assert.NotNull(result);
Assert.Equal(0, result.Total);
}
[Fact]
public void GetList_null_BadRequest()
{
var ex = Assert.Throws<BusinessException>(() => _service.GetList(null));
Assert.Equal(ErrorCode.BadRequest, ex.Code);
}
[Fact]
public void GetList__()
{
TestDb.Execute(@"INSERT INTO log_system (log_level, source, message, stack_trace, extra_data, created_at)
VALUES ('INFO', 'AuthService', '登录系统', '', '{}', NOW())");
var result = _service.GetList(new SystemLogQuery { Page = 1, PageSize = 20 });
Assert.Equal(1, result.Total);
}
}
}