Skip to content

Add some unit tests to validate cohosting configuration#11151

Merged
davidwengier merged 6 commits intodotnet:mainfrom
davidwengier:CohostEndpointTests
Nov 5, 2024
Merged

Add some unit tests to validate cohosting configuration#11151
davidwengier merged 6 commits intodotnet:mainfrom
davidwengier:CohostEndpointTests

Conversation

@davidwengier
Copy link
Member

These tests detect an issue I ran into doing code actions, and Dustin ran into doing hover.

Also makes it impossible to forget to specify a DocumentSelector in a registration.

@davidwengier davidwengier requested a review from a team as a code owner November 5, 2024 03:51
Copy link
Contributor

@ryzngard ryzngard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm definitely not an expert here but it looks reasonable to me

{
if (endpoint is CohostSemanticTokensRangeEndpoint)
{
// We can't currently test this, as the GetRegistrations method calls requestContext.GetRequiredService
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about a Mock?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't mock structs, and RazorCohostRequestContext is a struct, which takes a roslyn RequestContext as a constructor parameter, which is also a struct :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I missed it was a struct!


foreach (var registration in registrations)
{
var options = registration.RegisterOptions as ITextDocumentRegistrationOptions;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💭I'm not sure what the error message looks like but there is Assert.IsType<T>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the standard failure messages look terrible IMO and I hate that xunit got rid of the message parameters from most of them. In this case it would be something like "IsType failed, expected ITextDocumentRegistrationOptions", so you'd have to just debug the test to find out which one was the problem.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tyme to start writing extension methods for ALL of XUnit :P

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that'd work out, since xUnit's Assert is a static class and we don't have the ability to create static extension methods. IMO, we'd be better off just using FluentAssertions or some other library.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or do the AssertEx thing for our own implementations

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.

4 participants