Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit 085f541

Browse files
Fixes a bug where deployment node instances could set to a non-positive integer.
1 parent 5dfec2b commit 085f541

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

Structurizr.Core.Tests/Model/DeploymentNodeTests.cs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,45 @@ public void Test_GetInfrastructureNodeWithName_ReturnsTheNamedDeploymentNode_Whe
221221
Assert.Same(child, parent.GetInfrastructureNodeWithName("child"));
222222
}
223223

224+
[Fact]
225+
public void Test_Instances()
226+
{
227+
DeploymentNode deploymentNode = new DeploymentNode();
228+
deploymentNode.Instances = 8;
229+
230+
Assert.Equal(8, deploymentNode.Instances);
231+
}
232+
233+
[Fact]
234+
public void Test_Instances_ThrowsAnException_WhenZeroIsSpecified()
235+
{
236+
try
237+
{
238+
DeploymentNode deploymentNode = new DeploymentNode();
239+
deploymentNode.Instances = 0;
240+
throw new TestFailedException();
241+
}
242+
catch (ArgumentException ae)
243+
{
244+
Assert.Equal("Number of instances must be a positive integer.", ae.Message);
245+
}
246+
}
247+
248+
[Fact]
249+
public void Test_Instances_ThrowsAnException_WhenANegativeNumberIsSpecified()
250+
{
251+
try
252+
{
253+
DeploymentNode deploymentNode = new DeploymentNode();
254+
deploymentNode.Instances = -1;
255+
throw new TestFailedException();
256+
}
257+
catch (ArgumentException ae)
258+
{
259+
Assert.Equal("Number of instances must be a positive integer.", ae.Message);
260+
}
261+
}
262+
224263
}
225-
264+
226265
}

Structurizr.Core/Model/DeploymentNode.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,26 @@ public override Element Parent
3434
[DataMember(Name = "technology", EmitDefaultValue = false)]
3535
public string Technology { get; set; }
3636

37+
private int _instances = 1;
38+
3739
[DataMember(Name = "instances", EmitDefaultValue = false)]
38-
public int Instances { get; set; }
40+
public int Instances
41+
{
42+
get
43+
{
44+
return _instances;
45+
}
46+
47+
set
48+
{
49+
if (value < 1)
50+
{
51+
throw new ArgumentException("Number of instances must be a positive integer.");
52+
}
53+
54+
_instances = value;
55+
}
56+
}
3957

4058
private HashSet<DeploymentNode> _children;
4159

0 commit comments

Comments
 (0)