views:

12

answers:

0

I have the following code in a test:

 private void LoadIncomeStatementViewModel()
    {
        using (var evt = new AutoResetEvent(false))
        {
            EventHandler handler = (sender, e) => evt.Set();

            _incomeStatementViewModel.Loaded -= handler;
            _incomeStatementViewModel.Loaded += handler;
            _incomeStatementViewModel.LoadDataCommand.Execute(null);
            evt.WaitOne();
        }
    }

Now if I run the following test

[Test]
public void Test()
{
   LoadIncomeStatementViewModel();
   // do something

   LoadIncomeStatementViewModel();
   // do something
}

The second time the LoadIncomeStatementViewModel() is called I get a "Safe handle has been disposed" error message at EventHandler handler = (sender, e) => evt.Set();

Surely the using statement has reinitialized evt when the method is rerun the second time. I have a feeling that this may be something to do with the Resharper Test Runner (Nunit 2.7)....

Any thoughts on how to get around this?

Thanks Jeremy