public void SetValue_DefalutValue_SameValue()
        {
            var backingFileds = new BackingFields(null);

            backingFileds.SetValue(() => StringProperty, null);
            backingFileds.SetValue(() => IntProperty, 0);
            backingFileds.SetValue(() => DateTimeProperty, default(DateTime));
            backingFileds.SetValue(() => NullableDateTimeProperty, null);
            backingFileds.SetValue(() => StringListProperty, null);
            backingFileds.SetValue(() => ViewModelProperty, null);

            Assert.AreEqual(null, backingFileds.GetValue(() => StringProperty));
            Assert.AreEqual(0, backingFileds.GetValue(() => IntProperty));
            Assert.AreEqual(default(DateTime), backingFileds.GetValue(() => DateTimeProperty));
            Assert.AreEqual(null, backingFileds.GetValue(() => NullableDateTimeProperty));
            Assert.AreEqual(null, backingFileds.GetValue(() => StringListProperty));
            Assert.AreEqual(null, backingFileds.GetValue(() => ViewModelProperty));
        }
        public void GetValue_NotInitialized_DefaultValue()
        {
            var backingFileds = new BackingFields(null);

            Assert.AreEqual(null, backingFileds.GetValue(() => StringProperty));
            Assert.AreEqual(0, backingFileds.GetValue(() => IntProperty));
            Assert.AreEqual(default(DateTime), backingFileds.GetValue(() => DateTimeProperty));
            Assert.AreEqual(null, backingFileds.GetValue(() => NullableDateTimeProperty));
            Assert.AreEqual(null, backingFileds.GetValue(() => StringListProperty));
            Assert.AreEqual(null, backingFileds.GetValue(() => ViewModelProperty));
        }
        public void GetValue_Initialized_SameValue()
        {
            var backingFileds = new BackingFields(null);

            Assert.AreEqual("a", backingFileds.GetValue(() => StringProperty, () => "a"));
            Assert.AreEqual(7, backingFileds.GetValue(() => IntProperty, () => 7));
            Assert.AreEqual(new DateTime(2222, 2, 2), backingFileds.GetValue(() => DateTimeProperty, () => new DateTime(2222, 2, 2)));
            Assert.AreEqual(new DateTime(2345, 6, 7), backingFileds.GetValue(() => NullableDateTimeProperty, () => new DateTime(2345, 6, 7)));
            Assert.AreEqual("b", backingFileds.GetValue(() => StringListProperty, () => new List<string> { "b" })[0]);
            Assert.AreEqual("c", backingFileds.GetValue(() => ViewModelProperty, () => new ViewModel { Value = "c" }).Value);
        }
        public void SetValue_NotDefalutValue_SameValue()
        {
            var backingFileds = new BackingFields(null);

            Assert.IsTrue(backingFileds.SetValue(() => StringProperty, "a"));
            Assert.IsTrue(backingFileds.SetValue(() => IntProperty, 7));
            Assert.IsTrue(backingFileds.SetValue(() => DateTimeProperty, new DateTime(2222, 2, 2)));
            Assert.IsTrue(backingFileds.SetValue(() => NullableDateTimeProperty, new DateTime(2345, 6, 7)));
            Assert.IsTrue(backingFileds.SetValue(() => StringListProperty, new List<string> { "b" }));
            Assert.IsTrue(backingFileds.SetValue(() => ViewModelProperty, new ViewModel { Value = "c" }));

            Assert.AreEqual("a", backingFileds.GetValue(() => StringProperty));
            Assert.AreEqual(7, backingFileds.GetValue(() => IntProperty));
            Assert.AreEqual(new DateTime(2222, 2, 2), backingFileds.GetValue(() => DateTimeProperty));
            Assert.AreEqual(new DateTime(2345, 6, 7), backingFileds.GetValue(() => NullableDateTimeProperty));
            Assert.AreEqual("b", backingFileds.GetValue(() => StringListProperty)[0]);
            Assert.AreEqual("c", backingFileds.GetValue(() => ViewModelProperty).Value);

            Assert.IsFalse(backingFileds.SetValue(() => StringProperty, "a"));
            Assert.IsFalse(backingFileds.SetValue(() => IntProperty, 7));
            Assert.IsFalse(backingFileds.SetValue(() => DateTimeProperty, new DateTime(2222, 2, 2)));
            Assert.IsFalse(backingFileds.SetValue(() => NullableDateTimeProperty, new DateTime(2345, 6, 7)));
            Assert.IsFalse(backingFileds.SetValue(() => StringListProperty, backingFileds.GetValue(() => StringListProperty)));
            Assert.IsFalse(backingFileds.SetValue(() => ViewModelProperty, backingFileds.GetValue(() => ViewModelProperty)));
        }
        public void GetValue_Initialized_OnlyOnce()
        {
            var counter = 0;
            Func<ViewModel> init = () => { counter++; return new ViewModel(); };
            var backingFileds = new BackingFields(null);
            
            backingFileds.GetValue(() => ViewModelProperty, init);
            Assert.AreEqual(1, counter);

            backingFileds.GetValue(() => ViewModelProperty, init);
            Assert.AreEqual(1, counter);
        }