use std::sync::Arc;
#[allow(dead_code)]
use allframe_core::arch::{domain, handler, repository, use_case};
#[test]
fn test_domain_has_no_dependencies() {
#[domain]
struct User {
id: String,
email: String,
}
let user = User {
id: "123".to_string(),
email: "user@example.com".to_string(),
};
assert_eq!(user.id, "123");
assert_eq!(user.email, "user@example.com");
}
#[test]
fn test_repository_depends_on_domain() {
#[domain]
struct User {
id: String,
email: String,
}
#[repository]
trait UserRepository: Send + Sync {
fn find(&self, id: &str) -> Option<User>;
}
struct InMemoryUserRepository;
impl UserRepository for InMemoryUserRepository {
fn find(&self, _id: &str) -> Option<User> {
None
}
}
let repo: Arc<dyn UserRepository> = Arc::new(InMemoryUserRepository);
let _ = repo;
assert!(true);
}
#[test]
fn test_use_case_depends_on_repository() {
#[domain]
struct User {
id: String,
email: String,
}
#[repository]
trait UserRepository: Send + Sync {
fn find(&self, id: &str) -> Option<User>;
}
#[use_case]
struct GetUserUseCase {
repo: Arc<dyn UserRepository>,
}
impl GetUserUseCase {
pub fn new(repo: Arc<dyn UserRepository>) -> Self {
Self { repo }
}
}
assert!(true);
}
#[test]
fn test_handler_depends_on_use_case() {
#[domain]
struct User {
id: String,
email: String,
}
#[repository]
trait UserRepository: Send + Sync {
fn find(&self, id: &str) -> Option<User>;
}
#[use_case]
struct GetUserUseCase {
repo: Arc<dyn UserRepository>,
}
#[handler]
struct GetUserHandler {
use_case: Arc<GetUserUseCase>,
}
impl GetUserHandler {
pub fn new(use_case: Arc<GetUserUseCase>) -> Self {
Self { use_case }
}
}
assert!(true);
}
#[test]
fn test_handler_cannot_depend_on_repository() {
assert!(true); }