1- using ACadSharp . Tables ;
1+ using ACadSharp . Extensions ;
2+ using ACadSharp . Tables ;
23using ACadSharp . Tests . Common ;
34using System ;
5+ using System . Reflection ;
46using Xunit ;
57
68namespace ACadSharp . Tests . Tables
@@ -17,6 +19,52 @@ static TableEntryTests()
1719 }
1820 }
1921
22+ [ Fact ( ) ]
23+ public void ChangeName ( )
24+ {
25+ string initialName = "custom_layer" ;
26+ Layer layer = new Layer ( initialName ) ;
27+
28+ CadDocument doc = new CadDocument ( ) ;
29+
30+ doc . Layers . Add ( layer ) ;
31+
32+ layer . Name = "new_name" ;
33+
34+ Assert . NotNull ( doc . Layers [ layer . Name ] ) ;
35+ Assert . False ( doc . Layers . TryGetValue ( initialName , out _ ) ) ;
36+ }
37+
38+ [ Fact ]
39+ public void ChangeNameCloned ( )
40+ {
41+ string initialName = "custom_layer" ;
42+ Layer layer = new Layer ( initialName ) ;
43+
44+ CadDocument doc = new CadDocument ( ) ;
45+
46+ doc . Layers . Add ( layer ) ;
47+
48+ layer . Name = "new_name" ;
49+ layer . OnNameChanged += ( sender , args ) =>
50+ {
51+ throw new Exception ( ) ;
52+ } ;
53+
54+ Layer clone = layer . CloneTyped ( ) ;
55+ clone . Name = "test-event" ;
56+
57+ Assert . ThrowsAny < Exception > ( ( ) => layer . Name = "Hello" ) ;
58+
59+ var field = typeof ( TableEntry )
60+ . GetField ( nameof ( TableEntry . OnNameChanged ) , BindingFlags . Instance | BindingFlags . NonPublic ) ;
61+
62+ var e = field . GetValue ( layer ) as EventHandler < OnNameChangedArgs > ;
63+ Assert . NotEmpty ( e . GetInvocationList ( ) ) ;
64+ e = field . GetValue ( clone ) as EventHandler < OnNameChangedArgs > ;
65+ Assert . Null ( e ) ;
66+ }
67+
2068 [ Theory ]
2169 [ MemberData ( nameof ( TableEntryTypes ) ) ]
2270 public void Clone ( Type entryType )
@@ -27,20 +75,20 @@ public void Clone(Type entryType)
2775 CadObjectTestUtils . AssertTableEntryClone ( entry , clone ) ;
2876 }
2977
30- [ Fact ( ) ]
31- public void ChangeName ( )
78+ [ Fact ]
79+ public void DetachCloneEvents ( )
3280 {
3381 string initialName = "custom_layer" ;
3482 Layer layer = new Layer ( initialName ) ;
3583
3684 CadDocument doc = new CadDocument ( ) ;
37-
3885 doc . Layers . Add ( layer ) ;
3986
40- layer . Name = "new_name" ;
87+ Layer clone = layer . CloneTyped ( ) ;
88+ string name = "new_name" ;
89+ clone . Name = name ;
4190
42- Assert . NotNull ( doc . Layers [ layer . Name ] ) ;
43- Assert . False ( doc . Layers . TryGetValue ( initialName , out _ ) ) ;
91+ Assert . False ( doc . Layers . Contains ( name ) ) ;
4492 }
4593
4694 [ Fact ( ) ]
0 commit comments