From 5e34a59323201ebcaf4a33a5440c926cdbddf7b5 Mon Sep 17 00:00:00 2001 From: Alexandr Nikitin Date: Mon, 29 Jan 2024 21:13:22 -0800 Subject: [PATCH] Add a test for issue 771 https://github.com/nsubstitute/NSubstitute/issues/771 --- .../Issue771_NSubstituteLeakTests.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/NSubstitute.Acceptance.Specs/FieldReports/Issue771_NSubstituteLeakTests.cs diff --git a/tests/NSubstitute.Acceptance.Specs/FieldReports/Issue771_NSubstituteLeakTests.cs b/tests/NSubstitute.Acceptance.Specs/FieldReports/Issue771_NSubstituteLeakTests.cs new file mode 100644 index 00000000..d6cd9284 --- /dev/null +++ b/tests/NSubstitute.Acceptance.Specs/FieldReports/Issue771_NSubstituteLeakTests.cs @@ -0,0 +1,27 @@ +using NSubstitute.Exceptions; +using NUnit.Framework; + +namespace NSubstitute.Acceptance.Specs.FieldReports; + + +public class Issue771_NSubstituteLeakTests +{ + public class Foo; + + [Test] + public void NSubstituteDoesNotLeak() + { + WeakReference weakFoo; + { + var foo = new Foo(); + weakFoo = new WeakReference(foo); + } + + GC.Collect(); + GC.WaitForPendingFinalizers(); + + Assert.False(weakFoo.TryGetTarget(out _)); + } +} + +