ardalis / CleanArchitecture

Clean Architecture Solution Template: A starting point for Clean Architecture with ASP.NET Core
MIT License
16.25k stars 2.8k forks source link

Test case ReturnsTwoContributors() fails #682

Closed yogyogi closed 7 months ago

yogyogi commented 7 months ago

Test function ReturnsTwoContributors() fails.

Steps to Reproduce:

  1. Download the repository.
  2. Run all the tests and will see ReturnsTwoContributors() is failing.

The error screenshot:

test-error

Error Message:

Message: 
System.Net.Http.HttpRequestException : Response status code does not indicate success: 500 (Internal Server Error).

Stack Trace: 
HttpResponseMessage.EnsureSuccessStatusCode()
HttpClientGetExtensionMethods.GetAndDeserializeAsync[T](HttpClient client, String requestUri, ITestOutputHelper output)
ContributorList.ReturnsTwoContributors() line 16
--- End of stack trace from previous location ---
ParsaMehdipour commented 7 months ago

Have you put a break point and se what has happened? So we can see the real reason of the internal error

yogyogi commented 7 months ago

I have provided error message itself.

ParsaMehdipour commented 7 months ago

@yogyogi

As shown and commented in the code, the database is InMemory and the query will not execute

image

ParsaMehdipour commented 7 months ago

@yogyogi

If you want the test to pass you can use the LINQ query instead of SQL raw query

yogyogi commented 7 months ago

@ParsaMehdipour I think all test should pass beforehand. People should not have to do manual settings on the fresh download copy. I have also seen the previous version of this repo where all test were passing so this is probably a bug that needs to be corrected.

mickymcq commented 7 months ago

The issue appears to be two things. The column name needs to be aliased to PhoneNumber (to work with ContributorDTO) and NULL values need to be set to an empty string since PhoneNumber on the ContributorDTO is string and not string?. Updating the SQL to the following allows the test to pass (at least for sqlite which is the current default I believe):

SELECT Id, Name, COALESCE(PhoneNumber_Number, '') AS PhoneNumber FROM Contributors

I'll submit a PR for the change if no one has any objections?