CollectionChangedTracker.cs 908 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright (c) The Avalonia Project. All rights reserved.
  2. // Licensed under the MIT license. See licence.md file in the project root for full license information.
  3. using System;
  4. using System.Collections.Specialized;
  5. namespace Avalonia.Base.UnitTests.Collections
  6. {
  7. internal class CollectionChangedTracker
  8. {
  9. public CollectionChangedTracker(INotifyCollectionChanged collection)
  10. {
  11. collection.CollectionChanged += CollectionChanged;
  12. }
  13. public NotifyCollectionChangedEventArgs Args { get; private set; }
  14. public void Reset()
  15. {
  16. Args = null;
  17. }
  18. private void CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
  19. {
  20. if (Args != null)
  21. {
  22. throw new Exception("CollectionChanged called more than once.");
  23. }
  24. Args = e;
  25. }
  26. }
  27. }