Skip to content

Commit

Permalink
- Adds support for element groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Feb 15, 2021
1 parent edc4232 commit ba4bcdf
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 1 deletion.
51 changes: 51 additions & 0 deletions Structurizr.Core.Tests/Model/GroupableElementTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Xunit;

namespace Structurizr.Core.Tests
{

public class GroupableElementTests : AbstractTestBase
{

[Fact]
public void Test_getGroup_ReturnsNullByDefault()
{
Person element = Model.AddPerson("Person");
Assert.Null(element.Group);
}

[Fact]
public void Test_setGroup()
{
Person element = Model.AddPerson("Person");
element.Group = "Group";
Assert.Equal("Group", element.Group);
}

[Fact]
public void Test_setGroup_TrimsWhiteSpace()
{
Person element = Model.AddPerson("Person");
element.Group = " Group ";
Assert.Equal("Group", element.Group);
}

[Fact]
public void Test_setGroup_HandlesEmptyAndNullValues()
{
Person element = Model.AddPerson("Person");
element.Group = "Group";

element.Group = null;
Assert.Null(element.Group);

element.Group = "Group";
element.Group = "";
Assert.Null(element.Group);

element.Group = "Group";
element.Group = " ";
Assert.Null(element.Group);
}

}
}
42 changes: 42 additions & 0 deletions Structurizr.Core/Model/GroupableElement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Runtime.Serialization;

namespace Structurizr
{

public abstract class GroupableElement : Element
{

private string _group;

/// <summary>
/// The name of the group in which this element should be included in.
/// </summary>
[DataMember(Name = "group", EmitDefaultValue = false)]
public string Group
{
get
{
return _group;
}

set
{
if (value == null)
{
_group = null;
}
else {
_group = value.Trim();

if (String.IsNullOrEmpty(_group))
{
_group = null;
}
}
}
}

}

}
2 changes: 1 addition & 1 deletion Structurizr.Core/Model/StaticStructureElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/// This is the superclass for model elements that describe the static structure
/// of a software system, namely Person, SoftwareSystem, Container and Component.
/// </summary>
public abstract class StaticStructureElement : Element
public abstract class StaticStructureElement : GroupableElement
{

/// <summary>
Expand Down
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.0.0 (unreleased)

- Improved the support for creating [implied relationships](docs/implied-relationships.md).
- Adds support for element groups.
## 0.9.7 (29th June 2020)

- Added an ExternalSoftwareSystemBoundariesVisible property to ContainerView, to set whether software system boundaries should be visible for "external" containers (those outside the software system in scope).
Expand Down

0 comments on commit ba4bcdf

Please sign in to comment.