Mock CloudBlobClient with AutoFac and AutoMock

后端 未结 3 525
误落风尘
误落风尘 2021-01-14 10:07

I\'m trying to write unit tests for my AzureBlobRepository. The repository receives a CloubBlobClient in the constructor. I want to mock the client, but this gives an except

3条回答
  •  -上瘾入骨i
    2021-01-14 10:45

    See this CloudBlobContainer. This type contains three constructors. And constructor is required for create instance of type. Try to type in your code new CloudBlobContainer and you will need to choose one of three constructors. AutoMock cannot know what constructor must choose.

    You can say to AutoMock how to create CloudBlobContainer

    Sample:

    using (var mock = AutoMock.GetLoose())
    {
        mock.Provide(new NamedParameter("uri", new Uri("your uri")));
        var mockClient = mock.Mock();
    }
    

提交回复
热议问题