Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

682
Vistas
How to verify a Dictionary parameter?

I am using the Moq framework.

Given is the following code:

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 => ??? ) ) );
}

I know how to verify the properties of an interface parameter (ISomeContainer), but how is this possible with a Dictionary?

I would like to verify that the DoWork method is called with a simple Dictionary that contains only one key-value-pair KeyA + ValueA.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

It.Is anticipates a delegate where the parameter is the current value and the return type bool.

So, in your case: Func<Dictionary<string, object>, bool>

In order to test your assumptions you can create the following helper method:

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;
}

then you can call the Verify like this:

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda