1

I want to create a unit test method to ensure that all repositories are being passed through the constructor.

I believe that using Moq repositories may be the best solution here, but so far I have not been able to verify that the test method passes.

Controller:

public AgentsController(ICallBoardStatsRepo callBoardRepo)
{
    _callBoardRepo = callBoardRepo;
}

Interface:

public interface ICallBoardStatsRepo:IDisposable
{
    CallBoardStats ById(int clientId);
    ClientCalls ByIdNavStats(int clientId);
}

My current test method for the repository constructor looks like the following:

[TestMethod]
public void AgentController_Test()
{
    var myCallBoard = new Mock<AgentCallStats>();
    var myTestCallBoard = new Mock<AgentCallStats>();

    var callBoardList = new List<AgentCallStats>() { myCallBoard.Object, myTestCallBoard.Object };
    var ICallBoard = new Mock<IAgentCallStatsRepo>();
    ICallBoard.Setup(x => x.ById(2)).Returns(callBoardList);

    myCallBoard.Verify(x => x.Equals(It.IsAny<int>()), Times.Once());
    myTestCallBoard.Verify(x => x.Equals(It.IsAny<int>()), Times.Once());
 }

When running the individual test method, I get an error looking something like:

Expected invocation on the mock once, but was 0 times

I am not very experienced in writing unit tests, and this is really throwing me for a loop. Would anyone be willing to help point me in the right direction? I feel like I am close to solving this, but maybe an extra set of eyes may be able to highlight the problem. Thank you.

kara
  • 3,205
  • 4
  • 20
  • 34
SamRR_75
  • 729
  • 8
  • 18

0 Answers0