diff --git a/src/TinkState/Tests/TestDictionary.cs b/src/TinkState/Tests/TestDictionary.cs index 0e339e3..300ad78 100644 --- a/src/TinkState/Tests/TestDictionary.cs +++ b/src/TinkState/Tests/TestDictionary.cs @@ -221,6 +221,36 @@ string s(IReadOnlyDictionary d) Assert.That(auto.Value, Is.EqualTo("0-!,1-a,3-c")); } + [Test] + public void TestObserveAndDictionaryUsedInAuto() + { + var dict = Observable.Dictionary(); + dict[1] = "a"; + dict[2] = "b"; + var dictAsObservable = dict.Observe(); + + List Sorted(IEnumerable values) + { + var list = new List(values); + list.Sort(); + return list; + } + + var auto = Observable.Auto(() => + { + var a = string.Join(',', Sorted(dict.Values.ToArray())); + var b = string.Join('.', Sorted(dictAsObservable.Value.Values)); + return $"{a}-{b}"; + }); + + Assert.That(auto.Value, Is.EqualTo("a,b-a.b")); + + dict[1] = "A"; + dict[2] = "B"; + dict[3] = "C"; + Assert.That(auto.Value, Is.EqualTo("A,B,C-A.B.C")); + } + void Helper(Func compute, R initialExpectedValue, Action> tests) { var auto = Observable.Auto(compute); diff --git a/src/TinkState/Tests/TestList.cs b/src/TinkState/Tests/TestList.cs index 0b95ffd..654a8bf 100644 --- a/src/TinkState/Tests/TestList.cs +++ b/src/TinkState/Tests/TestList.cs @@ -176,6 +176,30 @@ public void TestObserve() Assert.That(auto.Value, Is.EqualTo("0,1,2,3")); } + + [Test] + public void TestObserveAndListUsedInAuto() + { + var list = Observable.List(); + list.Add("a"); + list.Add("b"); + var listAsObservable = list.Observe(); + + var auto = Observable.Auto(() => + { + var a = string.Join(',', list); + var b = string.Join('.', listAsObservable.Value); + return $"{a}-{b}"; + }); + + Assert.That(auto.Value, Is.EqualTo("a,b-a.b")); + + list[0] = "A"; + list[1] = "B"; + list.Add("C"); + Assert.That(auto.Value, Is.EqualTo("A,B,C-A.B.C")); + } + void Helper(Func compute, R initialExpectedValue, Action> tests) { var auto = Observable.Auto(compute);