This repository was archived by the owner on Jun 21, 2023. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
TL;DR: Create static methods that mirror the IGitService instance methods, and use either a real mef instance or a fake one to get at the instance methods. This way we can expose the service in unit tests and use it at runtime without worrying about different codepaths or untestable static methods.
Long Version
Things are slightly broken getting a reference to IGitService - in real life, it's not a service, it's an exported value, but in unit tests it's treated as a service (because this silly distinction between services
and exported values is silly).
IGitService
is nothing but a bunch of helper methods, and we want to use it as an instance and not just static methods, so that we can bypass hitting the filesystem and libgit2# methods in unit tests. Some bits that needIGitService
during runtime are running in places where there's no MEF.Therefore, the only time where it really makes a difference when/how the
IGitService
instance is created is in unit tests. When running for real, it makes zero difference if the instance is coming from mef or if it's just created on the spot, so that's what we're doing now.IGitService
can be obtained via MEF as usual, or throughComponentModel.DefaultExportProvider.GetExportedValue<IGitService>()
, orIUIProvider.GetService<IGitService>()
and variants (which end up going throughComponentModel
, so it's all the same), and now the unit tests substitutes also provide all these paths (before they'd only provideGetService()
).