public void ReplaceCollection_Updates() { var ctx = new TestContext(); var items = new ObservableCollection <int>(Enumerable.Range(0, 10)); var watcher = new CollectionChangedWatcher(); var comp = ctx.RenderComponent <Repeater <int> >(builder => builder .Add(p => p.Items, items) .Add(p => p.ChildContent, x => x.ToString()) .Add(p => p.CollectionChanged, callbackFactory.Create(watcher, (Action <NotifyCollectionChangedEventArgs>)watcher.OnCollectionChanged)) ); Assert.Equal(string.Concat(items.Select(x => x.ToString())), comp.Markup); Assert.Equal(1, watcher.Count); comp.SetParametersAndRender(builder => builder.Add(p => p.Items, items)); Assert.Equal(string.Concat(items.Select(x => x.ToString())), comp.Markup); Assert.Equal(1, watcher.Count); var updated = Enumerable.Range(10, 20).ToList(); comp.SetParametersAndRender(builder => builder.Add(p => p.Items, updated)); Assert.Equal(string.Concat(updated.Select(x => x.ToString())), comp.Markup); Assert.Equal(2, watcher.Count); }
public void CollectionChanged_Updates() { var ctx = new TestContext(); var items = new ObservableCollection <int>(Enumerable.Range(0, 10)); var watcher = new CollectionChangedWatcher(); var comp = ctx.RenderComponent <Repeater <int> >(builder => builder .Add(p => p.Items, items) .Add(p => p.ChildContent, x => x.ToString()) .Add(p => p.CollectionChanged, callbackFactory.Create(watcher, (Action <NotifyCollectionChangedEventArgs>)watcher.OnCollectionChanged)) ); Assert.Equal(string.Concat(items.Select(x => x.ToString())), comp.Markup); Assert.Equal(1, watcher.Count); items.Add(10); Assert.Equal(string.Concat(items.Select(x => x.ToString())), comp.Markup); Assert.Equal(2, watcher.Count); items.Clear(); Assert.True(string.IsNullOrWhiteSpace(comp.Markup)); Assert.Equal(3, watcher.Count); }