-
Notifications
You must be signed in to change notification settings - Fork 91
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
Improve FileRegionsCache testability #2129
Comments
Hi @lgolding , I was taking a look at this. I can expose the interface, but i will have to include one more method if that's not a problem. Below the interface: public interface IFileRegionsCache
{
Region PopulateTextRegionProperties(Region inputRegion, Uri uri, bool populateSnippet);
Region ConstructMultilineContextSnippet(Region inputRegion, Uri uri);
} Today the |
I'm not a big fan of using interfaces exclusively to drive testability. This results in a certain amount of type proliferation which generally only serves a single purpose (to help with testing). A more appropriate use of interfaces supports arbitrary additional uses. What tends to happen in projects like this one is that the interfaces are created in a somewhat haphazard manner and applied similarly (i.e., the abstraction is pushed through the API only in reaction to whatever testing is done). Broad areas of the code base don't have this kind of interface use, with the result that the API itself isn't consistent. My suggestion here is simply to ensure that FileRegionsCache is public, unsealed and to apply the 'virtual' keyword to relevant methods. This can be a simple, clean approach that allows easier testing. This approach can break down when attempting to test objects that are created indirectly by other classes/API but that doesn't seem to be the case here. |
just created a second PR with this approach + capacity fix + docs update |
I'm writing some unit tests for the VS Extension that require the use of a
FileRegionsCache
object, a concrete class that interacts with the file system. I can create, and use in my tests, aFileRegionsCache
object with a mockIFileSystem
. But that requires me to understand the internal workings ofFileRegionsCache
so I can mock the correct set of file system calls, and I also have to provide fake file system content to the mock.What I want/need instead is an
IFileRegionsCache
interface that I can mock, so that when the VS Extension product code that I'm unit testing callsfileRegionsCache.PopulateTextRegionProperties
, I can directly return the value I want.@michaelcfanning @eddynaka @GabeDeBacker FYI
The text was updated successfully, but these errors were encountered: