示例#1
0
        /// <summary>
        ///Ein Test für "CreateAccessor"
        ///</summary>
        public void CreateAccessorTestHelper()
        {
            var           tweener = new GenericTweenerImpl <int>();
            PrivateObject param0  = new PrivateObject(tweener, new PrivateType(typeof(GenericTweener <int>)));
            var           target  = new GenericTweener_Accessor <int>(param0);
            var           obj     = new TweeningTestObject();

            // test creation of field accessor
            var propOps = new PropertyOps("IntValue", 0, false);

            target.CreateAccessor(obj, propOps);
            Console.WriteLine("t " + tweener.GetAccessor());
            Assert.IsInstanceOfType(
                tweener.GetAccessor(),
                typeof(FieldAccessor <int>)
                );

            // test creation of field accessor
            propOps = new PropertyOps("IntProperty", 0, false);
            target.CreateAccessor(obj, propOps);
            Console.WriteLine("t " + tweener.GetAccessor());
            Assert.IsInstanceOfType(
                tweener.GetAccessor(),
                typeof(PropertyAccessor <int>)
                );
        }
示例#2
0
        /// <summary>
        ///Ein Test für "Ease"
        ///</summary>
        public void EaseTestHelper2 <TValueType>()
        {
            var target  = new SimpleTweenerImpl <TValueType>();
            var obj     = new TweeningTestObject();
            var propOps = new PropertyOps("FloatValue", 100, false).EaseEx(EaseEx.InElastic, new object[] { 0.3F, 0.3F });

            target.Create(obj, propOps);

            var param0   = new PrivateObject(target);
            var accessor = new SimpleTweener_Accessor <TValueType>(param0);

            // assert that only the EaseFunc is set and not EaseEx
            Assert.IsNull(accessor.EaseFunc);
            Assert.IsNotNull(accessor.EaseExFunc);
            Assert.IsNotNull(accessor.EaseExParams);

            var startValue = 100F;
            var deltaValue = 200F;

            Console.WriteLine("ret " + accessor.Ease(0F, startValue, deltaValue).GetType());
            var actual = accessor.Ease(0F, startValue, deltaValue);

            Assert.AreEqual(100, actual);

            actual = accessor.Ease(1F, startValue, deltaValue);
            Assert.AreEqual(300, actual);
        }
示例#3
0
        public override void Create(object obj, PropertyOps propOps)
        {
            // create the accessor
            CreateAccessor(obj, propOps);

            base.Create(obj, propOps);
        }
示例#4
0
        public void EaseExTest()
        {
            // setup object
            const string propertyName = "IntValue";
            object       targetValue  = 200;
            const bool   isRelative   = false;
            var          target       = new PropertyOps(propertyName, targetValue, isRelative);

            // set ease func and look if it is really getting set
            EaseExFunction easeExFunc = EaseEx.InElastic;
            var            easeParams = new object[] { 10, 20, 30 };

            // also test chaining
            var ret = target.EaseEx(easeExFunc, easeParams);

            Assert.AreEqual(target, ret);

            EaseExFunction expectedEaseFunc = easeExFunc;
            EaseExFunction actualEaseFunc   = target.EaseExFunc;

            Assert.AreEqual(actualEaseFunc, expectedEaseFunc);

            var expectedEaseParams = easeParams;
            var actualEaseParams   = target.EaseExParams;

            Assert.AreEqual(expectedEaseParams, actualEaseParams);
            Assert.AreEqual(3, actualEaseParams.Length);
        }
示例#5
0
        public void PropTest()
        {
            var target   = new TweenOps();
            var ops1     = new PropertyOps("ops1", 100, false);
            var ops2     = new PropertyOps("ops2", 200, true);
            var ops3     = new PropertyOps("ops3", 300, new DoubleTweener(), false);
            var expected = target;
            var actual   = target.Prop(ops1).Prop(ops2).Prop(ops3);

            // test chaining
            Assert.AreEqual(expected, actual);

            // test if PropertyOps are added
            Assert.AreEqual(3, target.PropertyOpses.Count);

            Assert.AreEqual("ops1", target.PropertyOpses[0].PropertyName);
            Assert.AreEqual(100, target.PropertyOpses[0].TargetValue);
            Assert.IsFalse(target.PropertyOpses[0].IsRelative);
            Assert.IsNull(target.PropertyOpses[0].Tweener);

            Assert.AreEqual("ops2", target.PropertyOpses[1].PropertyName);
            Assert.AreEqual(200, target.PropertyOpses[1].TargetValue);
            Assert.IsTrue(target.PropertyOpses[1].IsRelative);
            Assert.IsNull(target.PropertyOpses[1].Tweener);

            Assert.AreEqual(300, target.PropertyOpses[2].TargetValue);
            Assert.AreEqual("ops3", target.PropertyOpses[2].PropertyName);
            Assert.IsInstanceOfType(target.PropertyOpses[2].Tweener, typeof(DoubleTweener));
        }
示例#6
0
        protected ITweenSharkTweener CreateTweener(PropertyOps propertyOps)
        {
            // we can have tweens that need a accessor to be created
            // if ne tweener is given we assume we need to create an accessor
            if (propertyOps.Tweener == null)
            {
                return(CreateTweenerWithAccessor(propertyOps));
            }

            return(propertyOps.Tweener);
        }
示例#7
0
        /// <summary>
        ///Ein Test für "GetSubPropertyName"
        ///</summary>
        public void GetSubPropertyNameTestHelper <TValueType>()
        {
            var target  = new SimpleTweenerImpl <TValueType>();
            var obj     = new TweeningTestObject();
            var propOps = new PropertyOps("FloatValue", 100, false);

            target.Create(obj, propOps);
            string       actual   = target.GetSubPropertyName();
            const string expected = "";

            Assert.AreEqual(expected, actual);
        }
示例#8
0
        public void PropertyOpsConstructorTest()
        {
            const string propertyName = "TestProperty";
            object       targetValue  = 123F;
            const bool   isRelative   = true;
            var          target       = new PropertyOps(propertyName, targetValue, isRelative);

            Assert.AreEqual(target.PropertyName, propertyName);
            Assert.AreEqual(target.TargetValue, targetValue);
            Assert.AreEqual(target.Tweener, null);
            Assert.AreEqual(target.IsRelative, isRelative);
        }
示例#9
0
        public void PropertyOpsConstructorTest1()
        {
            const string       propertyName = "OtherTestProperty";
            object             targetValue  = 1000;
            ITweenSharkTweener tweener      = new UnsignedInt32Tweener();
            const bool         isRelative   = false;
            var target = new PropertyOps(propertyName, targetValue, tweener, isRelative);

            Assert.AreEqual(target.PropertyName, propertyName);
            Assert.AreEqual(target.TargetValue, targetValue);
            Assert.AreEqual(target.Tweener, tweener);
            Assert.AreEqual(target.IsRelative, isRelative);
        }
示例#10
0
        public virtual void Create(object obj, PropertyOps propOps)
        {
            Obj          = obj;
            PropOps      = propOps;
            EaseFunc     = propOps.EaseFunc;
            EaseExFunc   = propOps.EaseExFunc;
            EaseExParams = propOps.EaseExParams;

            if (EaseFunc == null && EaseExFunc == null)
            {
                EaseFunc = TweenSharkPkg.Ease.Linear;
            }

            CalculateAndSetValueDelegate = CalculateAndSetValue;

            Setup();
            Init();
        }
示例#11
0
        /// <summary>
        ///Ein Test für "Create"
        ///</summary>
        public void CreateTestHelper <TValueType>()
        {
            var          target               = CreateSimpleTweener <TValueType>();
            var          obj                  = new TweeningTestObject();
            const string propertyName         = "GenericValue";
            const int    targetValueContained = 100;
            var          targetValue          = new GenericParameterHelper(targetValueContained);
            const bool   isRelative           = true;
            var          propOps              = new PropertyOps(propertyName, targetValue, isRelative);

            target.Create(obj, propOps);

            var param0   = new PrivateObject(target);
            var accessor = new SimpleTweener_Accessor <TValueType>(param0);

            Assert.AreEqual(propertyName, accessor.PropOps.PropertyName);
            Assert.AreEqual(targetValue, accessor.PropOps.TargetValue);
            Assert.AreEqual(targetValueContained, ((GenericParameterHelper)accessor.PropOps.TargetValue).Data);
            Assert.AreEqual(isRelative, accessor.PropOps.IsRelative);
        }
示例#12
0
        public void EaseTest()
        {
            // setup object
            const string propertyName = "IntValue";
            object       targetValue  = 200;
            const bool   isRelative   = false;
            var          target       = new PropertyOps(propertyName, targetValue, isRelative);

            // set ease func and look if it is really getting set
            EaseFunction easeFunc = Ease.Linear;
            EaseFunction expected = easeFunc;

            // also test chaining
            var ret = target.Ease(easeFunc);

            Assert.AreEqual(target, ret);

            EaseFunction actual = target.EaseFunc;

            Assert.AreEqual(actual, expected);
        }
示例#13
0
        /// <summary>
        ///Ein Test für "GetValue"
        ///</summary>
        public void GetValueTestHelper()
        {
            var           tweener = new GenericTweenerImpl <int>();
            PrivateObject param0  = new PrivateObject(tweener, new PrivateType(typeof(GenericTweener <int>)));
            var           target  = new GenericTweener_Accessor <int>(param0);
            var           obj     = new TweeningTestObject()
            {
                IntValue = 100, IntProperty = 200
            };

            var propOps = new PropertyOps("IntValue", 0, false);

            target.CreateAccessor(obj, propOps);
            int actual = target.GetValue();

            Assert.AreEqual(100, actual);

            propOps = new PropertyOps("IntProperty", 0, false);
            target.CreateAccessor(obj, propOps);
            actual = target.GetValue();
            Assert.AreEqual(200, actual);
        }
示例#14
0
        //
        //Sie können beim Verfassen Ihrer Tests die folgenden zusätzlichen Attribute verwenden:
        //
        //Mit ClassInitialize führen Sie Code aus, bevor Sie den ersten Test in der Klasse ausführen.
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Mit ClassCleanup führen Sie Code aus, nachdem alle Tests in einer Klasse ausgeführt wurden.
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Mit TestInitialize können Sie vor jedem einzelnen Test Code ausführen.
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Mit TestCleanup können Sie nach jedem einzelnen Test Code ausführen.
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///Ein Test für "Create"
        ///</summary>
        public void CreateTestHelper <TValueType>()
        {
            var          target               = CreateGenericTweener <TValueType>();
            var          obj                  = new TweeningTestObject();
            const string propertyName         = "GenericValue";
            const int    targetValueContained = 100;
            var          targetValue          = new GenericParameterHelper(targetValueContained);
            const bool   isRelative           = true;
            var          propOps              = new PropertyOps(propertyName, targetValue, isRelative);

            target.Create(obj, propOps);

            PrivateObject param0 = new PrivateObject(target);
            GenericTweener_Accessor <TValueType> accessor = new GenericTweener_Accessor <TValueType>(param0); // TODO: Passenden Wert initialisieren


//            Assert.AreEqual(propertyName, accessor.PropertyName);
//            Assert.AreEqual(targetValue, accessor.TargetValue);
//            Assert.AreEqual(targetValueContained, ((GenericParameterHelper) accessor.TargetValue).Data);
//            Assert.AreEqual(isRelative, accessor.IsRelative);
//            Assert.AreEqual(createAccessor, accessor.CreateAccessor);
        }
示例#15
0
        public void StartTest()
        {
            // setup object
            const string propertyName = "IntValue";
            object       targetValue  = 200;
            const bool   isRelative   = false;
            var          target       = new PropertyOps(propertyName, targetValue, isRelative);

            // expect the StartValue to be Null when is was not set
            Assert.AreEqual(target.StartValue, null);

            // set a start value and check if it is there
            object startValue = 100;
            object expected   = 100;
            object actual;

            // also test chaining
            var ret = target.Start(startValue);

            Assert.AreEqual(target, ret);

            actual = target.StartValue;
            Assert.AreEqual(expected, actual);
        }
示例#16
0
        private void CreateAccessor(object obj, PropertyOps propOps)
        {
            var type = obj.GetType();

            var fieldInfo = type.GetField(propOps.PropertyName);

            if (fieldInfo != null)
            {
                _accessor = new FieldAccessor <TValueType>(obj, fieldInfo);
            }
            else
            {
                var propertyInfo = type.GetProperty(propOps.PropertyName);
                if (propertyInfo != null)
                {
                    _accessor = new PropertyAccessor <TValueType>(obj, propertyInfo);
                }
            }

            if (_accessor == null)
            {
                TweenShark.Logger.Error("Obj " + obj + " has no field or property " + propOps.PropertyName);
            }
        }
示例#17
0
        protected ITweenSharkTweener CreateTweenerWithAccessor(PropertyOps propertyOps)
        {
            // this is the instance of the tweener that will be created
            ITweenSharkTweener tweener = null;

            string propertyName = propertyOps.PropertyName;

            // look inside the given object
            var type = Obj.GetType();

            // for the type of the tweened property
            Type fieldType = null;

            // check if it a field or a property
            FieldInfo fieldInfo = type.GetField(propertyName);

            if (fieldInfo != null)
            {
                fieldType = fieldInfo.FieldType;
            }
            else
            {
                PropertyInfo propertyInfo = type.GetProperty(propertyName);
                if (propertyInfo != null)
                {
                    fieldType = propertyInfo.PropertyType;
                }
            }

            // could we find a property or a field?
            if (fieldType != null && fieldType.FullName != null)
            {
                // yes we could

                // try to determine the tweener type
                // do we have a tweener for this type?
                Type tweenerType;

                RegisteredPropertyTweens.TryGetValue(fieldType.FullName, out tweenerType);

                if (tweenerType != null)
                {
                    try
                    {
                        tweener = (ITweenSharkTweener)Activator.CreateInstance(tweenerType);
                    }
                    catch (Exception e)
                    {
                        TweenShark.Logger.Error("Could not instantiate Tweener " + tweenerType.FullName + " for " + Obj + "::" + propertyName + " which is of type " + fieldType.FullName + " - " + e.Message);
                    }
                }
                else
                {
                    TweenShark.Logger.Error("No tweener found for " + Obj + "::" + propertyName + " which is of type " + fieldType.FullName);
                }
            }
            else
            {
                TweenShark.Logger.Error("obj " + Obj + " has no field or property " + propertyName);
            }

            return(tweener);
        }