Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

680
Views
¿Cómo verificar un parámetro del diccionario?

Estoy usando el marco Moq.

Se da el siguiente código:

 public interface ISomeInterface { SomeResult DoWork( ISomeContainer foo, Dictionary<string, object> bar ); } [ Test ] public void SomeTest() { Mock<ISomeInterface> mock = new Mock<ISomeInterface>(); mock.Setup( m => m.DoWork( It.IsAny<ISomeContainer>(), It.IsAny<Dictionary<string, object>>() ) ); new Cut( mock ).DoSomething(); mock.Verify( m => m.DoWork( It.Is<ISomeContainer>( c => c.SomeValue == "foo" ), It.Is<Dictionary<string, object>>( d => ??? ) ) ); }

Sé cómo verificar las propiedades de un parámetro de interfaz ( ISomeContainer ), pero ¿cómo es esto posible con un diccionario?

Me gustaría verificar que el método DoWork se llama con un diccionario simple que contiene solo un par clave-valor KeyA + ValueA .

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

It.Is anticipa un delegado donde el parámetro es el valor actual y el tipo de retorno bool.

Entonces, en su caso: Func<Dictionary<string, object>, bool>

Para probar sus suposiciones, puede crear el siguiente método auxiliar:

 private static bool AssertBar(Dictionary<string, object> bar) { Assert.Single(bar); Assert.Equal("KeyA", bar.Keys.Single()); Assert.Equal("ValueA", bar.Values.Single()); return true; }

entonces puedes llamar a Verify así:

 mock.Verify( m => m.DoWork( It.Is<ISomeContainer>(c => AssertFoo(c)), It.Is<Dictionary<string, object>>(d => AssertBar(d))), Times.Once);
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!