add all crates: domain, protocol, application, client, adapters, ESP32 firmware
Server: domain (entities, value objects, ports), protocol (postcard wire types), application (config service, data projection), adapters (config-memory, tcp-server), bootstrap (composition root with fake data). Client: client-domain (layout engine, render tree, HAL ports), client-application (message handling, repaint commands), adapters (tcp-client, display-terminal), client-desktop (end-to-end working). ESP32: client-esp32 firmware with ILI9341 display over SPI, WiFi networking. Display test verified on hardware — landscape orientation, text rendering works. 60 workspace tests, all passing.
This commit is contained in:
126
crates/application/tests/support/mod.rs
Normal file
126
crates/application/tests/support/mod.rs
Normal file
@@ -0,0 +1,126 @@
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashMap;
|
||||
use domain::{
|
||||
ConfigRepository, EventPublisher,
|
||||
DataSource, DataSourceId, Layout, LayoutPreset, LayoutPresetId,
|
||||
WidgetConfig, WidgetId, DomainEvent,
|
||||
};
|
||||
|
||||
pub struct InMemoryConfigRepository {
|
||||
pub widgets: RefCell<HashMap<WidgetId, WidgetConfig>>,
|
||||
pub data_sources: RefCell<HashMap<DataSourceId, DataSource>>,
|
||||
pub layout: RefCell<Option<Layout>>,
|
||||
pub presets: RefCell<HashMap<LayoutPresetId, LayoutPreset>>,
|
||||
}
|
||||
|
||||
impl InMemoryConfigRepository {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
widgets: RefCell::new(HashMap::new()),
|
||||
data_sources: RefCell::new(HashMap::new()),
|
||||
layout: RefCell::new(None),
|
||||
presets: RefCell::new(HashMap::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Never;
|
||||
|
||||
impl std::fmt::Display for Never {
|
||||
fn fmt(&self, _: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
impl ConfigRepository for InMemoryConfigRepository {
|
||||
type Error = Never;
|
||||
|
||||
async fn get_widget(&self, id: WidgetId) -> Result<Option<WidgetConfig>, Self::Error> {
|
||||
Ok(self.widgets.borrow().get(&id).cloned())
|
||||
}
|
||||
|
||||
async fn list_widgets(&self) -> Result<Vec<WidgetConfig>, Self::Error> {
|
||||
Ok(self.widgets.borrow().values().cloned().collect())
|
||||
}
|
||||
|
||||
async fn save_widget(&self, config: &WidgetConfig) -> Result<(), Self::Error> {
|
||||
self.widgets.borrow_mut().insert(config.id, config.clone());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete_widget(&self, id: WidgetId) -> Result<(), Self::Error> {
|
||||
self.widgets.borrow_mut().remove(&id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_data_source(&self, id: DataSourceId) -> Result<Option<DataSource>, Self::Error> {
|
||||
Ok(self.data_sources.borrow().get(&id).cloned())
|
||||
}
|
||||
|
||||
async fn list_data_sources(&self) -> Result<Vec<DataSource>, Self::Error> {
|
||||
Ok(self.data_sources.borrow().values().cloned().collect())
|
||||
}
|
||||
|
||||
async fn save_data_source(&self, source: &DataSource) -> Result<(), Self::Error> {
|
||||
self.data_sources.borrow_mut().insert(source.id, source.clone());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete_data_source(&self, id: DataSourceId) -> Result<(), Self::Error> {
|
||||
self.data_sources.borrow_mut().remove(&id);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_layout(&self) -> Result<Option<Layout>, Self::Error> {
|
||||
Ok(self.layout.borrow().clone())
|
||||
}
|
||||
|
||||
async fn save_layout(&self, layout: &Layout) -> Result<(), Self::Error> {
|
||||
*self.layout.borrow_mut() = Some(layout.clone());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_preset(&self, id: LayoutPresetId) -> Result<Option<LayoutPreset>, Self::Error> {
|
||||
Ok(self.presets.borrow().get(&id).cloned())
|
||||
}
|
||||
|
||||
async fn list_presets(&self) -> Result<Vec<LayoutPreset>, Self::Error> {
|
||||
Ok(self.presets.borrow().values().cloned().collect())
|
||||
}
|
||||
|
||||
async fn save_preset(&self, preset: &LayoutPreset) -> Result<(), Self::Error> {
|
||||
self.presets.borrow_mut().insert(preset.id, preset.clone());
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn delete_preset(&self, id: LayoutPresetId) -> Result<(), Self::Error> {
|
||||
self.presets.borrow_mut().remove(&id);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InMemoryEventPublisher {
|
||||
pub events: RefCell<Vec<DomainEvent>>,
|
||||
}
|
||||
|
||||
impl InMemoryEventPublisher {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
events: RefCell::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn emitted(&self) -> Vec<DomainEvent> {
|
||||
self.events.borrow().clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl EventPublisher for InMemoryEventPublisher {
|
||||
type Error = Never;
|
||||
|
||||
async fn publish(&self, event: DomainEvent) -> Result<(), Self::Error> {
|
||||
self.events.borrow_mut().push(event);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user