From d88804dbdb2beba1ed29bc921d140c310c9ab23d Mon Sep 17 00:00:00 2001 From: Alexandr Nikitin Date: Sat, 23 Dec 2023 12:32:10 -0800 Subject: [PATCH] Add code for https://github.com/nsubstitute/NSubstitute/issues/759 --- .../FieldReports/Issue759_Event.cs | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/NSubstitute.Acceptance.Specs/FieldReports/Issue759_Event.cs diff --git a/tests/NSubstitute.Acceptance.Specs/FieldReports/Issue759_Event.cs b/tests/NSubstitute.Acceptance.Specs/FieldReports/Issue759_Event.cs new file mode 100644 index 00000000..3a284412 --- /dev/null +++ b/tests/NSubstitute.Acceptance.Specs/FieldReports/Issue759_Event.cs @@ -0,0 +1,44 @@ +using NUnit.Framework; +using System; + +namespace NSubstitute.Acceptance.Specs.FieldReports +{ + public class Issue759_Event + { + public interface IChild + { + event EventHandler Changed; + void Change(); + } + public class Parent : IDisposable + { + private IChild m_Child; + public Parent(IChild child) + { + m_Child = child; + m_Child.Changed += Child_Changed; + } + public void Dispose() + { + m_Child.Changed -= Child_Changed; + m_Child = null; + } + private void Child_Changed(object sender, EventArgs args) { } + public void Change() + { + m_Child.Change(); + } + } + + [Test] + public void Test() + { + for (int i = 0; i < 10000000; i++) + { + var child = Substitute.For(); + var sut = new Parent(child); + sut.Dispose(); + } + } + } +} \ No newline at end of file