Skip to content
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

Merged
merged 23 commits into from Mar 17, 2018

Conversation

bclothier
Copy link
Contributor

This PR attempts to cut down on the duplications that was created as consequence of recent PRs, namely:

  1. the VBE's version check

We introduced both VBESettings and VBERuntime; but they had their own version check logic, and were originally in two different projects. I have moved everything to Rubberduck.VBEEditor and separated out the version check logic.

  1. the acquisition of the UI's SynchronizationContext used by UiDispatcher and ComMessagePumper 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.

@bclothier bclothier added the PR-Status: Review Requested No more commits, PR is ready for the eyes that need to see it. label Mar 4, 2018
…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
Copy link
Contributor

@MDoerner MDoerner left a 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.");
Copy link
Contributor

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
Copy link
Contributor

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()
Copy link
Contributor

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.

@bclothier bclothier removed the PR-Status: Review Requested No more commits, PR is ready for the eyes that need to see it. label Mar 15, 2018
…lanatory comment to highlight the static methods being used for the VBEEvents.
@retailcoder retailcoder merged commit 47af462 into rubberduck-vba:next Mar 17, 2018
@bclothier bclothier deleted the UnifyVbeFunctions branch December 5, 2018 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants