The original method it still called when i try to use Moq. Here is my code:
var mockedBetRepository = new Mock<BetRepository>(new FakeSiteContext());
mockedBetRepository.CallBase = true;
Bet bet = new Bet();
mockedBetRepository.Setup<Bet>(m => m.UpdateBet(bet)).Returns(bet);
betRepository = mockedBetRepository.Object;
Later in the code, betRepository.UpdateBet(bet)
is called, but its not my mocked method which gets called, instead, the class's method gets called:
public virtual Bet UpdateBet(Bet betToUpdate)
{
siteContext.Entry(betToUpdate).State = System.Data.EntityState.Modified;
siteContext.SaveChanges();
return betToUpdate;
}
Why it this happening?
I have found the problem.
If i replace
Bet bet = new Bet();
mockedBetRepository.Setup<Bet>(m => m.UpdateBet(bet)).Returns(bet);
with this
mockedBetRepository.Setup<Bet>(m => m.UpdateBet(It.IsAny<Bet>())).Returns((Bet b) => b);
Then it works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With