New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify some duplicated codes and make them testable/mockable #3823
Unify some duplicated codes and make them testable/mockable #3823
Conversation
Make the DllVersion standalone Update namespace references
…whether it's a UI thread or not.
Provide an interface for UiDispatcher Make UiDispatcher injected via ctors for consuming classes
…ead of newing it up.
…nto UnifyVbeFunctions # Conflicts: # RetailCoder.VBE/VBERuntime/IVBESettings.cs # RetailCoder.VBE/VBERuntime/RegistryWrapper.cs # RetailCoder.VBE/VBERuntime/VBESettings.cs # Rubberduck.Core/Rubberduck.Core.csproj # Rubberduck.Core/UI/Settings/SettingsForm.cs # Rubberduck.Core/VBERuntime/IVBESettings.cs # Rubberduck.Core/VBERuntime/RegistryWrapper.cs # Rubberduck.Core/VBERuntime/VBESettings.cs # Rubberduck.Main/Root/RubberduckIoCInstaller.cs # Rubberduck.VBEEditor/Utility/RegistryWrapper.cs # Rubberduck.VBEEditor/VBERuntime/Settings/IVBESettings.cs # Rubberduck.VBEEditor/VBERuntime/Settings/VBESettings.cs # RubberduckTests/Settings/GeneralSettingsTests.cs # RubberduckTests/VBE/VBESettingsTests.cs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good work getting the UiDispatcher
under proper control and extracting the context handling.
I just have a few nitpicks.
if (UiContext == null) throw new InvalidOperationException("UiDispatcher is not initialized. Invoke Initialize() from UI thread first."); | ||
if (_contextProvider.UiContext == null) | ||
{ | ||
throw new InvalidOperationException("UiDispatcher is not initialized. Invoke Initialize() from UI thread first."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message is misleading now. The UiContext is not initialized and Initialize
has to be called on it, not on the dispatcher.
|
||
public class UiContextProvider : IUiContextProvider | ||
{ | ||
// thanks to Pellared on http://stackoverflow.com/a/12909070/1188513 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If at all any longer appropriate, this should probably be in the UiDispatcher
as it most closely resembles the code from the post.
public SynchronizationContext UiContext => Context; | ||
public TaskScheduler UiTaskScheduler => TaskScheduler; | ||
|
||
public bool CheckContext() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer a more descriptive name likem CurrentContextIsUiContext
or IsExecutingInUiContext
. The current name does not really convey what is checked.
…lanatory comment to highlight the static methods being used for the VBEEvents.
This PR attempts to cut down on the duplications that was created as consequence of recent PRs, namely:
We introduced both
VBESettings
andVBERuntime
; but they had their own version check logic, and were originally in two different projects. I have moved everything toRubberduck.VBEEditor
and separated out the version check logic.SynchronizationContext
used byUiDispatcher
andComMessagePumper
into a new class,UiContextProvider
.This makes those 2 consuming classes mockable which will aid the testability of the dependent classes (though they themselves cannot be really tested). Furthermore, the
UiContextProvider
can be DI'd for any new consumers.