Jelajahi Sumber

Merge pull request #2206 from jkoritzinsky/fixes/2149

Add unit test and fix #2149.
Jeremy Koritzinsky 7 tahun lalu
induk
melakukan
f09349715a

+ 1 - 0
src/Avalonia.Base/Data/Core/ExpressionNode.cs

@@ -147,6 +147,7 @@ namespace Avalonia.Data.Core
         private void StopListening()
         {
             StopListeningCore();
+            _listening = false;
         }
 
         private BindingNotification TargetNullNotification()

+ 13 - 0
tests/Avalonia.Base.UnitTests/Data/Core/ExpressionObserverTests_Property.cs

@@ -563,6 +563,19 @@ namespace Avalonia.Base.UnitTests.Data.Core
             Assert.Null(result.Item2.Target);
         }
 
+        [Fact]
+        public void Should_Not_Throw_Exception_On_Unsubscribe_When_Already_Unsubscribed()
+        {
+            var source = new Class1 { Foo = "foo" };
+            var target = new PropertyAccessorNode("Foo", false);
+            Assert.NotNull(target);
+            target.Target = new WeakReference(source);
+            target.Subscribe(_ => { });
+            target.Unsubscribe();
+            target.Unsubscribe();
+            Assert.True(true);
+        }
+
         private interface INext
         {
             int PropertyChangedSubscriptionCount { get; }