public void CorrectlyReturnsTheRightValue_WhenSetViaSetValueMethod()
            {
                var observableObject = new CustomObject();
                dynamic dynamicObservableObject = observableObject;

                // Setting value via SetValue method, getting via dynamic property and via GetValue<T> method.
                DateTime dt = DateTime.ParseExact("2016-01-01 01:01:01", "yyyy-MM-dd HH:mm:ss", null);
                observableObject.SetValue("Property1", "test");
                observableObject.SetValue("Property2", 100);
                observableObject.SetValue("Property3", 3.14F);
                observableObject.SetValue("Property4", 1.2M);
                observableObject.SetValue("Property5", dt);

                Assert.AreEqual("test", dynamicObservableObject.Property1);
                Assert.AreEqual(100, dynamicObservableObject.Property2);
                Assert.AreEqual(3.14F, dynamicObservableObject.Property3);
                Assert.AreEqual(1.2M, dynamicObservableObject.Property4);
                Assert.AreEqual(dt, dynamicObservableObject.Property5);

                Assert.AreEqual("test", observableObject.GetValue<string>("Property1"));
                Assert.AreEqual(100, observableObject.GetValue<int>("Property2"));
                Assert.AreEqual(3.14F, observableObject.GetValue<float>("Property3"));
                Assert.AreEqual(1.2M, observableObject.GetValue<decimal>("Property4"));
                Assert.AreEqual(dt, observableObject.GetValue<DateTime>("Property5"));
            }
            public void CorrectlyReturnsTheRightValue_WhenSetViaSetValueMethod()
            {
                var     observableObject        = new CustomObject();
                dynamic dynamicObservableObject = observableObject;

                // Setting value via SetValue method, getting via dynamic property and via GetValue<T> method.
                DateTime dt = DateTime.ParseExact("2016-01-01 01:01:01", "yyyy-MM-dd HH:mm:ss", null);

                observableObject.SetValue("Property1", "test");
                observableObject.SetValue("Property2", 100);
                observableObject.SetValue("Property3", 3.14F);
                observableObject.SetValue("Property4", 1.2M);
                observableObject.SetValue("Property5", dt);

                Assert.AreEqual("test", dynamicObservableObject.Property1);
                Assert.AreEqual(100, dynamicObservableObject.Property2);
                Assert.AreEqual(3.14F, dynamicObservableObject.Property3);
                Assert.AreEqual(1.2M, dynamicObservableObject.Property4);
                Assert.AreEqual(dt, dynamicObservableObject.Property5);

                Assert.AreEqual("test", observableObject.GetValue <string>("Property1"));
                Assert.AreEqual(100, observableObject.GetValue <int>("Property2"));
                Assert.AreEqual(3.14F, observableObject.GetValue <float>("Property3"));
                Assert.AreEqual(1.2M, observableObject.GetValue <decimal>("Property4"));
                Assert.AreEqual(dt, observableObject.GetValue <DateTime>("Property5"));
            }
            public void CorrectlyReturnsTheDefaultValue_WhenNotSet()
            {
                var     observableObject        = new CustomObject();
                dynamic dynamicObservableObject = observableObject;

                Assert.AreEqual(null, observableObject.GetValue <string>("Property1"));
                Assert.AreEqual(0, observableObject.GetValue <int>("Property2"));
                Assert.AreEqual(0F, observableObject.GetValue <float>("Property3"));
                Assert.AreEqual(0M, observableObject.GetValue <decimal>("Property4"));
                Assert.AreEqual(DateTime.MinValue, observableObject.GetValue <DateTime>("Property5"));
                //
                Assert.AreEqual(null, observableObject.GetValue <string>("Property1"));
                Assert.AreEqual(null, observableObject.GetValue <int?>("Property2"));
                Assert.AreEqual(null, observableObject.GetValue <float?>("Property3"));
                Assert.AreEqual(null, observableObject.GetValue <decimal?>("Property4"));
                Assert.AreEqual(null, observableObject.GetValue <DateTime?>("Property5"));
            }
Example #4
0
 public override void SendAction(ViewActionType actionType, CustomObject data)
 {
     switch (actionType)
     {
     case ViewActionType.LevelNumUpdate:
         _levelText.text = string.Format(_levelTemplate, data.GetValue <int>());
         break;
     }
 }
            public void CorrectlyReturnsTheDefaultValue_WhenNotSet()
            {
                var observableObject = new CustomObject();
                dynamic dynamicObservableObject = observableObject;

                Assert.AreEqual(null, observableObject.GetValue<string>("Property1"));
                Assert.AreEqual(0, observableObject.GetValue<int>("Property2"));
                Assert.AreEqual(0F, observableObject.GetValue<float>("Property3"));
                Assert.AreEqual(0M, observableObject.GetValue<decimal>("Property4"));
                Assert.AreEqual(DateTime.MinValue, observableObject.GetValue<DateTime>("Property5"));
                //
                Assert.AreEqual(null, observableObject.GetValue<string>("Property1"));
                Assert.AreEqual(null, observableObject.GetValue<int?>("Property2"));
                Assert.AreEqual(null, observableObject.GetValue<float?>("Property3"));
                Assert.AreEqual(null, observableObject.GetValue<decimal?>("Property4"));
                Assert.AreEqual(null, observableObject.GetValue<DateTime?>("Property5"));
            }