public void MethodCall_ObservableTarget_Update() { var update = false; var dummy = new ObservableDummy <int>() { Item = 23 }; var test = Observable.Expression <string>(() => dummy.Item.ToString()); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual("23", e.OldValue); Assert.AreEqual("42", e.NewValue); }; Assert.AreEqual("23", test.Value); Assert.IsFalse(update); dummy.Item = 42; Assert.IsTrue(update); Assert.AreEqual("42", test.Value); }
public void UnaryPlusChecked_Double_Observable_Updates() { checked { var update = false; var dummy = new ObservableDummy <double>() { Item = 23 }; var test = Observable.Expression <double>(() => + dummy.Item); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual(23, (double)e.OldValue); Assert.AreEqual(42, (double)e.NewValue); }; Assert.AreEqual(23, test.Value); Assert.IsFalse(update); dummy.Item = 42; Assert.IsTrue(update); Assert.AreEqual(42, test.Value); } }
public void ListInit_CustomListObservable_NoUpdateWhenDetached() { var update = false; var dummy = new ObservableDummy <string>("foo"); var test = Observable.Expression(() => new ListFake() { dummy.Item }); test.ValueChanged += (o, e) => update = true; Assert.AreEqual("foo", test.Value.Value); Assert.IsFalse(update); test.Detach(); dummy.Item = "bar"; Assert.IsFalse(update); Assert.AreEqual(string.Empty, test.Value.Value); test.Attach(); Assert.AreEqual("bar", test.Value.Value); dummy.Item = "42"; Assert.AreEqual("42", test.Value.Value); }
public void Cast_String_Observable_Update() { var update = false; var dummy = new ObservableDummy <object>() { Item = "23" }; var test = Observable.Expression <string>(() => (string)dummy.Item); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual("23", e.OldValue); Assert.AreEqual("42", e.NewValue); }; Assert.AreEqual("23", test.Value); Assert.IsFalse(update); dummy.Item = "42"; Assert.IsTrue(update); Assert.AreEqual("42", test.Value); }
public void UnaryMinusChecked_Float_Observable_Updates() { checked { var update = false; var dummy = new ObservableDummy <float>() { Item = 23 }; var test = Observable.Expression <float>(() => - dummy.Item); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual(-23, (float)e.OldValue); Assert.AreEqual(42, (float)e.NewValue); }; Assert.AreEqual(-23, test.Value); Assert.IsFalse(update); dummy.Item = -42; Assert.IsTrue(update); Assert.AreEqual(42, test.Value); } }
public void Cast_String_Observable_NoUpdatesWhenDetached() { var update = false; var dummy = new ObservableDummy <object>() { Item = "23" }; var test = new NotifyValue <string>(() => (string)dummy.Item); test.ValueChanged += (o, e) => update = true; Assert.AreEqual("23", test.Value); Assert.IsFalse(update); test.Detach(); dummy.Item = "42"; Assert.IsFalse(update); test.Attach(); Assert.IsTrue(update); Assert.AreEqual("42", test.Value); update = false; dummy.Item = "1"; Assert.IsTrue(update); }
public void UnaryPlusChecked_Long_Observable_Updates() { checked { var update = false; var dummy = new ObservableDummy <long>() { Item = 23 }; var test = new NotifyValue <long>(() => + dummy.Item); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual(23, (long)e.OldValue); Assert.AreEqual(42, (long)e.NewValue); }; Assert.AreEqual(23, test.Value); Assert.IsFalse(update); dummy.Item = 42; Assert.IsTrue(update); Assert.AreEqual(42, test.Value); } }
public void ConditionalExpression_NoObservableTruePart_NoUpdates() { var update = false; var dummy = new ObservableDummy <bool>() { Item = true }; var dummy2 = new Dummy <string>() { Item = "23" }; var test = new ObservingFunc <Dummy <bool>, string>(d => d.Item ? dummy2.Item : "23"); var result = test.Observe(dummy); result.ValueChanged += (o, e) => update = true; Assert.AreEqual("23", result.Value); Assert.IsFalse(update); dummy2.Item = "42"; Assert.IsFalse(update); }
public void ArrayLongIndexer2d_ObservableIndex_Updates() { var update = false; var coll = new string[, ] { { "23", "42" } }; var dummy = new ObservableDummy <long>(); var test = Observable.Expression <string>(() => coll[0L, dummy.Item]); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual("23", e.OldValue); Assert.AreEqual("42", e.NewValue); }; Assert.AreEqual("23", test.Value); Assert.IsFalse(update); dummy.Item = 1; Assert.IsTrue(update); Assert.AreEqual("42", test.Value); }
public void ConditionalExpression_ObservableFalsePart_Updates() { var update = false; var dummy = new ObservableDummy <bool>() { Item = false }; var dummy2 = new ObservableDummy <string>() { Item = "23" }; var test = new ObservingFunc <Dummy <bool>, string>(d => d.Item ? "23" : dummy2.Item); var result = test.Observe(dummy); result.ValueChanged += (o, e) => { update = true; Assert.AreEqual("23", e.OldValue); Assert.AreEqual("42", e.NewValue); }; Assert.AreEqual("23", result.Value); Assert.IsFalse(update); dummy2.Item = "42"; Assert.IsTrue(update); Assert.AreEqual("42", result.Value); }
public void ConditionalExpression_ObservableTest_NoUpdatesWhenDetached() { var update = false; var dummy = new ObservableDummy <bool>() { Item = false }; var test = new ObservingFunc <Dummy <bool>, string>(d => d.Item ? "42" : "23"); var result = test.Observe(dummy); result.ValueChanged += (o, e) => update = true; Assert.AreEqual("23", result.Value); Assert.IsFalse(update); result.Detach(); dummy.Item = true; Assert.IsFalse(update); result.Attach(); Assert.IsTrue(update); Assert.AreEqual("42", result.Value); update = false; dummy.Item = false; Assert.IsTrue(update); }
public void Add_Decimal_Observable_NoUpdateWhenDetached() { var updated = false; var dummy = new ObservableDummy <decimal>() { Item = 5 }; var result = Observable.Expression(() => dummy.Item + 7); result.ValueChanged += (o, e) => updated = true; Assert.AreEqual(12, result.Value); Assert.IsFalse(updated); result.Detach(); dummy.Item = 35; Assert.AreEqual(12, result.Value); Assert.IsFalse(updated); result.Attach(); Assert.IsTrue(updated); Assert.AreEqual(42, result.Value); updated = false; dummy.Item = 5; Assert.IsTrue(updated); }
public void Add_ULong_Observable_Update() { unchecked { var updated = false; var dummy = new ObservableDummy <ulong>() { Item = 5 }; var result = Observable.Expression(() => dummy.Item + 7); result.ValueChanged += (o, e) => { Assert.AreEqual(12ul, e.OldValue); updated = true; }; Assert.AreEqual(12ul, result.Value); Assert.IsFalse(updated); dummy.Item = 35; Assert.IsTrue(updated); Assert.AreEqual(42ul, result.Value); } }
public void MethodCall_ObservableArgument_Update() { var update = false; var dummy = new ObservableDummy <string>() { Item = "23" }; var test = Observable.Expression <int>(() => int.Parse(dummy.Item)); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual(23, e.OldValue); Assert.AreEqual(42, e.NewValue); }; Assert.AreEqual(23, test.Value); Assert.IsFalse(update); dummy.Item = "42"; Assert.IsTrue(update); Assert.AreEqual(42, test.Value); }
public void MemberExpression_ObservableSourceTargetChanges_Update() { var update = false; var dummy = new ObservableDummy <Dummy <int> >() { Item = new Dummy <int>(23) }; var test = new NotifyValue <int>(() => dummy.Item.Item); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual(23, e.OldValue); Assert.AreEqual(42, e.NewValue); }; Assert.AreEqual(23, test.Value); Assert.IsFalse(update); dummy.Item = new Dummy <int>(42); Assert.IsTrue(update); Assert.AreEqual(42, test.Value); }
public void Indexer_ObservableIndex_Updates() { var update = false; var coll = new List <string>(); coll.Add("23"); coll.Add("42"); var dummy = new ObservableDummy <int>(); var test = Observable.Expression <string>(() => coll[dummy.Item]); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual("23", e.OldValue); Assert.AreEqual("42", e.NewValue); }; Assert.AreEqual("23", test.Value); Assert.IsFalse(update); dummy.Item = 1; Assert.IsTrue(update); Assert.AreEqual("42", test.Value); }
public void UnaryMinusChecked_Double_Observable_Updates() { checked { var update = false; var dummy = new ObservableDummy <double>() { Item = 23 }; var test = new NotifyValue <double>(() => - dummy.Item); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual(-23, (double)e.OldValue); Assert.AreEqual(42, (double)e.NewValue); }; Assert.AreEqual(-23, test.Value); Assert.IsFalse(update); dummy.Item = -42; Assert.IsTrue(update); Assert.AreEqual(42, test.Value); } }
public void Subtract_ULong_Observable_Update() { unchecked { var updated = false; var dummy = new ObservableDummy <ulong>() { Item = 5 }; var test = new ObservingFunc <Dummy <ulong>, ulong>(d => d.Item - 3); var result = test.Observe(dummy); result.ValueChanged += (o, e) => { Assert.AreEqual(2ul, e.OldValue); updated = true; }; Assert.AreEqual(2ul, result.Value); Assert.IsFalse(updated); dummy.Item = 45; Assert.IsTrue(updated); Assert.AreEqual(42ul, result.Value); } }
public void UnaryPlus_Decimal_Observable_Updates() { var update = false; var dummy = new ObservableDummy <decimal>() { Item = 23 }; var test = new NotifyValue <decimal>(() => + dummy.Item); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual(23, (decimal)e.OldValue); Assert.AreEqual(42, (decimal)e.NewValue); }; Assert.AreEqual(23, test.Value); Assert.IsFalse(update); dummy.Item = 42; Assert.IsTrue(update); Assert.AreEqual(42, test.Value); }
public void Subtract_Decimal_Observable_Update() { var updated = false; var dummy = new ObservableDummy <decimal>() { Item = 5 }; var test = new ObservingFunc <Dummy <decimal>, decimal>(d => d.Item - 3); var result = test.Observe(dummy); result.ValueChanged += (o, e) => { Assert.AreEqual(2m, e.OldValue); updated = true; }; Assert.AreEqual(2, result.Value); Assert.IsFalse(updated); dummy.Item = 45; Assert.IsTrue(updated); Assert.AreEqual(42, result.Value); }
public void Negate_Bool_Observable_Updates() { var update = false; var dummy = new ObservableDummy <bool>() { Item = true }; var test = Observable.Expression <bool>(() => !dummy.Item); test.ValueChanged += (o, e) => { update = true; Assert.IsFalse((bool)e.OldValue); Assert.IsTrue((bool)e.NewValue); }; Assert.IsFalse(test.Value); Assert.IsFalse(update); dummy.Item = false; Assert.IsTrue(update); Assert.IsTrue(test.Value); }
public void MemberExpression_ObservableSourceObservableTargetChanges_Update() { var update = false; var dummy = new ObservableDummy <Dummy <int> >() { Item = new ObservableDummy <int>(23) }; var test = Observable.Expression <int>(() => dummy.Item.Item); test.ValueChanged += (o, e) => update = true; Assert.AreEqual(23, test.Value); Assert.IsFalse(update); dummy.Item.Item = 42; Assert.IsTrue(update); Assert.AreEqual(42, test.Value); update = false; dummy.Item = new ObservableDummy <int>(42); Assert.IsFalse(update); Assert.AreEqual(42, test.Value); dummy.Item.Item = 23; Assert.IsTrue(update); Assert.AreEqual(23, test.Value); }
public void UnaryMinus_Decimal_Observable_Updates() { var update = false; var dummy = new ObservableDummy <decimal>() { Item = 23 }; var test = Observable.Expression <decimal>(() => - dummy.Item); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual(-23, (decimal)e.OldValue); Assert.AreEqual(42, (decimal)e.NewValue); }; Assert.AreEqual(-23, test.Value); Assert.IsFalse(update); dummy.Item = -42; Assert.IsTrue(update); Assert.AreEqual(42, test.Value); }
public void MemberExpression_ObservableSourceMemberChanges_Update() { var update = false; var dummy = new ObservableDummy <int>() { Item = 23 }; var test = Observable.Expression <int>(() => dummy.Item); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual(23, e.OldValue); Assert.AreEqual(42, e.NewValue); }; Assert.AreEqual(23, test.Value); Assert.IsFalse(update); dummy.Item = 42; Assert.IsTrue(update); Assert.AreEqual(42, test.Value); }
public void Cast_Int_Observable_Update() { var update = false; var dummy = new ObservableDummy <object>() { Item = 23 }; var test = Observable.Expression <int>(() => (int)dummy.Item); test.ValueChanged += (o, e) => { update = true; Assert.AreEqual(23, e.OldValue); Assert.AreEqual(42, e.NewValue); }; Assert.AreEqual(23, test.Value); Assert.IsFalse(update); dummy.Item = 42; Assert.IsTrue(update); Assert.AreEqual(42, test.Value); }
public void Multiply_Decimal_Observable_Update() { unchecked { var updated = false; var dummy = new ObservableDummy <decimal>() { Item = 3 }; var test = new ObservingFunc <Dummy <decimal>, decimal>(d => d.Item * 7); var result = test.Observe(dummy); result.ValueChanged += (o, e) => { Assert.AreEqual(21m, e.OldValue); updated = true; }; Assert.AreEqual(21, result.Value); Assert.IsFalse(updated); dummy.Item = 6; Assert.IsTrue(updated); Assert.AreEqual(42, result.Value); } }
public void MemberInitialization_Observable_NoUpdatesWhenDetached() { var update = false; var dummy = new ObservableDummy <int>(23); var test = Observable.Expression(() => new Dummy <int>() { Item = dummy.Item }); test.ValueChanged += (o, e) => update = true; Assert.AreEqual(23, (test.Value as Dummy <int>).Item); Assert.IsFalse(update); test.Detach(); dummy.Item = 42; Assert.IsFalse(update); Assert.AreNotSame(dummy, test.Value); Assert.AreEqual(23, test.Value.Item); test.Attach(); Assert.AreEqual(42, test.Value.Item); dummy.Item = 1; Assert.AreEqual(1, test.Value.Item); }
public void MultiplyChecked_Long_Observable_Update() { checked { var updated = false; var dummy = new ObservableDummy <long>() { Item = 3 }; var test = new ObservingFunc <Dummy <long>, long>(d => d.Item * 7L); var result = test.Observe(dummy); result.ValueChanged += (o, e) => { Assert.AreEqual(21L, e.OldValue); updated = true; }; Assert.AreEqual(21L, result.Value); Assert.IsFalse(updated); dummy.Item = 6; Assert.IsTrue(updated); Assert.AreEqual(42L, result.Value); } }
public void ListInit_Observable_NoUpdateWhenDetached() { var update = false; var dummy = new ObservableDummy <string>("foo"); var test = Observable.Expression(() => new List <string>() { dummy.Item }); test.ValueChanged += (o, e) => update = true; Assert.IsTrue(test.Value.Contains("foo")); Assert.IsFalse(update); test.Detach(); dummy.Item = "bar"; Assert.IsFalse(update); Assert.AreEqual(0, test.Value.Count); test.Attach(); Assert.AreEqual(1, test.Value.Count); Assert.IsTrue(test.Value.Contains("bar")); dummy.Item = "42"; Assert.AreEqual(1, test.Value.Count); Assert.IsTrue(test.Value.Contains("42")); }
public void ArrayLongIndexer2d_ObservableIndex_NoUpdatesWhenDetached() { var update = false; var coll = new string[, ] { { "23", "42" } }; var dummy = new ObservableDummy <long>(); var test = new NotifyValue <string>(() => coll[0, dummy.Item]); test.ValueChanged += (o, e) => update = true; Assert.AreEqual("23", test.Value); Assert.IsFalse(update); test.Detach(); dummy.Item = 1; Assert.IsFalse(update); test.Attach(); Assert.IsTrue(update); Assert.AreEqual("42", test.Value); update = false; dummy.Item = 0; Assert.IsTrue(update); }