Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }