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

Update Chapter 07 Integration Tests to use FluentAssertions.Web extensions #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

adrianiftode
Copy link

I noticed you are using FluentAssertions.Web for API testing, so I'm adding this PR to exemplify some of the usages in Chapter 07. FluentAsertions.Web does not only have nice extensions around the HttpResponse, but it also provides useful outputs when the tests are failing.

For example, if you would pass an invalid Bearer token, you would get the following message in the Test Detail Summary

 AuthenticationTests.Auth_ShouldGetPastAuthEndpointJWT
   Source: Integration.Tests.cs line 42
   Duration: 762 ms

  Message: 
Expected response to be HttpStatusCode.OK {value: 200}, but found HttpStatusCode.Unauthorized {value: 401}.

The HTTP response was:

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer error="invalid_token"


The originating HTTP request was:

GET http://localhost/api/Auth/testAuth HTTP 1.1
Authorization: Bearer invalid-token


  Stack Trace: 
XUnit2TestFramework.Throw(String message)
TestFrameworkProvider.Throw(String message)
DefaultAssertionStrategy.HandleFailure(String message)
AssertionScope.FailWith(Func`1 failReasonFunc)
AssertionScope.FailWith(Func`1 failReasonFunc)
AssertionScope.FailWith(String message, Object[] args)
HttpResponseMessageAssertions.Be200Ok(String because, Object[] becauseArgs)
HttpStatusCodeAssertionsExtensions.Be200Ok(HttpResponseMessageAssertions`1 parent, String because, Object[] becauseArgs)
AuthenticationTests.Auth_ShouldGetPastAuthEndpointJWT() line 50
--- End of stack trace from previous location ---

image

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

Successfully merging this pull request may close these issues.

1 participant