I didn't create the framework but I need to write test for it. The scenario...
- It uses WeakReference to hold an object, there's a base method that I call to assign object to it (BaseClass.Register(weakObject))
- I can retrieve that object through a method (BaseClass.GetObject())
- Testing it... I had to register my mock (BaseClass.Register(mockWeak.Object)) first
When executing a method that relies on the registered object, my test sometimes fails because it has been garbage collected before i performed test to it.
Can I do something to prevent GC from collecting my WeakReference object?
NOTE: No changes should be done in the framework (BaseClass), only in my test class