Remove IDocumentMappingService.GetLanguageKind(...) and make it an extension method on RazorCodeDocument #10851
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.
For a long while, the
GetLanguageKind(...)
method that determines whether an index into a document falls within Razor, C# or HTML has been a bit of a wart on theIDocumentMappingService
. It really isn't part of document mapping, and its implementation is completely distinct. In fact, making the actual change is quite simple, so why hadn't it been done yet? The answer is mocking.There are several tests that mock
IDocumentMappingService.GetLanguageKind(...)
to lie about test inputs. In my not-so-humble opinion, this represents an abuse of mocking. Instead of setting up tests to have the necessary inputs that ensureGetLanguageKind(...)
would return a real and correct result, the inputs would often be garbage and anIDocumentMappingService
mock would lie about theGetLanguageKind(...)
result at a particular location. This makes movingGetLanguageKind(...)
off ofIDocumentMappingService
a much larger change than it needs to be. This is why there are substantial test changes in this PR.Don't misunderstand me as a mocking hater! Mocking libraries are definitely useful! In fact, there are new mocks used in this very PR! However, mocks should be used judiciously and thoughtfully, and in this case, a mock was used to write lazy tests.
Fixes #8774