TestSetPropertyWithBackStoreValueEqualToValueDoesNotSetStoreNorInvokesPropertyChangedEventAndReturnsFalse( [Values("Hello", "", null)] string currentValue) { int invocationCount = 0; int callbackCount = 0; BaseViewModelForTest model = new BaseViewModelForTest(); model.PropertyChanged += (s, a) => { invocationCount++; }; void Callback() { callbackCount++; } string backingStore = currentValue; string value = currentValue; bool valueSet = model.InvokeSetProperty(ref backingStore, value, string.Empty, Callback); Assert.IsFalse(valueSet); Assert.AreEqual(currentValue, backingStore); Assert.AreEqual(0, invocationCount); Assert.AreEqual(0, callbackCount); }
TestSetPropertyWithBackStoreValueNotEqualToValueSetsStoreAndInvokesPropertyChangedEventAndReturnsTrue( [Values("Hello", "", null)] string currentValue, [Values("Hello", "", null)] string newValue, [Values] bool isChangedEventNull, [Values] bool isCallbackNull) { // Not valid test case as expecting values to be different if (currentValue == newValue) { return; } const string propertyName = "Title"; object sender = null; PropertyChangedEventArgs args = null; int invocationCount = 0; int callbackCount = 0; int expectedCount = isChangedEventNull ? 0 : 1; int expectedCallbackCount = isCallbackNull ? 0 : 1; BaseViewModelForTest model = new BaseViewModelForTest(); if (!isChangedEventNull) { model.PropertyChanged += (s, a) => { sender = s; args = a; invocationCount++; }; } void Callback() { callbackCount++; } Action callback = isCallbackNull ? (Action)null : Callback; string backingStore = currentValue; bool valueSet = model.InvokeSetProperty(ref backingStore, newValue, propertyName, callback); Assert.IsTrue(valueSet); Assert.AreEqual(newValue, backingStore); Assert.AreEqual(expectedCount, invocationCount); Assert.AreEqual(expectedCallbackCount, callbackCount); if (!isChangedEventNull) { Assert.IsNotNull(sender); Assert.AreSame(model, sender); Assert.IsNotNull(args); Assert.AreEqual(propertyName, args.PropertyName); } }