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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:40:21+00:00 2026-05-10T20:40:21+00:00

I am writing an unit test for a mvc web application that checks if

  • 0

I am writing an unit test for a mvc web application that checks if a returned list of anonymous variables(in a jsonresult) is correct. therefore i need to iterate through that list but i cannot seem to find a way to do so.

so i have 2 methods

1) returns a json result . In that json result there is a property called data. that property is of type object but internally it’s a list of anonymous variables

2) the method calls method 1 and checks if the returned jsonresult is ok.

if i run the test and i break the debugger i can hover over the result and see the items in it. i just don’t find a way to do so in code.(just using a foreach isn’t possible because at the point i need it i’m not in the method that created the anonymous method)

  • 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. 2026-05-10T20:40:21+00:00Added an answer on May 10, 2026 at 8:40 pm

    I think you mean ‘anonymous type’ everywhere you’ve said ‘anonymous variable’ – but you can still iterate over the list with foreach, just declaring the iteration variable as type object:

    foreach (object o in myList) {     // Not sure what you're actually trying to do in here... } 

    If you need to check the contents, you can use the fact that anonymous types override ToString in a useful way. Your test can check the result of projecting each element to a string. Indeed, you could convert your result object to a sequence of strings quite easily:

    var strings = ((IEnumerable) result).Cast<object>.Select(x => x.ToString()); 

    Then test strings possibly using SequenceEqual.

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

Sidebar

Related Questions

We are writing unit tests for our ASP.NET application that run against a test
I have mvc application and I'm working with poco objects and writing unit test.
I am writing unit tests to test an MVC application. How can I validate
I'm writing a unit test for a method that packs boolean values into a
I'm writing a unit test for a Text Scrubber utility that will remove any
I am writing a c# unit test that validates string properties for an ORM
I'm having some difficulty writing some Unit Tests to test a custom ModelBinder that
I am writing unit tests against my ASP.NET MVC application, in particular I am
My team is writing a content-managed web-hosting application in ASP.Net MVC 2 with the
I'm writing unit tests for an MVC web app, and I've been getting null

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.