❔ Using Moq Library for test

I want to apply unit tests in .net framework using the Moq library. In this case, I have two projects, "Application.Test" and "Negocios". "Negocios" is referenced by "Application.Test" and contains the methods to be tested. However, when using Moq, I need to use an interface created in "Application". I cannot make a reference in "Negocios" because it would be cyclical. How can I solve this problem to perform unit tests of databases using a mock?
21 Replies
phaseshift
phaseshift2y ago
What's wrong with, test -> nego test -> appl ? Anyhow, you can always break a circular dependency by adding another layer
circular:
a
/ \
b <- c
circular:
a
/ \
b <- c
break the problem code out of b:
fixed
a
/ \
b' c
\ /
b''
fixed
a
/ \
b' c
\ /
b''
Leonardo_R08
Leonardo_R08OP2y ago
i only had two projects, application.test and negocios, thers no test for application
phaseshift
phaseshift2y ago
if you only have two regular projects and a test project, then how can there be a circular ref?
Leonardo_R08
Leonardo_R08OP2y ago
application.test reference negocios project i need to add an interfece in negocio, but i cand make the project reference, because should be a circular ref application.tes make de interface, negocios should have the ref but application.test is referenced with negocios
phaseshift
phaseshift2y ago
You're making an interface in the test project? no...
Leonardo_R08
Leonardo_R08OP2y ago
yes
phaseshift
phaseshift2y ago
that's why... That's wrong
Leonardo_R08
Leonardo_R08OP2y ago
moq library examples make that for mocking
phaseshift
phaseshift2y ago
make what?
Leonardo_R08
Leonardo_R08OP2y ago
moq examples uses interface in test project for mocking then the class in tested project shoul use the interface
phaseshift
phaseshift2y ago
the interface is meant to come from your code project Otherwise what is the point...
Leonardo_R08
Leonardo_R08OP2y ago
okay, so, the mock item should be in my project code aslo ?
phaseshift
phaseshift2y ago
nooooo Are you sure you know what mock/moq is for?
Leonardo_R08
Leonardo_R08OP2y ago
im only telling you what i saw from moq example
phaseshift
phaseshift2y ago
It's just an example. Sounds like a bad one or you misunderstood
Leonardo_R08
Leonardo_R08OP2y ago
can you show me a link with a propper example ?
phaseshift
phaseshift2y ago
well there will be examples on the github for it
Leonardo_R08
Leonardo_R08OP2y ago
can you show me at least one ?
phaseshift
phaseshift2y ago
https://github.com/moq/moq4 on the main page The problem sounds like your code tbh
Leonardo_R08
Leonardo_R08OP2y ago
thanks, im going to watch mor about it
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server