/// <summary> /// Update the aggregated pages as the set of tags changes. /// </summary> /// <param name="sender">collection which emits the event</param> /// <param name="e">event details</param> private void OnTagsCollectionChanged(object sender, NotifyDictionaryChangedEventArgs <string, TagPageSet> e) { switch (e.Action) { case NotifyDictionaryChangedAction.Add: foreach (var item in e.Items) { _aggregatedPages.UnionWith(item.FilteredPages); } break; case NotifyDictionaryChangedAction.Remove: // rebuild the set _aggregatedPages.Clear(); foreach (var item in e.Items) { _aggregatedPages.UnionWith(item.FilteredPages); } break; case NotifyDictionaryChangedAction.Reset: _aggregatedPages.Clear(); break; } }
public override void Save() { _settings.LoginNameMarkupColors = GetNewUserColorSettings(false); _settings.Save(); _defaultMarkupColor = _settings.DefaultMarkupColor; _loginNameMarkupColorsOriginalSettings = new XmlSerializableStringToColorDictionary(_settings.LoginNameMarkupColors); _useRandomDefaultMarkupColor = _settings.UseRandomDefaultMarkupColor; _userMarkupPropertiesDictionary.ItemAdded -= OnUserMarkupPropertiesChanged; _userMarkupPropertiesDictionary.ItemChanged -= OnUserMarkupPropertiesChanged; _userMarkupPropertiesDictionary.ItemRemoved -= OnUserMarkupPropertiesChanged; _userMarkupPropertiesDictionary.Clear(); }
public void OperationCollapseTest() { var argsList = new List <DictionaryChangedEventArgs <int, string> >(); var dictionary = new ObservableDictionary <int, string>(); dictionary.DictionaryChanged += (sender, e) => argsList.Add(e); dictionary.BeginBatch(); dictionary.Add(1, "1"); // \ dictionary.Add(2, "2"); // > collapse into [0] add dictionary.Add(3, "3"); // / dictionary.Remove(1); // \ dictionary.Remove(2); // > collapse into [1] remove dictionary.Remove(3); // / dictionary.AddRange(MakeTestPairs(1, 2, 3)); // \ dictionary.Add(4, "4"); // > collapse into [2] add dictionary.AddRange(MakeTestPairs(5, 6, 7)); // / dictionary.Remove(7); // \ dictionary.Remove(6); // > collapse into [3] reset dictionary.Clear(); // / dictionary[1] = "1"; // \ dictionary[2] = "2"; // > collapse into [4] add dictionary[3] = "3"; // / dictionary[1] = "1234"; // no collapse - [5] replace dictionary.Remove(1); // \ dictionary.Clear(); // / collapse into [6] reset Assert.AreEqual(0, argsList.Count); dictionary.EndBatch(); Assert.AreEqual(7, argsList.Count); Assert.AreEqual(NotifyCollectionChangedAction.Add, argsList[0].Action); Assert.IsTrue(Enumerable.SequenceEqual(MakeTestPairs(1, 2, 3), argsList[0].NewItems)); Assert.AreEqual(NotifyCollectionChangedAction.Remove, argsList[1].Action); Assert.IsTrue(Enumerable.SequenceEqual(MakeTestPairs(1, 2, 3), argsList[1].OldItems)); Assert.AreEqual(NotifyCollectionChangedAction.Add, argsList[2].Action); Assert.IsTrue(Enumerable.SequenceEqual(MakeTestPairs(1, 2, 3, 4, 5, 6, 7), argsList[2].NewItems)); Assert.AreEqual(NotifyCollectionChangedAction.Reset, argsList[3].Action); Assert.AreEqual(NotifyCollectionChangedAction.Add, argsList[4].Action); Assert.IsTrue(Enumerable.SequenceEqual(MakeTestPairs(1, 2, 3), argsList[4].NewItems)); Assert.AreEqual(NotifyCollectionChangedAction.Replace, argsList[5].Action); Assert.AreEqual(NotifyCollectionChangedAction.Reset, argsList[6].Action); }
public void ExpressionlessSourceManipulation() { var numbers = new ObservableDictionary <int, int>(System.Linq.Enumerable.Range(0, 10).ToDictionary(i => i)); using (var query = numbers.ActiveFirst()) { Assert.IsNull(query.OperationFault); Assert.AreEqual(0, query.Value.Value); numbers.Remove(0); Assert.AreEqual(1, query.Value.Value); numbers.Clear(); Assert.IsNotNull(query.OperationFault); Assert.AreEqual(0, query.Value.Value); numbers.Add(30, 30); Assert.IsNull(query.OperationFault); Assert.AreEqual(30, query.Value.Value); numbers.Reset(new Dictionary <int, int> { { 15, 15 } }); Assert.IsNull(query.OperationFault); Assert.AreEqual(15, query.Value.Value); numbers.Remove(15); Assert.IsNotNull(query.OperationFault); Assert.AreEqual(0, query.Value.Value); } }
public void ClearItems() { Debug.LogFormat("ClearItems"); nextIndex = 0; modelDictionary.Clear(); }
private void _dictionaryTestButton_Click(object sender, EventArgs e) { var dictionary = new ObservableDictionary <string, int>(); dictionary.ObservationWindow.ItemAdded += (dict, value, key) => _outputWriter.WriteLine("Single event: Added {0} at {1} ", value, key); dictionary.ObservationWindow.ItemRemoved += (dict, value, key) => _outputWriter.WriteLine("Single event: Removed {0} at {1} ", value, key); dictionary.ObservationWindow.Changed += (dict, events) => { _outputWriter.WriteLine("Global Handler"); foreach (var @event in events) { _outputWriter.WriteLine("\t: {0} {1} at {2} ", @event.EventType, @event.Item, @event.Location); } }; dictionary.Add("string 1", 1); dictionary.Remove("string 1"); dictionary.Add("string 2", 2); dictionary.Add("string 3", 3); dictionary.Add("string 4", 4); dictionary.Add("string 5", 5); dictionary.Add("string 6", 6); dictionary["string 6"] = -6; dictionary.Remove("string 1"); dictionary.Remove(dictionary.ElementAt(0)); dictionary.Clear(); }
public void SourceManipulation() { var numbers = new ObservableDictionary <int, int>(Enumerable.Range(1, 3).ToDictionary(i => i)); using var expr = numbers.ActiveSingle((key, value) => value % 3 == 0); Assert.IsNull(expr.OperationFault); Assert.AreEqual(3, expr.Value.Value); numbers.Remove(3); Assert.IsNotNull(expr.OperationFault); Assert.AreEqual(0, expr.Value.Value); numbers.Add(3, 3); Assert.IsNull(expr.OperationFault); Assert.AreEqual(3, expr.Value.Value); numbers.Add(5, 5); Assert.IsNull(expr.OperationFault); Assert.AreEqual(3, expr.Value.Value); numbers.Add(6, 6); Assert.IsNotNull(expr.OperationFault); Assert.AreEqual(0, expr.Value.Value); numbers.Clear(); Assert.IsNotNull(expr.OperationFault); Assert.AreEqual(0, expr.Value.Value); numbers.Add(3, 3); numbers.Add(6, 6); Assert.IsNotNull(expr.OperationFault); Assert.AreEqual(0, expr.Value.Value); numbers.Remove(3); Assert.IsNull(expr.OperationFault); Assert.AreEqual(6, expr.Value.Value); }
public void BeginEndBulkOperationTest() { DictionaryChangedEventArgs <int, string> args = null; var dictionary = new ObservableDictionary <int, string>(); dictionary.DictionaryChanged += (sender, e) => args = e; dictionary.BeginBatch(); dictionary.Add(1, "1"); Assert.IsNull(args); dictionary.Add(2, "2"); Assert.IsNull(args); dictionary.EndBatch(); Assert.IsNotNull(args); args = null; dictionary.BeginBatch(); dictionary.AddRange(MakeTestPairs(4, 5, 6)); Assert.IsNull(args); dictionary.Add(10, "10"); Assert.IsNull(args); dictionary.Remove(4); Assert.IsNull(args); dictionary[4] = "44"; Assert.IsNull(args); dictionary[44] = "44"; Assert.IsNull(args); dictionary.Clear(); Assert.IsNull(args); dictionary.EndBatch(); Assert.IsNotNull(args); }
public void DictionaryChanges() { var perfectNumbers = new ObservableDictionary <int, int>(Enumerable.Range(1, 10).ToDictionary(i => i, i => i * i)); var values = new BlockingCollection <int>(); using (var expr = ActiveExpression.Create(p1 => p1[5], perfectNumbers)) { var disconnect = expr.OnPropertyChanged(ae => ae.Value, value => { values.Add(value); }); values.Add(expr.Value); perfectNumbers.Add(11, 11 * 11); perfectNumbers.AddRange(Enumerable.Range(12, 3).ToDictionary(i => i, i => i * i)); perfectNumbers.Remove(11); perfectNumbers.RemoveRange(Enumerable.Range(12, 3)); perfectNumbers.Remove(5); perfectNumbers.Add(5, 30); perfectNumbers[5] = 25; perfectNumbers.RemoveRange(Enumerable.Range(4, 3)); perfectNumbers.AddRange(Enumerable.Range(4, 3).ToDictionary(i => i, i => i * i)); perfectNumbers.Clear(); disconnect(); } Assert.IsTrue(new int[] { 25, 0, 30, 25, 0, 25, 0 }.SequenceEqual(values)); }
private void UpdatePop() { _species.Clear(); foreach (var kvp in ColonyInfo.Population) { string name = kvp.Key.GetDataBlob <NameDB>().DefaultName; _species.Add(name, kvp.Value); } }
/// <summary> /// Find pages in OneNote. /// </summary> /// <remarks> /// Calling this method may cause tags in the filter to become stale. It is the /// responsibility of the caller to update tag objects it may have associated with /// the filter. /// </remarks> /// <param name="query"> query string. if null or empty just the tags are provided</param> /// <param name="scopeID"> /// OneNote id of the scope to search for pages. This is the element ID of a /// notebook, section group, or section. If given as null or empty string scope is /// the entire set of notebooks open in OneNote. /// </param> /// <seealso cref="Filter" /> internal void Find(string query, string scopeID) { _filteredPages.Clear(); _filterTags.Clear(); _query = query; if (string.IsNullOrEmpty(query)) { // collect all tags used somewhere on a page FindTaggedPages(scopeID); } else { // run a text search FindTaggedPages(query, scopeID); } // rebuild filter tags and filtered pages int filtersApplied = 0; foreach (string tagname in _tagFilter) { TagPageSet t; if (Tags.TryGetValue(tagname, out t)) { _filterTags.Add(t); if (filtersApplied++ == 0) { _filteredPages.UnionWith(t.Pages); } else { _filteredPages.IntersectWith(t.Pages); } } } if (filtersApplied == 0 && !string.IsNullOrEmpty(query)) { // as there are no filters we simply show the entire // query result _filteredPages.UnionWith(Pages.Values); } ApplyFilterToTags(); }
public void ObservableDictionary_RaisesCollectionResetOnClear() { var dict = new ObservableDictionary <String, Int32>(); var reset = false; dict.CollectionReset += (dictionary) => { reset = true; }; dict["Testing"] = 1234; dict.Clear(); TheResultingValue(reset).ShouldBe(true); }
public void ObservableDictionary_RaisesCollectionResetOnClear() { var dict = new ObservableDictionary<String, Int32>(); var reset = false; dict.CollectionReset += (dictionary) => { reset = true; }; dict["Testing"] = 1234; dict.Clear(); TheResultingValue(reset).ShouldBe(true); }
private void BuildConnectionList() { _connectionDictionary.Clear(); Connections = new ObservableCollection <string>(PLCConnectionConfiguration.GetConfigurationNames()); foreach (var item in Connections) { if (!DictonaryConnectionSymboltables.ContainsKey(item)) { DictonaryConnectionSymboltables.Add(item, null); } _connectionDictionary.Add(item, new PLCConnection(item)); } RefreshSymbols(); }
public void ClearTest() { var dic = new ObservableDictionary <int, string>(); List <NotifyCollectionChangedEventArgs> collectionsEvents = new List <NotifyCollectionChangedEventArgs>(); List <PropertyChangedEventArgs> propertyEvents = new List <PropertyChangedEventArgs>(); dic.Add(1, "1"); ((INotifyCollectionChanged)dic).CollectionChanged += (s, e) => collectionsEvents.Add(e); ((INotifyPropertyChanged)dic).PropertyChanged += (s, e) => propertyEvents.Add(e); dic.Clear(); collectionsEvents[0].Action.Should().Be(NotifyCollectionChangedAction.Reset); propertyEvents.First(e => e.PropertyName == "Count").Should().NotBeNull(); dic.Count.Should().Be(0); }
public void ObservableDictionaryReferenceTrackOnClearTest() { var sourceDictionary = new ObservableDictionary <int, string>(); var syncSourceRoot = new SyncSourceRoot(sourceDictionary, SyncSourceSettings.Default); sourceDictionary.Add(1, "1"); sourceDictionary.Add(2, "2"); Assert.Equal(3, syncSourceRoot.TrackedReferences.Count()); sourceDictionary.Clear(); Assert.Single(syncSourceRoot.AddedReferences); }
public void ClearShouldThrowDisposedExceptionAfterDisposal() { // given var observableDictionary = new ObservableDictionary <string, string>(); observableDictionary.Dispose(); // when Action action = () => { observableDictionary.Clear(); }; // then action.Should().Throw <ObjectDisposedException>(); }
private void Initialise() { var minerals = systemBodyInfo.Minerals; _mineralDeposits.Clear(); foreach (var kvp in minerals) { MineralSD mineral = _staticData.Minerals[kvp.Key]; if (!_mineralDeposits.ContainsKey(kvp.Key)) { _mineralDeposits.Add(kvp.Key, new PlanetMineralInfoVM(mineral.Name, kvp.Value)); } } OnPropertyChanged(nameof(MineralDeposits)); }
public void ResetTest() { var initialItems = MakeTestPairs(Enumerable.Range(0, 50)); var dictionary = new ObservableDictionary <int, string>(initialItems); DictionaryChangedEventArgs <int, string> args = null; dictionary.DictionaryChanged += (sender, e) => args = e; dictionary.Clear(); Assert.IsNotNull(args); Assert.AreEqual(NotifyCollectionChangedAction.Reset, args.Action); Assert.AreEqual(0, args.NewItems.Count); Assert.AreEqual(0, args.OldItems.Count); Assert.AreEqual(0, dictionary.Count); }
public void ExpressionlessSourceManipulation() { var numbers = new ObservableDictionary <int, int>(Enumerable.Range(0, 10).ToDictionary(i => i)); using var query = numbers.ActiveLast(); Assert.IsNull(query.OperationFault); Assert.AreEqual(9, query.Value.Value); numbers.Remove(9); Assert.AreEqual(8, query.Value.Value); numbers.Clear(); Assert.IsNotNull(query.OperationFault); Assert.AreEqual(0, query.Value.Value); numbers.Add(30, 30); Assert.IsNull(query.OperationFault); Assert.AreEqual(30, query.Value.Value); }
/// <summary> /// create and display new game board /// </summary> public BoardViewModel() { Board = new ObservableDictionary <Coordinates, SpaceViewModel>(); //build spaces Board.Clear(); for (int y = 0; y < Config.BOARD_SIZE; y++) { for (int x = 0; x < Config.BOARD_SIZE; x++) { Coordinates coords = new Coordinates(x, y); Board.Add(coords, new SpaceViewModel(coords)); } } NotifyPropertyChanged(nameof(Board)); }
public void AddFiresEventWithNotifyDictionaryItemClearedEventArgs() { NotifyDictionaryChangedEventArgs <string, string> actualArgs = null; var dictionary = new ObservableDictionary <string, string> { { ExpectedKey, "originalValue" } }; dictionary.DictionaryChanged += (sender, args) => { actualArgs = args; }; dictionary.Clear(); Assert.IsNotNull(actualArgs); Assert.AreEqual(NotifyDictionaryChangedAction.Clear, actualArgs.Action); Assert.IsInstanceOfType(actualArgs, typeof(NotifyDictionaryItemClearedEventArgs <string, string>)); Assert.AreEqual(0, dictionary.Count); }
public void RaisesEventWhileClearing() { bool wasRaised = false; var observableDictionary = new ObservableDictionary <int, int> { { 1, 1 } }; observableDictionary.AutomaticallyDispatchChangeNotifications = false; observableDictionary.CollectionChanged += (sender, args) => wasRaised = args.Action == NotifyCollectionChangedAction.Reset; observableDictionary.Clear(); Assert.IsTrue(wasRaised && observableDictionary.Count == 0); }
public void ExpressionlessSourceManipulation() { var numbers = new ObservableDictionary <int, int>(Enumerable.Range(1, 1).ToDictionary(i => i)); using var expr = numbers.ActiveSingle(); Assert.IsNull(expr.OperationFault); Assert.AreEqual(1, expr.Value.Value); numbers.Add(2, 2); Assert.IsNotNull(expr.OperationFault); Assert.AreEqual(0, expr.Value.Value); numbers.Remove(1); Assert.IsNull(expr.OperationFault); Assert.AreEqual(2, expr.Value.Value); numbers.Clear(); Assert.IsNotNull(expr.OperationFault); Assert.AreEqual(0, expr.Value.Value); }
public void ShouldBeEmptyAfterClear() { // given var initialItems = new List<KeyValuePair<int, string>>() { new KeyValuePair<int, string>(1, "One"), new KeyValuePair<int, string>(2, "Two") }; using (var observableDictionary = new ObservableDictionary<int, string>(initialItems)) { // when observableDictionary.Clear(); // then observableDictionary.IsEmpty.Should().BeTrue(); } }
public void ObservableDictionaryRedoAtClear(ObservableDictionary <int, int> dict) { // ARRANGE EnvironmentSettings.AlwaysSuppressCurrentSynchronizationContext = true; dict.Clear(); dict.Undo(); Assert.True( dict.ContainsKey(1), "Element not found: 1"); Assert.True( dict.ContainsKey(7), "Element not found: 7"); Assert.True( dict.ContainsKey(19), "Element not found: 19"); Assert.True( dict.ContainsKey(23), "Element not found: 23"); Assert.True( dict.ContainsKey(4), "Element not found: 4"); // ACT dict.Redo(); // ASSERT Assert.False( dict.ContainsKey(1), "Element found: 1"); Assert.False( dict.ContainsKey(7), "Element found: 7"); Assert.False( dict.ContainsKey(19), "Element found: 19"); Assert.False( dict.ContainsKey(23), "Element found: 23"); Assert.False( dict.ContainsKey(4), "Element found: 4"); }
public void SourceManipulation() { var numbers = new ObservableDictionary <int, int>(Enumerable.Range(1, 10).ToDictionary(i => i, i => i * 3)); using var query = numbers.ActiveAll((key, value) => value % 3 == 0); Assert.IsNull(query.OperationFault); Assert.IsTrue(query.Value); numbers[1] = 2; Assert.IsFalse(query.Value); numbers.Remove(1); Assert.IsTrue(query.Value); --numbers[2]; Assert.IsFalse(query.Value); numbers.Clear(); Assert.IsTrue(query.Value); numbers.Add(11, 7); Assert.IsFalse(query.Value); }
public void ShouldBeEmptyAfterClear() { // given var initialItems = new List <KeyValuePair <int, string> >() { new KeyValuePair <int, string>(1, "One"), new KeyValuePair <int, string>(2, "Two") }; using (var observableDictionary = new ObservableDictionary <int, string>(initialItems)) { // when observableDictionary.Clear(); // then observableDictionary.IsEmpty.Should().BeTrue(); } }
public void TestClearItems() { var items = new[] { 98, 15, 51, 87, 66, 20, 27, 86 }; var dict = new ObservableDictionary <int, double>(items.ToDictionary(i => i, i => 1d / i)); var keys = dict.Keys; var values = keys.ListSelect(i => 1d / i); Assert.AreEqual(items.Length, dict.Count); Assert.AreEqual(items.Length, keys.Count); Assert.AreEqual(items.Length, values.Count); dict.Clear(); Assert.AreEqual(0, dict.Count); Assert.AreEqual(0, keys.Count); Assert.AreEqual(0, values.Count); }
/// <summary> /// Get all open futures contracts. /// </summary> /// <returns></returns> public async Task RefreshOpenContractList() { var f = await GetOpenContractList(); if (contractList == null) { contractList = new ObservableDictionary <string, FuturesContract>(); } else { contractList.Clear(); } foreach (var fc in f) { contractList.Add(fc); } }
public void ExpressionlessSourceManipulation() { var numbers = new ObservableDictionary <int, int>(System.Linq.Enumerable.Range(1, 10).ToDictionary(i => i, i => i * 3)); using (var query = numbers.ActiveAny()) { Assert.IsNull(query.OperationFault); Assert.IsTrue(query.Value); numbers[1] = 2; Assert.IsTrue(query.Value); numbers.Remove(1); Assert.IsTrue(query.Value); --numbers[2]; Assert.IsTrue(query.Value); numbers.Clear(); Assert.IsFalse(query.Value); numbers.Add(1, 7); Assert.IsTrue(query.Value); } }
protected void Start() { #if UNITY_IOS this.dict = new ObservableDictionary <int, Item>(new IntEqualityComparer()); #else this.dict = new ObservableDictionary <int, Item>(); #endif dict.CollectionChanged += OnCollectionChanged; dict.Add(1, new Item() { Title = "title1", IconPath = "xxx/xxx/icon1.png", Content = "this is a test." }); dict.Add(2, new Item() { Title = "title2", IconPath = "xxx/xxx/icon2.png", Content = "this is a test." }); dict.Remove(1); dict.Clear(); }
public void SynchronizeRegistryWith(ObservableDictionary<uint, VirtualRegistryKey> keyList) { if (keyList == null) throw new ArgumentNullException("keyList"); keyList.Clear(); var keys = _regDatabase.ReadAll(); foreach (var key in keys) keyList.Add(key.Handle, key); keyList.ItemAdded += Registry_ItemAdded; keyList.ItemChanged += Registry_ItemChanged; keyList.ItemRemoved += Registry_ItemRemoved; }
public void ClearClearsDictionary() { // given var initialKvPs = new List<KeyValuePair<int, string>>() { new KeyValuePair<int, string>(1, "One"), new KeyValuePair<int, string>(2, "Two") }; using (var observableDictionary = new ObservableDictionary<int, string>(initialKvPs)) { // when observableDictionary.Clear(); // then observableDictionary.Count.Should().Be(0); } }
public void ObservableDictionaryClearTest() { ObservableDictionary<GenericParameterHelper, GenericParameterHelper> target = new ObservableDictionary<GenericParameterHelper, GenericParameterHelper>(); target.Add(new GenericParameterHelper(1), new GenericParameterHelper(1)); target.Add(new GenericParameterHelper(2), new GenericParameterHelper(2)); target.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs e) { Assert.AreEqual(NotifyCollectionChangedAction.Reset, e.Action); }; target.Clear(); Assert.AreEqual(0, target.Count); }
public void ClearNotifiesAsReset() { // given var initialList = new List<KeyValuePair<int, string>>() { new KeyValuePair<int, string>(1, "Some Value"), new KeyValuePair<int, string>(2, "Some Other Value"), new KeyValuePair<int, string>(3, "Some Totally Different Value"), }; var scheduler = new TestScheduler(); var observer = scheduler.CreateObserver<IObservableDictionaryChange<int, string>>(); var resetsObserver = scheduler.CreateObserver<Unit>(); var observableCollectionChangesObserver = scheduler.CreateObserver<IObservableCollectionChange<KeyValuePair<int, string>>>(); using (var observableDictionary = new ObservableDictionary<int, string>(initialList, scheduler: scheduler)) { // when observableDictionary.ThresholdAmountWhenChangesAreNotifiedAsReset = int.MaxValue; IDisposable dictionaryChangesSubscription = null; IDisposable resetsSubscription = null; IDisposable observableCollectionChangesSubscription = null; try { dictionaryChangesSubscription = observableDictionary.DictionaryChanges.Subscribe(observer); resetsSubscription = observableDictionary.Resets.Subscribe(resetsObserver); observableCollectionChangesSubscription = ((INotifyObservableCollectionChanges<KeyValuePair<int, string>>)observableDictionary) .CollectionChanges .Subscribe(observableCollectionChangesObserver); observableDictionary.Clear(); scheduler.AdvanceBy(3); // then observableDictionary.Count.Should().Be(0); resetsObserver.Messages.Count.Should().Be(1); observer.Messages.Count.Should().Be(1); observableCollectionChangesObserver.Messages.Count.Should().Be(1); observer.Messages.First().Value.Value.ChangeType.Should().Be(ObservableDictionaryChangeType.Reset); observer.Messages.First().Value.Value.Key.Should().Be(default(int)); observer.Messages.First().Value.Value.Value.Should().Be(default(string)); observer.Messages.First().Value.Value.OldValue.Should().Be(default(string)); observer.Messages.First().Value.Value.ChangedPropertyName.Should().BeEmpty(); observableCollectionChangesObserver.Messages.First().Value.Value.ChangeType.Should().Be(ObservableCollectionChangeType.Reset); observableCollectionChangesObserver.Messages.First().Value.Value.Item.Key.Should().Be(default(int)); observableCollectionChangesObserver.Messages.First().Value.Value.Item.Value.Should().Be(default(string)); } finally { dictionaryChangesSubscription?.Dispose(); resetsSubscription?.Dispose(); observableCollectionChangesSubscription?.Dispose(); } } }
public void ClearDoesNotRaisesPropertyChangeEventForItemIndexerdAndCountIfDictionaryIsEmpty() { // given using (var observableDictionary = new ObservableDictionary<int, string>()) { observableDictionary.MonitorEvents(); // when observableDictionary.Clear(); // then observableDictionary .ShouldNotRaise(nameof(observableDictionary.PropertyChanged)); } }
public void ClearRaisesPropertyChangeEventForItemIndexerdAndCount() { // given var items = new List<KeyValuePair<int, string>>() { new KeyValuePair<int, string>(1, "One"), new KeyValuePair<int, string>(2, "Two"), new KeyValuePair<int, string>(3, "Three"), }; using (var observableDictionary = new ObservableDictionary<int, string>(items)) { observableDictionary.MonitorEvents(); // when observableDictionary.Clear(); // then observableDictionary .ShouldRaise(nameof(observableDictionary.PropertyChanged)) .WithSender(observableDictionary) .WithArgs<PropertyChangedEventArgs>(args => args.PropertyName == "Item[]"); observableDictionary .ShouldRaise(nameof(observableDictionary.PropertyChanged)) .WithSender(observableDictionary) .WithArgs<PropertyChangedEventArgs>(args => args.PropertyName == nameof(observableDictionary.Count)); } }