public void Serialize_and_Deserialize_SceneWithEntityWithComponentAccessingAssetStoreDuringSerialization()
        {
            // Arrange
            var entity = new Entity();
            var componentToSerialize = new AssetStoreTestComponent();

            entity.AddComponent(componentToSerialize);

            var scene = TestSceneFactory.Create();

            scene.AddEntity(entity);

            _componentFactoryProvider.Get(ComponentId.Of <AssetStoreTestComponent>()).Returns(new AssetStoreTestComponent.Factory());

            // Act
            var actual = SerializeAndDeserialize(scene);

            // Assert
            Assert.That(componentToSerialize.SerializeAssetStore, Is.EqualTo(_assetStore));
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.RootEntities, Has.Count.EqualTo(1));
            var actualEntity = actual.RootEntities.Single();

            Assert.That(actualEntity.Components, Has.Count.EqualTo(1));
            var deserializedComponent = actualEntity.Components.ElementAt(0);

            Assert.That(deserializedComponent, Is.TypeOf <AssetStoreTestComponent>());
            Assert.That(((AssetStoreTestComponent)deserializedComponent).DeserializeAssetStore, Is.EqualTo(_assetStore));
        }
Пример #2
0
        public void Of_ShouldReturnComponentIdEqualComponentIdAttribute_GivenComponentTypeWithComponentIdAttribute()
        {
            // Arrange
            // Act
            var actual = ComponentId.Of(typeof(ComponentWithCustomId));

            // Assert
            Assert.That(actual, Is.EqualTo(new ComponentId("Custom Component Id")));
        }
Пример #3
0
        public void Of_ShouldReturnComponentIdEqualComponentTypeFullName_GivenComponentTypeWithoutComponentIdAttribute()
        {
            // Arrange
            // Act
            var actual = ComponentId.Of(typeof(ComponentWithoutCustomId));

            // Assert
            Assert.That(actual, Is.EqualTo(new ComponentId(typeof(ComponentWithoutCustomId).FullName ?? throw new InvalidOperationException())));
        }
Пример #4
0
        public void Of_ShouldReturnComponentIdEqualComponentIdAttribute_GivenComponentTypeGenericParameterWithComponentIdAttribute()
        {
            // Arrange
            // Act
            var actual = ComponentId.Of <ComponentWithCustomId>();

            // Assert
            Assert.That(actual, Is.EqualTo(new ComponentId("Custom Component Id")));
        }
Пример #5
0
        public void Of_ShouldReturnTheSameComponentIdTwice_TryToTestCache()
        {
            // Arrange
            // Act
            var actual1 = ComponentId.Of(typeof(ComponentWithCustomId));
            var actual2 = ComponentId.Of(typeof(ComponentWithCustomId));

            // Assert
            Assert.That(actual1, Is.EqualTo(actual2));
        }
        public void Serialize_and_Deserialize_SceneWithEntityWithComponents()
        {
            // Arrange
            var entity = new Entity();

            entity.AddComponent(new TestComponentA {
                DataA = "Data A"
            });
            entity.AddComponent(new TestComponentB {
                DataB = "Data B"
            });
            entity.AddComponent(new TestComponentC {
                DataC = "Data C"
            });

            var scene = TestSceneFactory.Create();

            scene.AddEntity(entity);

            _componentFactoryProvider.Get(ComponentId.Of <TestComponentA>()).Returns(new TestComponentA.Factory());
            _componentFactoryProvider.Get(ComponentId.Of <TestComponentB>()).Returns(new TestComponentB.Factory());
            _componentFactoryProvider.Get(ComponentId.Of <TestComponentC>()).Returns(new TestComponentC.Factory());

            // Act
            var actual = SerializeAndDeserialize(scene);

            // Assert
            Assert.That(actual, Is.Not.Null);
            Assert.That(actual.RootEntities, Has.Count.EqualTo(1));
            var actualEntity = actual.RootEntities.Single();

            Assert.That(actualEntity.Components, Has.Count.EqualTo(3));
            var actualComponent1 = actualEntity.Components.ElementAt(0);
            var actualComponent2 = actualEntity.Components.ElementAt(1);
            var actualComponent3 = actualEntity.Components.ElementAt(2);

            Assert.That(actualComponent1, Is.TypeOf <TestComponentA>());
            Assert.That(actualComponent2, Is.TypeOf <TestComponentB>());
            Assert.That(actualComponent3, Is.TypeOf <TestComponentC>());
            Assert.That(((TestComponentA)actualComponent1).DataA, Is.EqualTo("Data A"));
            Assert.That(((TestComponentB)actualComponent2).DataB, Is.EqualTo("Data B"));
            Assert.That(((TestComponentC)actualComponent3).DataC, Is.EqualTo("Data C"));
        }