Search Results for

    Show / Hide Table of Contents

    Event AssertionFailed

    Invoked when a memory assertion has failed.

    Namespace: SciTech.NetMemProfiler
    Assembly: SciTech.MemProfilerApi.dll
    Syntax
    public static event EventHandler AssertionFailed
    Returns
    Type Description
    System.EventHandler
    Remarks

    This event can be useful when using declarative assertions and unit testing together.

    [TestFixture]
    public class TestClass
    {
       [TestFixtureSetUp]
       public void FixtureSetup()
       {
          MemAssertion.AssertionFailed += new EventHandler( MemAssertion_AssertionFailed );
       }
    
       [TestFixtureTearDown]
       public void FixtureTearDown()
       {
          MemAssertion.AssertionFailed -= new EventHandler( MemAssertion_AssertionFailed );
       }
    
       /// 
       /// Handles a failed memory assertion by failing a unit test assertion.
       /// 
       void MemAssertion_AssertionFailed( object sender, EventArgs e )
       {
          Assert.Fail( "Memory assertion has failed." );
       }
    
       /// 
       /// A test that uses declarative assertions.
       /// 
       [Test]
       public void SomeTest()
       {
          MethodWithDeclarativeAssertion();
       }
    
       [NoNewInstances(...)]
       void MethodWithDeclarativeAssertion()
       {
          // ...
       }
    }
    In This Article
    Back to top

    © Copyright 2002-2020. SciTech Software AB.
    For information about .NET Memory Profiler, see the product site at https://memprofiler.com