public void ShouldImplementIList()
        {
            var property         = new AnimatableProperty <float>();
            var compositionChain = AnimationCompositionChain <float> .Create(property, SingleTraits.Instance);

            var list = (IList <AnimationInstance>)compositionChain;
            var animationInstance0 = AnimationInstance <float> .Create(new SingleFromToByAnimation());

            var animationInstance1 = AnimationInstance <float> .Create(new SingleFromToByAnimation());

            var animationInstance2 = AnimationInstance <float> .Create(new SingleFromToByAnimation());

            var wrongInstance = AnimationInstance.Create(new TimelineGroup());

            // The enumerator is not implemented (to prevent garbage).
            Assert.That(() => { list.GetEnumerator(); }, Throws.TypeOf <NotImplementedException>());

            // Add
            Assert.That(() => list.Add(wrongInstance), Throws.ArgumentException);
            list.Add(animationInstance0);

            // Contains
            Assert.IsTrue(list.Contains(animationInstance0));
            Assert.IsFalse(list.Contains(animationInstance1));
            Assert.IsFalse(list.Contains(wrongInstance));

            // IndexOf
            Assert.AreEqual(0, list.IndexOf(animationInstance0));
            Assert.AreEqual(-1, list.IndexOf(animationInstance1));
            Assert.AreEqual(-1, list.IndexOf(wrongInstance));

            // IsReadOnly
            Assert.IsFalse(list.IsReadOnly);

            // Insert
            list.Insert(1, animationInstance1);
            Assert.That(() => list.Insert(0, wrongInstance), Throws.ArgumentException);

            // Indexer
            Assert.AreEqual(animationInstance1, list[1]);
            list[0] = animationInstance2;
            Assert.That(() => list[0] = wrongInstance, Throws.ArgumentException);

            // CopyTo
            AnimationInstance[] array = new AnimationInstance[2];
            list.CopyTo(array, 0);
            Assert.AreEqual(animationInstance2, array[0]);
            Assert.AreEqual(animationInstance1, array[1]);

            // Remove
            Assert.IsTrue(list.Remove(animationInstance2));
            Assert.AreEqual(1, list.Count);
            Assert.IsFalse(list.Remove(wrongInstance));

            // RemoveAt
            list.RemoveAt(0);
            Assert.AreEqual(0, list.Count);
        }
Пример #2
0
        AnimationInstance ITimeline.CreateInstance()
        {
            if (!IsFrozen)
            {
                throw new AnimationException("This animation is not frozen. Freeze() must be called before the animation can be used.");
            }

            return(AnimationInstance <SkeletonPose> .Create(this));
        }