title: How can I unit test a lock statement?
body: <p>How would I write a unit test to ensure that a lock was acquired?</p>
  
  <p>For example:</p>
  
  <pre><code>public void AddItem(object item)
  {
      lock (_list)
      {
          _list.Add(item)
      }
  }
  </code></pre>
  
  <p>Is there a way to ensure that the <code>lock</code> statement is run?</p>
  
  <p><strong>Edit</strong>: I'm not trying to prove thread-safety (this I would assume), just that the lock() statement is called.</p>
  
  <p>For example, I might test a <code>new object()</code> statement by substituting it in a <code>CreateObject()</code> factory function.</p>