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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:18:20+00:00 2026-06-13T07:18:20+00:00

I have the following code: var connector = new Mock<IConector>(); connector .Setup(cn => cn.listar(FetchEstandar,

  • 0

I have the following code:

var connector = new Mock<IConector>();

connector
    .Setup(cn => cn.listar("FetchEstandar", new Estandar(), new {Id = 1}))
    .Returns(new List<Estandar>{ new Estandar {Id = 1} });

 var entidad = connector.Object
     .listar("FetchEstandar", new Estandar(), new {Id = 1});

when I call listar on the connector Object, I get an "Expression Cannot Contain an Anonymouse Type" error. I’ve tried with rhino mocks and moq.

Is there any way I can mock this method? am I doing something wrong? alternatively, I could ignore this parameter but I don’t know how. I really just need to test the value of the first parameter and ignorearguments works but I have no idea whether or how I can get this value if I use it

  • 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-06-13T07:18:21+00:00Added an answer on June 13, 2026 at 7:18 am

    I do not know if this is the only way to match an anonymous object but it can be done using It.Is<>() and reflection

    public class Estandar {
        public int Id { get; set; }
    }
    
    public interface IConector {
        IEnumerable<Estandar> listar(string name, Estandar estandar, object key);   
    }
    
    
    [TestMethod]
    public void CheckAnonymous() {
    
        var connector = new Mock<IConector>();
    
        connector.Setup(cn => cn.listar("FetchEstandar",
                                        It.IsAny<Estandar>(),
                                        It.Is<object>(it => MatchKey(it, 1))))
                 .Returns(new List<Estandar> { new Estandar { Id = 1 } });
    
        var entidad = connector.Object.listar("FetchEstandar", new Estandar(), new { Id = 1 });
    
        Assert.AreEqual(1, entidad.Count());
    
    }
    
    public static bool MatchKey(object key, int soughtId) {
        var ret = false;
        var prop = key.GetType().GetProperty("Id");
        if (prop != null) {
            var id = (int)prop.GetValue(key, null);
            ret = id == soughtId;
        }
        return  ret;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: var carsContext = new CarsDataContext(); IQueryable<Car> allCars = carsContext.Cars;
I have the following code: var tlp = new TableLayoutPanel { Location = new
I have the following code try { using (var connection = new SqlConnection(Utils.ConnectionString)) {
I have the following code: var submitHandler = function ($link, $form, close) { var
I have the following code: var refreshId = setInterval(function() { $(#footad).html('myjshere'); }, 15500); Where
I have the following code var dbvalue = Ned; var deleteLink = '<a href=#delete
I have the following code: var sl: THashedStringList; begin sl:= THashedStringList.Create; sl.Duplicates := dupIgnore;
I have the following code: var bool:String = true; Without an if block or
I have the following code: var GoalPanelView = Backbone.View.extend({ // Bind to the goal
I am using ASP.NET 3.5 with iTextSharp and I have the following code: var

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.