Revenger
Revenger
CC#
Created by Krzak on 7/4/2024 in #help
Learning how to test API with NUnit and Nsubstitute
This explains it a bit more in detail: https://goodjava.org/blog?rec_id=17
22 replies
CC#
Created by Krzak on 7/4/2024 in #help
Learning how to test API with NUnit and Nsubstitute
Does that make sense?
22 replies
CC#
Created by Krzak on 7/4/2024 in #help
Learning how to test API with NUnit and Nsubstitute
His point whas that you shouldn't make a generic "get" method with a predicate, and instead scope your fetches from the database to the contexts their in. For example a method that explicitly only "getsAllPeople" or whatever from the database.
22 replies
CC#
Created by Krzak on 7/4/2024 in #help
Learning how to test API with NUnit and Nsubstitute
He basically told you what is stated on that blog i sent you, and inserted and opinion on the use of generic repo's. Not sure that you indicated that you where making such interfaces, but whatever 🙂 You can spin up a new instance of your db in memory and execute your tests as you would on a normal DB. If your list is very long you could consider using .skip and .take to page? the results, so you don't send too long a response 🙂
22 replies
CC#
Created by Krzak on 7/4/2024 in #help
Learning how to test API with NUnit and Nsubstitute
If you want to run tests against your database context, you could look into the Repository Pattern: https://learn.microsoft.com/en-us/ef/core/testing/testing-without-the-database#:%7E:text=As%20discussed%20in%20the%20testing%20overview%20page%2C%20using%20the%20in%2Dmemory%20provider%20for%20testing%20is%20strongly%20discouraged%3B%20consider%20using%20SQLite%20instead%2C%20or%20implementing%20the%20repository%20patternv Basically you can wrap your database context and use the DB in memory instead, then use it as you would normally 🙂
22 replies