Architectural sovereignty means business logic rules its own territory: databases and frameworks do not dictate how the core works. Boundaries between the core and outside systems let other parts change without rewriting that logic. section 5.5.4
A ServerMonitor core can be driven by different adapters:
- A web API controller calls CheckTemperature(). section 5.5.4
- An admin CLI uses a ConsoleAdapter for a health check. section 5.5.4
- A scheduled background job uses a KafkaAdapter to monitor servers. section 5.5.4
Keeping the core independent makes tests fast and deterministic, and contains changes—such as an external API change—within an adapter rather than spreading them into business rules. section 5.5.4
Listing 5.8 “After”: Unit Tests
// 1. The Fake lives OUTSIDE the test method
class FakeAlertPort : IAlertPort
{
public List<string> SentMessages { get; } = new List<string>();
public void SendAlert(string message) => SentMessages.Add(message);
}
[TestClass]
public class ServerMonitorTests
{
public void ServerOverheating_SendsAlert_ExactlyOnce()
{
// Arrange: Use a simple "Fake" adapter (just a list!)
var fakePort = new FakeAlertPort();
var monitor = new ServerMonitor(fakePort);
// Act: Poke the core
monitor.CheckTemperature(100); #A
// Assert: Verify the OUTCOME, not the implementation
Assert.AreEqual(1, fakePort.SentMessages.Count); #B
Assert.IsTrue(fakePort.SentMessages[0].Contains("Take cover!"));
}
}A unit test uses a fake alert port to check the outcome of the core’s behavior. section 5.5.4
