Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Conversation

shana
Copy link
Contributor

@shana shana commented Sep 23, 2015

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 need IGitService 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 through ComponentModel.DefaultExportProvider.GetExportedValue<IGitService>(), or IUIProvider.GetService<IGitService>() and variants (which end up going through ComponentModel, so it's all the same), and now the unit tests substitutes also provide all these paths (before they'd only provide GetService()).

@shana shana force-pushed the shana/fix-gitservice-null branch from 9bc94a2 to 6a2b6a1 Compare September 23, 2015 13:23
Make 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.

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 stupid distinction between services
and exported values is stupid).

So, 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 need IGitService for realz 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.
@shana shana force-pushed the shana/fix-gitservice-null branch from 6a2b6a1 to d99b34a Compare September 23, 2015 15:20
Also disabled a R# warning so I stop seeing it since it doesn't apply.
haacked added a commit that referenced this pull request Sep 23, 2015
@haacked haacked merged commit b872d48 into master Sep 23, 2015
@haacked haacked deleted the shana/fix-gitservice-null branch September 23, 2015 21:00
@haacked
Copy link
Contributor

haacked commented Sep 23, 2015

Nice work @shana!

@shana
Copy link
Contributor Author

shana commented Sep 23, 2015

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants