Exemplo n.º 1
0
        public void TestSpriteCompositeDrawWithDefaultValuesAndIdentityTransform()
        {
            var source1 = new RectangleInt(10, 10, 20, 20);
            var source2 = new RectangleInt(40, 40, 30, 30);
            var origin = new Vector(4, 7);

            var expected1 = CreateDrawImageParams(source1, origin, destination: new Rectangle(0, 0, 20, 20));
            var expected2 = CreateDrawImageParams(source2, origin, destination: new Rectangle(0, 0, 30, 30));

            // ARRANGE
            var sprite1 = CreateSprite(source1, origin);
            var sprite2 = CreateSprite(source2, origin);
            var spriteComposite = new SpriteComposite("tata", new[] { sprite1, sprite2 });

            DrawImageParams actual1 = null;
            DrawImageParams actual2 = null;
            var callCount = 0;
            var drawContext = CreateDrawContextMock(p =>
            {
                callCount++;
                if (callCount == 1) actual1 = p;
                if (callCount == 2) actual2 = p;
            });

            // ACT
            spriteComposite.Draw(drawContext.Object, SpriteTransform.SpriteIdentity);

            // ASSERT
            drawContext.VerifyAll();
            Assert.AreEqual(2, callCount);
            AssertDrawImageParamsAreEquals(expected1, actual1);
            AssertDrawImageParamsAreEquals(expected2, actual2);
        }
        public void TestCompositeWithTransform()
        {
            var source = new RectangleInt(10, 10, 20, 20);
            var origin = new Vector(4, 7);

            // ARRANGE
            var spriteSheet = new SpriteSheet(null, "toto");
            var definition = spriteSheet.AddSpriteDefinition("toto", source, origin);
            var transform = new SpriteTransform(translation: new Vector(43, -27), rotation: -1.2f, scale: 5.0f, color: Color.Yellow);
            var template = spriteSheet.AddSpriteCompositeTemplate("tata")
                .AddTemplate(definition, transform);

            var expectedSprite = new Sprite(spriteSheet, "toto")
            {
                Position = new Vector(43, -27),
                Rotation = -1.2f,
                Scale = 5.0f,
                Color = Color.Yellow
            };

            var expected = new SpriteComposite("tata", new[] { expectedSprite });

            // ACT
            var actual = (SpriteComposite)template.CreateInstance();

            // ASSERT
            AssertSprite.CompositeEqual(expected, actual);
        }
        public void TestDefaultValueForEmptyComposite()
        {
            var expected = new SpriteComposite("tata", Enumerable.Empty<SpriteBase>());

            // ARRANGE
            var spriteSheet = new SpriteSheet(null, "toto");
            var template = spriteSheet.AddSpriteCompositeTemplate("tata");

            // ACT
            var actual = (SpriteComposite)template.CreateInstance();

            // ASSERT
            AssertSprite.CompositeEqual(expected, actual);
        }
Exemplo n.º 4
0
        public void TestSpriteCompositeDrawWithChangesButIdentityTransform()
        {
            var source1 = new RectangleInt(10, 10, 20, 20);
            var source2 = new RectangleInt(40, 40, 30, 30);
            var origin = new Vector(4, 7);

            var expected1 = CreateDrawImageParams(source1, origin,
                destination: new Rectangle(12, 8, 10, 10), rotation: 4.2f, color: Color.Red);

            var expected2 = CreateDrawImageParams(source2, origin,
                destination: new Rectangle(12, 8, 15, 15), rotation: 4.2f, color: Color.Red);

            // ARRANGE
            var sprite1 = CreateSprite(source1, origin);
            var sprite2 = CreateSprite(source2, origin);
            var spriteComposite = new SpriteComposite("tata", new[] { sprite1, sprite2 })
            {
                Position = new Vector(12, 8),
                Rotation = 4.2f,
                Scale = 0.5f,
                Color = Color.Red
            };

            DrawImageParams actual1 = null;
            DrawImageParams actual2 = null;
            var callCount = 0;
            var drawContext = CreateDrawContextMock(p =>
            {
                callCount++;
                if (callCount == 1) actual1 = p;
                if (callCount == 2) actual2 = p;
            });

            // ACT
            spriteComposite.Draw(drawContext.Object, SpriteTransform.SpriteIdentity);

            // ASSERT
            drawContext.VerifyAll();
            Assert.AreEqual(2, callCount);
            AssertDrawImageParamsAreEquals(expected1, actual1);
            AssertDrawImageParamsAreEquals(expected2, actual2);
        }
        public void TestComposite()
        {
            var source = new RectangleInt(10, 10, 20, 20);
            var origin = new Vector(4, 7);

            // ARRANGE
            var spriteSheet = new SpriteSheet(null, "toto");
            var definition = spriteSheet.AddSpriteDefinition("toto", source, origin);
            var template = spriteSheet.AddSpriteCompositeTemplate("tata")
                .AddTemplate(definition);

            var expectedSprite = new Sprite(spriteSheet, "toto");
            var expected = new SpriteComposite("tata", new[] { expectedSprite });

            // ACT
            var actual = (SpriteComposite)template.CreateInstance();

            // ASSERT
            AssertSprite.CompositeEqual(expected, actual);
        }
Exemplo n.º 6
0
        public static void CompositeEqual(SpriteComposite expected, SpriteComposite actual, string path = "")
        {
            BaseEqual(expected, actual, path);

            Assert.AreEqual(expected.Children.Count(), actual.Children.Count(), path + "Children count");

            var tuples = expected.Children.OfType<SpriteBase>()
                .Zip(actual.Children.OfType<SpriteBase>(),
                    (e, a) => new Tuple<SpriteBase, SpriteBase>(e, a));

            var index = 0;
            foreach (var tuple in tuples)
            {
                var childPath = "C" + index + " - ";
                Assert.AreEqual(tuple.Item1.GetType(), tuple.Item2.GetType(), childPath + "Child Type");

                ChildSpriteEqual(tuple.Item1, tuple.Item2, childPath);

                index++;
            }
        }