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 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))); }