Skip to content

Commit 8df396f

Browse files
committed
tests
1 parent 4fd92b5 commit 8df396f

File tree

5 files changed

+90
-9
lines changed

5 files changed

+90
-9
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using ACadSharp.Entities;
2+
using ACadSharp.Objects;
3+
using System;
4+
using Xunit;
5+
6+
namespace ACadSharp.Tests.Objects
7+
{
8+
public class GroupTests : NonGraphicalObjectTests<Group>
9+
{
10+
[Fact]
11+
public void AddTest()
12+
{
13+
CadDocument doc = new CadDocument();
14+
Line l = new Line();
15+
var group = new Group();
16+
17+
group.Add(l);
18+
19+
Assert.Contains(group, l.Reactors);
20+
Assert.Throws<InvalidOperationException>(() => doc.Groups.Add(group));
21+
22+
group.Clear();
23+
24+
Assert.DoesNotContain(group, l.Reactors);
25+
26+
doc.Groups.Add(group);
27+
Assert.Contains(group, doc.Groups);
28+
29+
Assert.Throws<InvalidOperationException>(() => group.Add(l));
30+
31+
doc.Entities.Add(l);
32+
group.Add(l);
33+
34+
Assert.Contains(l, group.Entities);
35+
}
36+
37+
[Fact]
38+
public void IsUnnamedTest()
39+
{
40+
var group = new Group();
41+
42+
Assert.True(group.IsUnnamed);
43+
group.Name = null;
44+
Assert.True(group.IsUnnamed);
45+
group.Name = " ";
46+
Assert.True(group.IsUnnamed);
47+
48+
group.Name = "my_group";
49+
Assert.False(group.IsUnnamed);
50+
}
51+
}
52+
}

src/ACadSharp/CadObject.cs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,7 @@ public IEnumerable<CadObject> Reactors
5959
{
6060
get
6161
{
62-
if (this.Document == null)
63-
{
64-
return Enumerable.Empty<CadObject>();
65-
}
66-
else
67-
{
68-
return this._reactors;
69-
}
62+
return this._reactors;
7063
}
7164
}
7265

src/ACadSharp/Objects/Collections/GroupCollection.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using ACadSharp.Entities;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text.RegularExpressions;
@@ -15,6 +16,14 @@ public GroupCollection(CadDictionary dictionary) : base(dictionary)
1516
/// <inheritdoc/>
1617
public override void Add(Group entry)
1718
{
19+
foreach (var e in entry.Entities)
20+
{
21+
if (e.Document != this._dictionary.Document)
22+
{
23+
throw new InvalidOperationException("Entities in a group must be in the same document as the group being added.");
24+
}
25+
}
26+
1827
if (entry.IsUnnamed)
1928
{
2029
int next = 0;

src/ACadSharp/Objects/Group.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class Group : NonGraphicalObject
3939
/// The name for an unnamed group will be managed by the <see cref="GroupCollection"/>.
4040
/// </remarks>
4141
[DxfCodeValue(70)]
42-
public bool IsUnnamed { get { return !this.Name.IsNullOrWhiteSpace() && this.Name.StartsWith("*"); } }
42+
public bool IsUnnamed { get { return this.Name.IsNullOrWhiteSpace() || this.Name.StartsWith("*"); } }
4343

4444
/// <inheritdoc/>
4545
public override string ObjectName => DxfFileToken.TableGroup;
@@ -95,6 +95,29 @@ public void AddRange(IEnumerable<Entity> entities)
9595
}
9696
}
9797

98+
/// <summary>
99+
/// Removes all entities in the group.
100+
/// </summary>
101+
public void Clear()
102+
{
103+
foreach (var e in this._entities)
104+
{
105+
e.RemoveReactor(this);
106+
}
107+
108+
this._entities.Clear();
109+
}
110+
111+
/// <summary>
112+
/// Removes the entity from the group.
113+
/// </summary>
114+
/// <param name="entity"></param>
115+
public bool Remove(Entity entity)
116+
{
117+
entity.RemoveReactor(this);
118+
return this._entities.Remove(entity);
119+
}
120+
98121
/// <inheritdoc/>
99122
public override CadObject Clone()
100123
{

src/CodeMaid.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@
8282
<value>False</value>
8383
</setting>
8484
<setting name="Cleaning_InsertExplicitAccessModifiersOnProperties"
85+
serializeAs="String">
86+
<value>False</value>
87+
</setting>
88+
<setting name="Cleaning_InsertBlankSpaceBeforeSelfClosingAngleBrackets"
8589
serializeAs="String">
8690
<value>True</value>
8791
</setting>

0 commit comments

Comments
 (0)