I have the following class that needs to be tested.
public ReportViewModel
{
public ReportViewModel()
{
using (var repository = new ExecutionDetailsReportRepository())
{
this._reportData= repository.GetExecutionDetailsReport(testManager.ExecutionDetail.ExecutionId);
}
}
}
The constructor creates a new ExecutionDetailsReportRepository and this needs to be mocked
My Test method has the mock setup like this
var mockExecutionDetailsReportRepository = new Mock<IExecutionDetailsReportRepository>(MockBehavior.Loose);
mockExecutionDetailsReportRepository.Setup(ed => ed.GetExecutionDetailsReport(null)).Returns((List<ExecutionDetailsReport> x) => x).Verifiable();
GetExecutionDetailsReport takes a int? as parameter type. I tried setting it up with 0 or It.IsAny but still my test ends up createing a new real instance of GetExecutionDetailsReport rather than using the Mocked instance.
Please help me understand what is wrong in my Mock Setup? Im using Moq 4.0
usingblock, I'm not quite sure how you want to mock that. - Patryk Ćwiek