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

827
Vistas
Mocking Azure BlobItem - C# unit test

I have some unit tests where I want to mock the Azure BlobItem class (Azure.Storage.Blobs.Models).

Here is my test class I'm using. I want the Values getter to return a list with a mock BlobItem. That is working.

public class TestPage : Page<BlobItem>
{
    public override IReadOnlyList<BlobItem> Values
    {
        get
        {
            return new List<BlobItem>() { new Mock<BlobItem>().Object };
        }
    }

    public override string ContinuationToken => throw new NotImplementedException();

    public override Response GetRawResponse()
    {
        throw new NotImplementedException();
    }
}

However when I do this, the Name property on my mock BlobItem is always null.

I can try to set it up so that Name would return a mocked value like so:

var mock = new Mock<BlobItem>();
mock.SetupGet(x => x.Name).Returns("mock");

But then I get an error:

Non-overridable members may not be used in setup/verification expressions.

I understand why this error is happening. But I do not know what the solution is.

I want a mocked BlobItem to return a non-null Name value. How can I achieve this?

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

0

Apparently there's a factory class called BlobsModelFactory.

You can mock a BlobItem with whatever name you want by calling:

var blob = BlobsModelFactory.BlobItem("mocked.mocked.mocked.mocked")
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