public void WhenValuesAreEqual_ShouldDoNothing() { bool val1 = true, val2 = val1; var demo = new DemoModel(); using (demo.CreatePropertyChangedObservable().Subscribe(_ => throw new InvalidOperationException())) { demo.SetPropertyAndNotify(ref val1, val2, "Test"); } Assert.Equal(val1, val2); }
public void WhenSomeArgumentsAreInvalid_ShouldNotifyAboutValidElements() { var expectedResults = this.argument_forTest2.Where(name => !string.IsNullOrWhiteSpace(name)); var results = new List <string>(expectedResults.Count()); var model = new DemoModel(); using (model.CreatePropertyChangedObservable().Subscribe(name => results.Add(name))) { model.RaisePropertiesChanged(this.argument_forTest2); } Assert.Equal(expectedResults, results); }
public void WhenArgumentIsNull_ShouldDoNothing() { var model = new DemoModel(); object result = null; object testValue = new object(); using (model.CreatePropertyChangedObservable() .Subscribe(name => result = testValue)) { model.RaisePropertiesChanged(argument_forTest1); } Assert.Null(result); }
public void WhenValuesAreEqual_ShouldDoNothing() { int val1 = 2, val2 = val1; var demo = new DemoModel(); using (demo.CreatePropertyChangedObservable().Subscribe(_ => throw new InvalidOperationException())) { demo.SetPropertyAndNotifyMany(ref val1, val2, " ", "", null, "example"); } string[] nullArray = null; demo.SetPropertyAndNotifyMany(ref val1, val2, nullArray); Assert.Equal(val1, val2); }
public void WhenValuesAreNotEqualAndSomePropertyNamesAreNotEmpty_ShouldSetValueAndNotifyAboutNotEmptyElements() { object val1 = "val1"; object val2 = "val2"; var demo = new DemoModel(); var testedValues = new string[] { "Name", " Name1 ds", null, "", " " }; var expectedValues = testedValues.Where(name => !string.IsNullOrWhiteSpace(name)); var results = new List <string>(); using (demo.CreatePropertyChangedObservable().Subscribe(name => results.Add(name))) { demo.SetPropertyAndNotifyMany(ref val2, val1, testedValues); } Assert.Equal(val1, val2); Assert.Equal(expectedValues, results); }
public void WhenValuesAreNotEqual_PropertyNamesInTestCases_ShouldSetValueAndNotifyAboutValidElements(string propertyName, bool shouldRaiseEvent) { object val1 = "val1"; object val2 = "val2"; var demo = new DemoModel(); if (shouldRaiseEvent) { Assert.PropertyChanged(demo, propertyName, () => demo.SetPropertyAndNotify(ref val2, val1, propertyName)); } else { using (demo.CreatePropertyChangedObservable().Subscribe(_ => throw new InvalidOperationException())) { demo.SetPropertyAndNotify(ref val2, val1, propertyName); } } Assert.Equal(val1, val2); }