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 7489757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:22:02+00:00 2026-05-29T15:22:02+00:00

I’ve got a method which takes a IList<Person> and returns an IEnumberable as so:

  • 0

I’ve got a method which takes a IList<Person> and returns an IEnumberable as so:

 internal static IEnumerable<Dictionary<string, string>> GetPersonsPerSite(IList<Person> Data)
    { 
         //Implementation ...
    }

and I’m trying to create a mock object of IList<Person> so I can test this method.

Using Moq I have written the following:

var mockObjects = new Mock<IList<Person>>();

mockObjects.Setup(x => x[0]).Returns(new Person()
                                                 {
                                                        SITE_ID = "test",
                                                        MPAN = "test",
                                                        ADDLINE1 = "test",
                                                        ADDLINE2 = "test",
                                                        ADDRESS_LINE_1 = "test",
                                                        ADDRESS_LINE_2 = "test"
                                                 });

However when I come to use the object the IEnumerable returned is aways throwing exception Object reference not set to an instance of an object.

I’m brand new to Moq, and I’m pretty sure I’m missing a fundamental concept here, however I’ve successfully being able to throw exceptions and modifiy outputs with other mock objects.

I’d appreciate if someone could point me in the right direction.

  • 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-29T15:22:04+00:00Added an answer on May 29, 2026 at 3:22 pm

    Don’t mock the IList. You don’t need to, unless there’s something specific your looking to check.

    Instead just keep your test simple and do something like this:

    var testData = new List<Person>(){new Person()
                                                     {
                                                            SITE_ID = "test",
                                                            MPAN = "test",
                                                            ADDLINE1 = "test",
                                                            ADDLINE2 = "test",
                                                            ADDRESS_LINE_1 = "test",
                                                            ADDRESS_LINE_2 = "test"
                                                     }};
    var result = GetPersonsePerSite(testData);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
i got an object with contents of html markup in it, for example: string
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small

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.