From 51261f29b0e3dfa6cc0fadb0ce7b24be5978b414 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20=C5=A0t=C3=A1gl?= Date: Wed, 8 Jan 2025 04:40:25 +0100 Subject: [PATCH] add another INotifyPropertyChanged test --- FastCloner.Tests/SpecialCaseTests.cs | 39 ++++++++++++++++++++++++++++ FastCloner/FastCloner.csproj | 2 +- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/FastCloner.Tests/SpecialCaseTests.cs b/FastCloner.Tests/SpecialCaseTests.cs index bd2aa1b..6ab34f3 100644 --- a/FastCloner.Tests/SpecialCaseTests.cs +++ b/FastCloner.Tests/SpecialCaseTests.cs @@ -923,6 +923,45 @@ public void NotifyPropertyChanged_With_Collection_Clone() }); } + public class INotifyTest : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + + private string _prop; + public string Prop + { + get => _prop; + + set + { + _prop = value; + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Prop))); + } + } + } + + [Test] + public void Test_Notify_Triggered_Correctly() + { + // Arrange + List output = []; + INotifyTest a = new INotifyTest(); + a.PropertyChanged += (sender, args) => + { + output.Add(((INotifyTest)sender).Prop); + }; + + // Act + a.Prop = "A changed"; + INotifyTest b = a.DeepClone(); + b.Prop = "B changed"; + b.Prop = "B changed again"; + + // Assert + Assert.That(output, Has.Count.EqualTo(1)); + Assert.That(output[0], Is.EqualTo("A changed")); + } + public class NotifyingPerson : INotifyPropertyChanged { private string _name; diff --git a/FastCloner/FastCloner.csproj b/FastCloner/FastCloner.csproj index 274a911..754309f 100644 --- a/FastCloner/FastCloner.csproj +++ b/FastCloner/FastCloner.csproj @@ -22,7 +22,7 @@ - 3.1.4 + 3.1.5 FastCloner Fast deep cloning library for .NET 8+. Supports both deep and shallow cloning. Extensively tested, focused on performance and stability even on complicated object graphs.