Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6890279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:15:43+00:00 2026-05-27T06:15:43+00:00

I have a unit test with moq in which I am getting an error

  • 0

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();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:15:43+00:00Added an answer on May 27, 2026 at 6:15 am

    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"
                } 
            });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a unit test that works fine locally but when uploaded to TeamCity
I have a unit test that tests if an Exception is throw, but this
I have a unit test which contains the following line of code Site.objects.get(name=UnitTest).delete() and
I have a unit test that creates a mock calls my method to be
I have 1 unit test method that needs several parameters. I would like to
I have the following unit test: [TestMethod] public void Execute_Sends_Email_To_User() { // Setup InitializeTestEntities();
I have a unit test where I have statically defined a quite large byte
I have a unit test (example is modified Test::Unit documentation ) require 'test/unit' class
I have a unit test where I run a method for every item in
I have a unit test called TestMakeAValidCall() . It tests my phone app making

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.