DEV Community

Discussion on: Tutorial: MongoDB With C# The Easy Way!

Collapse
 
anthopark profile image
Anthony Park • Edited

This tremendously helped! I'm now thinking of testing a service object that depends on the repository. I'm thinking of try DB.InitAsync with mongo2go in the xunit project and was wondering if you have some suggestions around the right way to mocking the DB connection with your library.. Thanks a ton!

Thread Thread
 
djnitehawk profile image
Dĵ ΝιΓΞΗΛψΚ

integration testing is the recommended approach. something like this if it's a web api project.

however I think doing db.initasync with mongo2go address in the setup/class fixture should do the trick.

let me know if it doesn't and I'll have a deeper look.

Thread Thread
 
anthopark profile image
Anthony Park

Thanks for the quick response! I was able to connect to Mongo2Go with your library but came across an issue which I've described in your repo issues.

I think I may need to use Xunit's class fixture and persist the connection throughout the test cases in a test class.