Skip to content
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

Fix ResultsOfTGenerated tests #57465

Merged
merged 1 commit into from
Aug 22, 2024
Merged

Fix ResultsOfTGenerated tests #57465

merged 1 commit into from
Aug 22, 2024

Conversation

captainsafia
Copy link
Member

Closes #57360.

@captainsafia captainsafia requested a review from amcasey August 22, 2024 17:20
@dotnet-issue-labeler dotnet-issue-labeler bot added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Aug 22, 2024
@dotnet-policy-service dotnet-policy-service bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Aug 22, 2024
@captainsafia captainsafia added area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions labels Aug 22, 2024
@dotnet-policy-service dotnet-policy-service bot added the area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions label Aug 22, 2024
@@ -72,7 +72,7 @@ Results<ChecksumResult1, NoContent> MyApi()
// Act & Assert
var result = MyApi();

Assert.ThrowsAsync<ArgumentNullException>(async () =>
await Assert.ThrowsAsync<ArgumentNullException>(async () =>
Copy link
Member

Choose a reason for hiding this comment

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

I'm kind of surprised there isn't an analyzer for this.

Copy link
Member

Choose a reason for hiding this comment

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

I think there is now, which is why we noticed this.
See #57303

@@ -84,7 +84,7 @@ public void ResultsOfTResult1TResult2_Throws_InvalidOperationException_WhenResul
// Arrange
Results<ChecksumResult1, NoContent> MyApi()
{
return new ChecksumResult1(1);
return (ChecksumResult1)null;
Copy link
Member

Choose a reason for hiding this comment

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

Am I reading correctly that the test was looking for an argument null exception but the argument wasn't null?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, although it throws an InvalidOperationException because the null value here is not an argument but the return type of a method we've indicated cannot be null.

@@ -482,7 +482,7 @@ static void GenerateTest_ExecuteResult_ExecutesAssignedResult(StreamWriter write
static void GenerateTest_Throws_ArgumentNullException_WhenHttpContextIsNull(StreamWriter writer, int typeArgNumber)
{
//[Fact]
//public void ResultsOfTResult1TResult2_Throws_ArgumentNullException_WhenHttpContextIsNull()
//public async Task ResultsOfTResult1TResult2_Throws_ArgumentNullException_WhenHttpContextIsNull()
Copy link
Member

Choose a reason for hiding this comment

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

Does this sample test need the (ChecksumResult1)null change too?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not necessarily. This one is testing the exception that is thrown when no HTTP context is provided (ref) which happens before we asset on the IResult type being null.

@captainsafia captainsafia enabled auto-merge (squash) August 22, 2024 18:34
@captainsafia captainsafia merged commit bf37c27 into main Aug 22, 2024
26 checks passed
@captainsafia captainsafia deleted the 57360 branch August 22, 2024 19:20
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview1 milestone Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc area-networking Includes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Test failure: no exception in ResultsOfTResult1TResult2_Throws_InvalidOperationException_WhenResultIsNull
3 participants