DynamoDS/Dynamo — pull request #2859 by ke-yu (2014-10-27 09:25:32+00:00)
Title: Fix memory leak in nunit (DynamoCoreTest)

This pull request tries to fix memory leak in ``DynamoCoreTest``.

There are two major issues.
* ``DynamoModel`` calls ``Dispatcher.CurrentDispatcher.BeginInvoke()``. Unfortunately, in nunit the action will never get a chance to be called (Google [WPF+Dispatcher+Nunit](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&es_th=1&ie=UTF-8#q=WPF+dispatcher+nunit) will get a lot of solution about how to run ``BeginInvoke`` in Nunit, but as this action is just logging workspace loading time, it can be skipped). As the dispatcher is from nunit test running thread, this static object will never be garbage collected until all test cases run, the corresponding ``DynamoModel`` will not be released.

* The other issue is, as ``DynamoView`` is not created in ``DynamoCoreTest``, if some tests create some nodes, ``DynamoViewModel.PerformShutdownSequence()`` will fail in the middle when asking for saving workspace therefore the shutdown is incomplete. So ``RequestUserSaveWorkflow`` event handler is registered in ``DynamoViewModelUnitTests``.

Test result: peak memory usage in ``DynamoCoreTest`` from many GB to < 500 MB after running 700 test cases.

@Benglin please review :-)