Beispiel #1
0
        public void SerializeAndDeserialize_WhenSpriteIsNotNull()
        {
            // Arrange
            var texture       = Substitute.For <ITexture>();
            var sprite        = new Sprite(texture, Vector2.Zero, Vector2.Zero, Vector2.Zero, 0);
            var spriteAssetId = AssetId.CreateUnique();

            var component = new SpriteRendererComponent
            {
                Visible          = false,
                SortingLayerName = "Some sorting layer",
                OrderInLayer     = 2,
                Sprite           = sprite
            };

            AssetStore.GetAssetId(sprite).Returns(spriteAssetId);
            AssetStore.GetAsset <Sprite>(spriteAssetId).Returns(sprite);

            // Act
            var actual = SerializeAndDeserialize(component);

            // Assert
            Assert.That(actual.Visible, Is.EqualTo(component.Visible));
            Assert.That(actual.SortingLayerName, Is.EqualTo(component.SortingLayerName));
            Assert.That(actual.OrderInLayer, Is.EqualTo(component.OrderInLayer));
            Assert.That(actual.Sprite, Is.EqualTo(sprite));
        }
        public void SerializeAndDeserialize_WhenInputMappingIsNotNull()
        {
            // Arrange
            var inputMapping        = new InputMapping();
            var inputMappingAssetId = AssetId.CreateUnique();

            var component = new InputComponent
            {
                InputMapping = inputMapping
            };

            AssetStore.GetAssetId(inputMapping).Returns(inputMappingAssetId);
            AssetStore.GetAsset <InputMapping>(inputMappingAssetId).Returns(inputMapping);

            // Act
            var actual = SerializeAndDeserialize(component);

            // Assert
            Assert.That(actual.InputMapping, Is.EqualTo(inputMapping));
            Assert.That(actual.HardwareInput, Is.EqualTo(HardwareInput.Empty));
            Assert.That(actual.ActionBindings, Is.Empty);
            Assert.That(actual.AxisBindings, Is.Empty);
            Assert.That(actual.ActionStates, Is.Empty);
            Assert.That(actual.AxisStates, Is.Empty);
        }
Beispiel #3
0
        public void SerializeAndDeserialize_WhenCurrentAnimationIsNull()
        {
            // Arrange
            var animation        = CreateAnimation();
            var animationAssetId = AssetId.CreateUnique();

            var component = new SpriteAnimationComponent();

            component.AddAnimation("animation", animation);
            component.Position      = 0.7;
            component.PlaybackSpeed = 1.3;
            component.PlayInLoop    = true;

            AssetStore.GetAssetId(animation).Returns(animationAssetId);
            AssetStore.GetAsset <SpriteAnimation>(animationAssetId).Returns(animation);

            // Act
            var actual = SerializeAndDeserialize(component);

            // Assert
            Assert.That(actual.Animations, Has.Count.EqualTo(1));
            Assert.That(actual.Animations.Single().Key, Is.EqualTo("animation"));
            Assert.That(actual.Animations.Single().Value, Is.EqualTo(animation));
            Assert.That(actual.CurrentAnimation, Is.Null);
            Assert.That(actual.IsPlaying, Is.False);
            Assert.That(actual.Position, Is.EqualTo(component.Position));
            Assert.That(actual.PlaybackSpeed, Is.EqualTo(component.PlaybackSpeed));
            Assert.That(actual.PlayInLoop, Is.EqualTo(component.PlayInLoop));
        }
Beispiel #4
0
        public void SerializeAndDeserialize_WhenSoundIsNotNull()
        {
            // Arrange
            var sound        = Substitute.For <ISound>();
            var soundAssetId = AssetId.CreateUnique();

            var component = new AudioSourceComponent
            {
                Sound     = sound,
                IsPlaying = true
            };

            AssetStore.GetAssetId(sound).Returns(soundAssetId);
            AssetStore.GetAsset <ISound>(soundAssetId).Returns(sound);

            // Act
            var actual = SerializeAndDeserialize(component);

            // Assert
            Assert.That(actual.Sound, Is.EqualTo(sound));
            Assert.That(actual.IsPlaying, Is.True);
        }