Skip to content

Commit 8035dd5

Browse files
committed
Add test for ISerializableComponent
1 parent dd22f0b commit 8035dd5

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

test/Serialization.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using System.Collections.Generic;
23
using System.IO;
34
using System.Linq;
@@ -45,7 +46,7 @@ public void RoundTripEntity()
4546
Assert.That(newScene.Count, Is.EqualTo(1));
4647

4748
var newEntity = newScene.Single();
48-
Assert.That(newEntity.GetComponentsUnsafe().Count(), Is.EqualTo(1));
49+
AssertEntityHasComponents(newEntity, typeof(NameComp));
4950
Assert.That(newEntity.Get<NameComp>().Name, Is.EqualTo("MyEntity"));
5051
}
5152

@@ -69,7 +70,29 @@ public void RoundTripEntityReference()
6970
Entity.CurrentScene = newScene;
7071
var newA = newScene.Where(e => e.Get<NameComp>().Name == "a").Single();
7172
var newB = newScene.Where(e => e.Get<NameComp>().Name == "b").Single();
73+
AssertEntityHasComponents(newA, typeof(NameComp), typeof(EntityReferenceComp));
74+
AssertEntityHasComponents(newB, typeof(NameComp));
7275
Assert.That(newA.Get<EntityReferenceComp>().Other, Is.EqualTo(newB));
7376
}
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+
}
7497
}
7598
}

0 commit comments

Comments
 (0)