-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuilders.rs
More file actions
55 lines (45 loc) · 1.81 KB
/
Copy pathbuilders.rs
File metadata and controls
55 lines (45 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//! Test builders for Destroy Command
//!
//! This module provides test builders that simplify test setup by managing
//! dependencies and lifecycle for `DestroyCommandHandler` tests.
use std::sync::Arc;
use tempfile::TempDir;
use crate::application::command_handlers::destroy::DestroyCommandHandler;
/// Test builder for `DestroyCommandHandler` that manages dependencies and lifecycle
///
/// This builder simplifies test setup by:
/// - Managing `TempDir` lifecycle
/// - Providing sensible defaults for all dependencies
/// - Allowing selective customization of dependencies
/// - Returning only the command handler and necessary test artifacts
pub struct DestroyCommandHandlerTestBuilder {
temp_dir: TempDir,
}
impl DestroyCommandHandlerTestBuilder {
/// Create a new test builder with default configuration
#[must_use]
pub fn new() -> Self {
let temp_dir = TempDir::new().expect("Failed to create temp dir");
Self { temp_dir }
}
/// Build the `DestroyCommandHandler` with all dependencies
///
/// Returns: (`command_handler`, `temp_dir`)
/// The `temp_dir` must be kept alive for the duration of the test.
pub fn build(self) -> (DestroyCommandHandler, TempDir) {
let repository_factory =
crate::infrastructure::persistence::repository_factory::RepositoryFactory::new(
std::time::Duration::from_secs(30),
);
let repository = repository_factory.create(self.temp_dir.path().to_path_buf());
// Create a system clock for testing
let clock = Arc::new(crate::shared::SystemClock);
let command_handler = DestroyCommandHandler::new(repository, clock);
(command_handler, self.temp_dir)
}
}
impl Default for DestroyCommandHandlerTestBuilder {
fn default() -> Self {
Self::new()
}
}