// Copyright (C) Stichting Deltares 2026. All rights reserved. // // This file is part of the application DAM - UI. // // DAM - UI is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program. If not, see . // // All names, logos, and references to "Deltares" are registered trademarks of // Stichting Deltares and remain full property of Stichting Deltares at all times. // All rights reserved. using System; using Deltares.Dam.Tests.TestUtils; using NUnit.Framework; namespace Deltares.Dam.TestHelper.TestUtils { [TestFixture] public class ObjectLeakMonitorTest { [Test] public void IsAlive_ObjectStillInScope_True() { // setup var objectToMonitor = new object(); var monitor = new ObjectLeakMonitor(objectToMonitor); // call bool isAlive = monitor.ObjectIsAlive(); // assert var text = objectToMonitor.ToString(); // To ensure it stays in scope Assert.That(isAlive, Is.True, text); } [Test] public void MonitoredObjectType_ShouldBeTypeOfMonitoredObject() { // setup var objectToMonitor = new object(); var monitor = new ObjectLeakMonitor(objectToMonitor); // call Type type = monitor.MonitoredObjectType; // assert Assert.That(type, Is.EqualTo(objectToMonitor.GetType())); } [Test] public void ObjectIsAlive_ObjectOutOfScope_False() { // setup ObjectLeakMonitor monitor = CreateObjectAndAssignToObjectLeakMonitor(); // call bool isAlive = monitor.ObjectIsAlive(); // assert Assert.That(isAlive, Is.False); } private ObjectLeakMonitor CreateObjectAndAssignToObjectLeakMonitor() { var objectToMonitor = new object(); // This object goes out of scope when the method returns, and will be garbage collectable return new ObjectLeakMonitor(objectToMonitor); } } }