public void TestAddOrUpdate_TryRemove() { var npc = new NotifyPropertyChangedImpl(); const string testKey = "One"; var ocd = new ObservableConcurrentDictionary <string, NotifyPropertyChangedImpl>(); ocd.AddOrUpdate(testKey, npc, (s, impl) => throw new InvalidOperationException()); // Register without doing, just to make sure we also test the event generation for now ocd.CollectionChanged += (sender, args) => { Log.Info().WriteLine($"Old location: {args.OldStartingIndex}"); }; var isNpcTriggered = false; // Subscribe to the PropertyChanged using (ocd.OnPropertyChanged().Subscribe(args => isNpcTriggered = true)) { // change a value, a NPC is triggered npc.Name = "Robin1"; // Test trigger Assert.True(isNpcTriggered); // Reset the trigger test value isNpcTriggered = false; // Remove the item, this should remove the event registration Assert.True(ocd.TryRemove(testKey, out _)); // change a value, a NPC is triggered npc.Name = "Robin2"; // Make sure we DID NOT get the trigger Assert.False(isNpcTriggered); } }