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

  • SEARCH
  • Home
  • 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 872829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:50:35+00:00 2026-05-15T10:50:35+00:00

Can someone please help? I use Google code’s Moq framework for mocking within my

  • 0

Can someone please help?

I use Google code’s Moq framework for mocking within my Unit Tests and Unity for Dependency Injection.

In my Test class

private Mock<ICustomerSearchService> CustomerSearchServiceMock = null;
private CustomerService customerService = null;

private void SetupMainData()
{
    CustomerSearchServiceMock = new Mock<ICustomerSearchService>();
    customerService = new CustomerService ();

    // CustomerSearchService is a property in CustomerService and dependency is  configuered via Unity
    customerService.CustomerSearchService = CustomerSearchServiceMock.Object;

     Customer c = new Customer ()
     {
         ID = "AT"
     };

     CustomerSearchServiceMock.Setup(s => s.GetCustomer(EqualsCondition)).Returns(c); 
}


[TestMethod]
public void GetCustomerData_Test_Method()
{
    SetupMainData()
    var customer = customerService.GetCustomerData("AT");
}


 public static bool EqualsCondition(Customer customer)
 {
     return customer.ID.Equals("AT");
 }

CustomerService class

public class CustomerService : ICustomerService
{

    [Dependency]
    public ICustomerSearchService CustomerSearchService { get; set; }


    public IEnumerable<SomeObject> GetCustomerData(string custID)
    {

      I GET Null for customer ?????}
      var customer = CustomerSearchService.GetCustomer (c => c.ID.Equals(custID));

       //Do more things
    }
}

When I debug the code I can see CustomerSearchService has a proxy object, but the customer returns as null. Any ideas? Or is there something missing here?


Note: ICustomerSearchService I have implemented below method.

     Customer GetCustomer(Func<Customer, bool> predicate);
  • 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-15T10:50:36+00:00Added an answer on May 15, 2026 at 10:50 am

    I’ve seen this problem in Rhino.Mocks too (mocking, lambdas and stubbing/expectations). See:

    http://groups.google.com/group/rhinomocks/msg/318a35ae7536d90a

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this code to merge two images. Can someone please help me to
Please can someone help? I have the following code which uploads a file to
Can someone please help me out? My code for splitting the strings is working
Can someone please help me with a very simple example on how to use
With real examples and their use, can someone please help me understand: How to
With real examples and their use, can someone please help me understand: When do
Can someone help me out please, as google is not providing the answers. I've
Just wondering if someone can help me code the following. I want to use
Can someone please help to clarify? Also, please mention if there are other representation
can someone please help me out? I'm trying to create an input dynamically with

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.