mmacneil / fullstack-jobs

Real(ish) demo using Angular with ASP.NET Core GraphQL and IdentityServer.
https://fullstackmark.com/post/22/build-an-authenticated-graphql-app-with-angular-aspnet-core-and-identityserver-part-1
MIT License
88 stars 31 forks source link

CanLogin and CanCreateJobPosting fail despite using InMemory database #2

Closed hellfirehd closed 4 years ago

hellfirehd commented 4 years ago

CanCreateAccount succeeds.

Error:

An unhandled exception occurred while processing the request. SqlException: Cannot open database "FullStackJobs" requested by the login. The login failed. Login failed for user 'DOMAIN\user'.

Repro:

Clone the project Open the solution Run the tests

Impact:

I was hoping to be able to run the tests on a CI server without having to configure a local database

mmacneil commented 4 years ago

Thanks for the report @hellfirehd - The culprit is IdentityServer's DbContext is using the hardwired connection string/DB instead of the InMemory database when running under the test.

This one should be easy to fix, I should be able to get it patched up tonight.

AuthServer Startup.cs

This line: options.ConfigureDbContext = ctxBuilder => ctxBuilder.UseSqlServer(Configuration.GetConnectionString(_connectionStringName));

needs to be something like this for testing: options.ConfigureDbContext = ctxBuilder => ctxBuilder.UseInMemoryDatabase("InMemoryDbForTesting");

mmacneil commented 4 years ago

Fixed: https://github.com/mmacneil/fullstack-jobs/commit/2d6a662ec1ed7c207f4ef9923de06211dc761251