// Copyright (C) Stichting Deltares 2019. All rights reserved. // // This file is part of the Delta Shell Light Library. // // The Delta Shell Light Library 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 Deltares.Standard.TestUtils; using NUnit.Framework; namespace Deltares.Dam.Tests.TestUtils { [TestFixture] public class ObjectLeakMonitorTest { [Test] public void IsAlive_ObjectStillInScope_True() { // setup var objectToMonitor = new object(); var monitor = new ObjectLeakMonitor(objectToMonitor); // call var isAlive = monitor.ObjectIsAlive(); // assert var text = objectToMonitor.ToString(); // To ensure it stays in scope Assert.IsTrue(isAlive, text); } [Test] public void MonitoredObjectType_ShouldBeTypeOfMonitoredObject() { // setup var objectToMonitor = new object(); var monitor = new ObjectLeakMonitor(objectToMonitor); // call var type = monitor.MonitoredObjectType; // assert Assert.AreEqual(objectToMonitor.GetType(), type); } [Test] public void ObjectIsAlive_ObjectOutOfScope_False() { // setup var monitor = CreateObjectAndAssignToObjectLeakMonitor(); // call var isAlive = monitor.ObjectIsAlive(); // assert Assert.IsFalse(isAlive); } 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); } } }