1
+ using System ;
1
2
using System . Collections . Generic ;
2
3
using System . IO ;
3
4
using System . Linq ;
@@ -45,7 +46,7 @@ public void RoundTripEntity()
45
46
Assert . That ( newScene . Count , Is . EqualTo ( 1 ) ) ;
46
47
47
48
var newEntity = newScene . Single ( ) ;
48
- Assert . That ( newEntity . GetComponentsUnsafe ( ) . Count ( ) , Is . EqualTo ( 1 ) ) ;
49
+ AssertEntityHasComponents ( newEntity , typeof ( NameComp ) ) ;
49
50
Assert . That ( newEntity . Get < NameComp > ( ) . Name , Is . EqualTo ( "MyEntity" ) ) ;
50
51
}
51
52
@@ -69,7 +70,29 @@ public void RoundTripEntityReference()
69
70
Entity . CurrentScene = newScene ;
70
71
var newA = newScene . Where ( e => e . Get < NameComp > ( ) . Name == "a" ) . Single ( ) ;
71
72
var newB = newScene . Where ( e => e . Get < NameComp > ( ) . Name == "b" ) . Single ( ) ;
73
+ AssertEntityHasComponents ( newA , typeof ( NameComp ) , typeof ( EntityReferenceComp ) ) ;
74
+ AssertEntityHasComponents ( newB , typeof ( NameComp ) ) ;
72
75
Assert . That ( newA . Get < EntityReferenceComp > ( ) . Other , Is . EqualTo ( newB ) ) ;
73
76
}
77
+
78
+ struct NonSerializedComp : IComponent { }
79
+ [ Test ]
80
+ public void IComponentsAreNotSerialized ( )
81
+ {
82
+ Scene scene = new Scene ( ) ;
83
+ Entity entity = scene . CreateEntity ( "MyEntity" ) ;
84
+ entity . Add < NonSerializedComp > ( ) ;
85
+
86
+ var json = SceneJsonSerializer . ToJson ( scene ) ;
87
+ var newScene = SceneJsonSerializer . FromJson ( json ) ;
88
+
89
+ AssertEntityHasComponents ( entity , typeof ( NameComp ) ) ;
90
+ }
91
+ void AssertEntityHasComponents ( Entity entity , params Type [ ] componentTypes )
92
+ {
93
+ Assert . That (
94
+ entity . GetComponentsUnsafe ( ) . Select ( x => x . GetType ( ) ) ,
95
+ Is . EquivalentTo ( componentTypes ) ) ;
96
+ }
74
97
}
75
98
}
0 commit comments