moq No setups configured error, how to quickly add a setup properly

I have a unit test with moq in which I am getting an error that I need to do a setup, I do see examples, but everything is so different that I am wanting to do a a proper moq setup

Error: "Expected invocation on the mock at least once, but was never performed: called => called.SetWidgetResponseResponseData("searchType", It.IsAny()) No setups configured."

All 3 of these tests fail

[TestMethod]
public void it_should_call_set_response_response_data_on_the_view_reccount()
{
   view.Verify(called => called.SetWidgetResponseResponseData("recCount",It.IsAny<string>()));
}

[TestMethod]
public void it_should_call_set_response_response_data_on_the_view_searchtype()
{
  view.Verify(called => called.SetWidgetResponseResponseData("searchType", It.IsAny<string>()));
}

[TestMethod]
public void it_should_call_set_response_response_data_on_the_view_isgeosearch()
{
  view.Verify(called => called.SetWidgetResponseResponseData("isGEOSearch", It.IsAny<bool>()));
}

I think that the error is because "res" needs to be mocked with moq with a setup right?

if (res != null && res.Count > 0)
{ 

    View.SetWidgetResponseResponseData("recCount", res.Count.ToString());
    View.SetWidgetResponseResponseData("searchType", provFacSearchCrt.SearchType);
    View.SetWidgetResponseResponseData("isGEOSearch", provFacSearchCrt.IsGeoSearch);
}

Update

   public abstract class ProviderSearchPresenterContext :   Specification<Tc.Cbc.Presentation.ProviderSearchPresenter>
{
    protected Mock<ICESBaseWidgetView> view = new Mock<ICESBaseWidgetView>();
    protected Mock<ILookupServiceManager> lookupService = new Mock<ILookupServiceManager>(MockBehavior.Loose);
    protected Mock<ICAPProviderService> capProvider = new Mock<ICAPProviderService>(MockBehavior.Loose);
    protected Mock<IProviderFacilityServiceManager> prvFacServiceMgr = new Mock<IProviderFacilityServiceManager>(MockBehavior.Loose);
    //protected Mock<ProviderFacilitySearchCriteria> provFacSearchCrt = new Mock<ProviderFacilitySearchCriteria>(MockBehavior.Loose);
    protected Mock<ICESTraceManager> traceManager = new Mock<ICESTraceManager>();
    protected Mock<ILogger> logger = new Mock<ILogger>();
    protected Mock<IResourcesHelper> resources = new Mock<IResourcesHelper>();
    protected Mock<IUserContext> userContext = new Mock<IUserContext>();

    protected NameValueCollection QueryString = new NameValueCollection();
    protected NameValueCollection Form = new NameValueCollection();
    protected Dictionary<string, string> MethodArguments = new Dictionary<string, string>();

    protected override Tc.CES.Presentation.ProviderSearchPresenter construct()
    {
        //capProvider.Setup(x => x.GetProvider(It.Is<GetProviderReqMsg>(y => y.GetProvider.ProviderSystemIDs[0].SystemIDName == CESConstants.PROVIDER_ID 
        //    && y.GetProvider.ProviderSystemIDs[0].SystemIDValue == CESConstants.TZCOMMON))).Returns(new GetProviderRespMsg { 

        var presenter = new Tc.CES.Presentation.ProviderSearchPresenter(view.Object, traceManager.Object, logger.Object, resources.Object, 
            userContext.Object, lookupService.Object, capProvider.Object, prvFacServiceMgr.Object);
        presenter.QueryString = QueryString;
        presenter.Form = Form;
        presenter.MethodArguments = MethodArguments;
        return presenter;
    }

    protected override void given() { }

    protected override void when()
    {
        QueryString["ProFacSearch"] = "FACILITY";
        sut.ShowProviderSearch(null, null);
    }
}

The Specification class looks like this:

[TestClass]
public abstract class Specification<SUT>
{
    protected SUT sut;

    [TestInitialize]
    public void Initialize()
    {
        sut = construct();

        given();

        when();
    }

    protected abstract SUT construct();
    protected abstract void given();
    protected abstract void when();
}

Answers


Ok, I fixed it. I added a Setup like this:

this.prvFacServiceMgr.Setup(call =>     call.SearchProviderFacility(It.IsAny<ProviderFacilitySearchCriteria>())).Returns(new List<ProviderFacilitySearchResult>() 
        { 
            new ProviderFacilitySearchResult()
            { 
                ProviderName="TestProvider"
            } 
        });

Need Your Help

Implement Factory pattern using Generics once and for all

c# oop generics inheritance

Consider this. I want to create a factory (the pattern, not planing a new genesis) that creates animals. I thought I would be smart and create a class that has the 3 things I will need for this to ...

Python facebook-sdk Graph api access error

python facebook-graph-api facebook-access-token

I am using Python facebook-sdk to fetch users's posts in Facebook page.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.