using DramaLing.Api.Models.Entities;
namespace DramaLing.Api.Tests.TestData;
///
/// 測試資料工廠,用於建立測試用的實體物件
///
public static class TestDataFactory
{
///
/// 建立測試用使用者
///
public static User CreateUser(string? email = null, Guid? id = null)
{
return new User
{
Id = id ?? Guid.NewGuid(),
Email = email ?? $"test{Random.Shared.Next(1000, 9999)}@example.com",
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};
}
///
/// 建立測試用單字卡
///
public static Flashcard CreateFlashcard(Guid? userId = null, string? frontText = null, string? backText = null)
{
var user = userId ?? Guid.NewGuid();
return new Flashcard
{
Id = Guid.NewGuid(),
UserId = user,
FrontText = frontText ?? $"Test Front {Random.Shared.Next(100, 999)}",
BackText = backText ?? $"Test Back {Random.Shared.Next(100, 999)}",
IsFavorite = false,
ImageUrl = null,
AudioUrl = null,
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow
};
}
///
/// 建立測試用單字卡列表
///
public static List CreateFlashcards(Guid userId, int count = 5)
{
var flashcards = new List();
for (int i = 0; i < count; i++)
{
flashcards.Add(CreateFlashcard(
userId: userId,
frontText: $"Front Text {i + 1}",
backText: $"Back Text {i + 1}"
));
}
return flashcards;
}
///
/// 建立測試用句子分析快取
///
public static SentenceAnalysisCache CreateAnalysisCache(string sentence, string? result = null)
{
return new SentenceAnalysisCache
{
Id = Guid.NewGuid(),
Sentence = sentence,
AnalysisResult = result ?? $"{{\"analysis\": \"Test analysis for {sentence}\"}}",
CreatedAt = DateTime.UtcNow
};
}
}