93 lines
2.3 KiB
C#
93 lines
2.3 KiB
C#
using AssetManager.Data;
|
|
using AssetManager.Data.Repositories;
|
|
using FluentAssertions;
|
|
using Microsoft.Extensions.Logging;
|
|
using Moq;
|
|
using SqlSugar;
|
|
using Xunit;
|
|
|
|
namespace AssetManager.Tests.Repositories;
|
|
|
|
/// <summary>
|
|
/// PortfolioRepository 单元测试
|
|
/// </summary>
|
|
public class PortfolioRepositoryTests
|
|
{
|
|
private readonly Mock<ISqlSugarClient> _dbMock;
|
|
private readonly Mock<ILogger<PortfolioRepository>> _loggerMock;
|
|
|
|
public PortfolioRepositoryTests()
|
|
{
|
|
_dbMock = new Mock<ISqlSugarClient>();
|
|
_loggerMock = new Mock<ILogger<PortfolioRepository>>();
|
|
}
|
|
|
|
#region GetByIdAsync Tests
|
|
|
|
[Fact(Skip = "需要 SqlSugar 完整 mock 设置")]
|
|
public async Task GetByIdAsync_ExistingPortfolio_ShouldReturnPortfolio()
|
|
{
|
|
// Arrange
|
|
var portfolioId = "port-001";
|
|
var userId = "user-001";
|
|
|
|
// Act
|
|
// var result = await _repo.GetByIdAsync(portfolioId, userId);
|
|
|
|
// Assert
|
|
// result.Should().NotBeNull();
|
|
// result.Id.Should().Be(portfolioId);
|
|
}
|
|
|
|
[Fact(Skip = "需要 SqlSugar 完整 mock 设置")]
|
|
public async Task GetByIdAsync_WrongUser_ShouldReturnNull()
|
|
{
|
|
// Arrange
|
|
var portfolioId = "port-001";
|
|
var wrongUserId = "user-002";
|
|
|
|
// Act
|
|
// var result = await _repo.GetByIdAsync(portfolioId, wrongUserId);
|
|
|
|
// Assert
|
|
// result.Should().BeNull();
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region DeleteAsync Tests
|
|
|
|
[Fact(Skip = "需要 SqlSugar 完整 mock 设置")]
|
|
public async Task DeleteAsync_ShouldDeleteRelatedData()
|
|
{
|
|
// Arrange
|
|
var portfolioId = "port-001";
|
|
var userId = "user-001";
|
|
|
|
// Act
|
|
// var result = await _repo.DeleteAsync(portfolioId, userId);
|
|
|
|
// Assert
|
|
// 验证删除了 Position, Transaction, NavHistory
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region GetTransactionsAsync Tests
|
|
|
|
[Fact(Skip = "需要 SqlSugar 完整 mock 设置")]
|
|
public async Task GetTransactionsAsync_ShouldReturnOrderedByDate()
|
|
{
|
|
// Arrange
|
|
var portfolioId = "port-001";
|
|
|
|
// Act
|
|
// var result = await _repo.GetTransactionsAsync(portfolioId, 10, 0);
|
|
|
|
// Assert
|
|
// result.Should().BeInDescendingOrder(t => t.TransactionTime);
|
|
}
|
|
|
|
#endregion
|
|
}
|