public static void Add() { var reference = new ObservableCollection <int>(); using var expected = reference.SubscribeAll(); var batchCollection = new DispatchingCollection <int>(); using var actual = batchCollection.SubscribeAll(); reference.Add(1); batchCollection.Add(1); CollectionAssert.AreEqual(reference, batchCollection); CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default); reference.Add(2); batchCollection.Add(2); CollectionAssert.AreEqual(reference, batchCollection); CollectionAssert.AreEqual(expected, actual, EventArgsComparer.Default); }
public static void Add() { var collection = new DispatchingCollection <int>(); var itemsControl = new ItemsControl { ItemsSource = collection }; CollectionAssert.IsEmpty(itemsControl.Items); collection.Add(1); CollectionAssert.AreEqual(new[] { 1 }, itemsControl.Items); }
public static async Task WhenAddOnOtherThread() { var collection = new DispatchingCollection <int>(); var itemsControl = new ItemsControl { ItemsSource = collection }; CollectionAssert.IsEmpty(itemsControl.Items); await Task.Run(() => collection.Add(1)).ConfigureAwait(false); await Application.Current.Dispatcher.SimulateYield(); CollectionAssert.AreEqual(new[] { 1 }, itemsControl.Items); }