Exemplo n.º 1
0
        private void AssertDrawTextWithCorrectColor(ColorF expected, ColorF colorValue, AnimationFlags flags)
        {
            const float Divisor  = 255f / 128f;
            var         sequence = new Sequence
            {
                AnimationGroups = new List <Sequence.AnimationGroup>
                {
                    new Sequence.AnimationGroup
                    {
                        Animations = new List <Sequence.Animation>
                        {
                            new Sequence.Animation
                            {
                                FrameEnd   = 100,
                                Flags      = Sequence.CanHostChildFlag,
                                ColorStart = (colorValue / Divisor).ToRgba(),
                                ColorEnd   = (colorValue / Divisor).ToRgba(),
                            }
                        }
                    }
                },
                SpriteGroups = new List <List <Sequence.SpritePart> >
                {
                    new List <Sequence.SpritePart>()
                },
                Sprites = new List <Sequence.Sprite>()
            };

            var drawing         = Extensions.MockDrawing();
            var messageProvider = Substitute.For <IMessageProvider>();
            var messageRenderer = new MockMessageRenderer();
            var messageEncode   = Substitute.For <IMessageEncode>();
            var spriteTexture   = Substitute.For <ISpriteTexture>();
            var factory         = new AnimatedSequenceFactory(
                drawing,
                messageProvider,
                messageRenderer,
                messageEncode,
                sequence,
                spriteTexture);

            messageEncode.Encode(Arg.Is <List <MessageCommandModel> >(x => true))
            .Returns(new byte[] { 0x21 });

            var animation = factory.Create(new AnimatedSequenceDesc
            {
                Flags       = flags,
                MessageText = "test"
            });

            animation.Draw(0, 0);

            expected = ColorF.FromRgba(expected.ToRgba());
            Assert.True(messageRenderer.HasBeenCalled);
            Assert.Equal(expected.R, messageRenderer.LastColor.R, 2);
            Assert.Equal(expected.G, messageRenderer.LastColor.G, 2);
            Assert.Equal(expected.B, messageRenderer.LastColor.B, 2);
            Assert.Equal(expected.A, messageRenderer.LastColor.A, 2);
        }