Clean Architecture Demo
Toggle main menu visibility
Loading...
Searching...
No Matches
StabilityTests.cs
Go to the documentation of this file.
1
using
ArchUnitNET.Loader;
2
using
Ucu.Andis.ArchitectureMetrics;
3
4
namespace
TaskManagement.Architecture.Tests
;
5
6
[TestFixture]
7
public
class
StabilityMetricsTests
8
{
9
private
static
readonly ArchUnitNET.Domain.Architecture Architecture =
new
ArchLoader()
10
.LoadAssemblies(
11
typeof(
TaskManagement
.
Domain
.
Entities
.
TaskItem
).Assembly,
12
typeof(
TaskManagement
.
Application
.
Commands
.
CreateTaskInteractor
).Assembly,
13
typeof(
TaskManagement
.
Infrastructure
.
Persistence
.
Repositories
.
TaskRepository
).Assembly,
14
typeof(
TaskManagement
.
API
.
Controllers
.
TasksController
).Assembly
15
)
16
.Build();
17
33
[Test]
34
public
void
DisplayAllComponentMetrics
()
35
{
36
var components =
37
MetricsCalculator.BuildAssemblyComponents(
38
Architecture,
39
"TaskManagement.Domain"
,
40
"TaskManagement.Application"
,
41
"TaskManagement.Infrastructure"
,
42
"TaskManagement.API"
);
43
44
var metrics =
45
MetricsCalculator.CalculateMetrics(components);
46
47
TestContext.Out.WriteLine(
"\n=== Métricas de componentes ==="
);
48
TestContext.Out.WriteLine(
49
"{0,-40} {1,6} {2,6} {3,11} {4,12} {5,10}"
,
50
"Componente"
,
"FanIn"
,
"FanOut"
,
"Abstracción"
,
"Inestabilidad"
,
"Distancia"
);
51
52
TestContext.Out.WriteLine(
new
string
(
'-'
, 95));
53
54
foreach
(var metric
in
metrics.OrderBy(m => m.Name))
55
{
56
TestContext.Out.WriteLine(
57
"{0,-40} {1,6} {2,6} {3,11:F4} {4,12:F4} {5,10:F4}"
,
58
metric.Name,
59
metric.FanIn,
60
metric.FanOut,
61
metric.Abstractness,
62
metric.Instability,
63
metric.Distance);
64
}
65
}
66
79
[Test]
80
public
void
Domain_Should_Remain_Stable
()
81
{
82
var components =
83
MetricsCalculator.BuildAssemblyComponents(
84
Architecture,
85
"TaskManagement.Domain"
,
86
"TaskManagement.Application"
,
87
"TaskManagement.Infrastructure"
,
88
"TaskManagement.API"
);
89
90
var metrics =
91
MetricsCalculator.CalculateMetrics(components);
92
93
var domain =
94
metrics.Single(
95
m => m.Name ==
"TaskManagement.Domain"
);
96
97
Assert.That(domain.Instability,
98
Is.LessThan(0.3));
99
100
Assert.That(domain.Distance,
101
Is.LessThan(0.8));
102
}
103
117
[Test]
118
public
void
Application_Should_Be_Balanced
()
119
{
120
var components =
121
MetricsCalculator.BuildAssemblyComponents(
122
Architecture,
123
"TaskManagement.Domain"
,
124
"TaskManagement.Application"
,
125
"TaskManagement.Infrastructure"
,
126
"TaskManagement.API"
);
127
128
var metrics =
129
MetricsCalculator.CalculateMetrics(components);
130
131
var application =
132
metrics.Single(
133
m => m.Name ==
"TaskManagement.Application"
);
134
135
// Application layer should have moderate dependencies
136
Assert.That(application.Instability,
137
Is.LessThan(0.6),
138
"Application should be relatively stable (I < 0.6)"
);
139
140
// Application layer distance should be acceptable
141
Assert.That(application.Distance,
142
Is.LessThan(0.7),
143
"Application should be close to main sequence (D < 0.7)"
);
144
}
145
159
[Test]
160
public
void
Infrastructure_Should_Be_Dependent
()
161
{
162
var components =
163
MetricsCalculator.BuildAssemblyComponents(
164
Architecture,
165
"TaskManagement.Domain"
,
166
"TaskManagement.Application"
,
167
"TaskManagement.Infrastructure"
,
168
"TaskManagement.API"
);
169
170
var metrics =
171
MetricsCalculator.CalculateMetrics(components);
172
173
var infrastructure =
174
metrics.Single(
175
m => m.Name ==
"TaskManagement.Infrastructure"
);
176
177
// Infrastructure should be highly dependent (leaf layer)
178
Assert.That(infrastructure.Instability,
179
Is.GreaterThan(0.8),
180
"Infrastructure should be highly dependent (I > 0.8)"
);
181
182
// Infrastructure should be on the main sequence
183
Assert.That(infrastructure.Distance,
184
Is.LessThan(0.2),
185
"Infrastructure should be on main sequence (D < 0.2)"
);
186
}
187
201
[Test]
202
public
void
API_Should_Be_Dependent
()
203
{
204
var components =
205
MetricsCalculator.BuildAssemblyComponents(
206
Architecture,
207
"TaskManagement.Domain"
,
208
"TaskManagement.Application"
,
209
"TaskManagement.Infrastructure"
,
210
"TaskManagement.API"
);
211
212
var metrics =
213
MetricsCalculator.CalculateMetrics(components);
214
215
var api =
216
metrics.Single(
217
m => m.Name ==
"TaskManagement.API"
);
218
219
// API/Presentation should be highly dependent (leaf layer)
220
Assert.That(api.Instability,
221
Is.GreaterThan(0.8),
222
"API should be highly dependent (I > 0.8)"
);
223
224
// API should be on the main sequence
225
Assert.That(api.Distance,
226
Is.LessThan(0.2),
227
"API should be on main sequence (D < 0.2)"
);
228
}
229
}
TaskManagement.API.Controllers.TasksController
TasksController es el endpoint de la API REST para operaciones de gestión de tareas.
Definition
TasksController.cs:42
TaskManagement.Application.Commands.CreateTaskInteractor
CreateTaskInteractor implementa el caso de uso de crear una tarea.
Definition
CreateTaskInteractor.cs:30
TaskManagement.Architecture.Tests.StabilityMetricsTests
Definition
StabilityTests.cs:8
TaskManagement.Architecture.Tests.StabilityMetricsTests.Application_Should_Be_Balanced
void Application_Should_Be_Balanced()
Valida que la capa Application tenga características equilibradas.
Definition
StabilityTests.cs:118
TaskManagement.Architecture.Tests.StabilityMetricsTests.API_Should_Be_Dependent
void API_Should_Be_Dependent()
Valida que la capa API cumpla el rol de capa de presentación dependiente.
Definition
StabilityTests.cs:202
TaskManagement.Architecture.Tests.StabilityMetricsTests.Domain_Should_Remain_Stable
void Domain_Should_Remain_Stable()
Valida que la capa Domain mantenga características de estabilidad esperadas.
Definition
StabilityTests.cs:80
TaskManagement.Architecture.Tests.StabilityMetricsTests.DisplayAllComponentMetrics
void DisplayAllComponentMetrics()
Muestra todas las métricas de estabilidad de los componentes de la arquitectura.
Definition
StabilityTests.cs:34
TaskManagement.Architecture.Tests.StabilityMetricsTests.Infrastructure_Should_Be_Dependent
void Infrastructure_Should_Be_Dependent()
Valida que la capa Infrastructure cumpla el rol de capa dependiente.
Definition
StabilityTests.cs:160
TaskManagement.Domain.Entities.TaskItem
TaskItem es una entidad del dominio que representa una tarea en el sistema.
Definition
TaskItem.cs:51
TaskManagement.Infrastructure.Persistence.Repositories.TaskRepository
TaskRepository es el repositorio de escritura para entidades TaskItem.
Definition
TaskRepository.cs:55
TaskManagement.API.Controllers
Definition
TasksController.cs:11
TaskManagement.API
Definition
TasksController.cs:11
TaskManagement.Application.Commands
Definition
CompleteTaskInput.cs:1
TaskManagement.Application
Definition
CompleteTaskInput.cs:1
TaskManagement.Architecture.Tests
Definition
ArchitectureTests.cs:5
TaskManagement.Domain.Entities
Definition
TaskItem.cs:4
TaskManagement.Domain
Definition
Result.cs:2
TaskManagement.Infrastructure.Persistence.Repositories
Definition
TaskReadRepository.cs:9
TaskManagement.Infrastructure.Persistence
Definition
TaskConfiguration.cs:6
TaskManagement.Infrastructure
Definition
LoggingEmailService.cs:4
TaskManagement
Definition
TasksController.cs:11
test
TaskManagement.Architecture.Tests
StabilityTests.cs
Generated by
1.18.0