I working on UnitTests and want to mock Azure.Storage.Blobs, what is working so long but for ShimBlockBlobClient.GetBlockListaSync (GetBlockListAsyncBlockListTypesStringBlobRequestConditionsCancellationToken) I running into a problem.
For the resulting List I need to create a Azure.Storage.Blobs.Models.Fakes.ShimBlockList containing two lists of Azure.Storage.Blobs.Models.BlobBlock. BlobBlock has no public constructor and the generated ShimBlobBlock has also no public construtor.
var fake = new Azure.Storage.Blobs.Specialized.Fakes.ShimBlockBlobClient()
{
/*Some other Fake Func<> definitions*/
,
GetBlockListAsyncBlockListTypesStringBlobRequestConditionsCancellationToken =
async (type, stringValue, condition, token) =>
{
await Task.Delay(1);
return GetBlockList();
}
};
ar baseClass = new Azure.Storage.Blobs.Specialized.Fakes.ShimBlobBaseClient(fake)
{
NameGet = () => name,
/* Some more Fake Func<> definitions*/
};
private static Response<BlockList> GetBlockList()
{
var commited = new List<Azure.Storage.Blobs.Models.BlobBlock>();
commited.Add(new BlobBlock("1", Data.Length)); // How to add here some value to the List
/*commited.Add(new ShimBlobBlock()); does not work as it is generated as private construcor*/
return new Azure.Fakes.StubResponse<Azure.Storage.Blobs.Models.BlockList>()
{
ValueGet = () =>
{
return new Azure.Storage.Blobs.Models.Fakes.ShimBlockList()
{
CommittedBlocksGet = () => { return commited; },
UncommittedBlocksGet = () => { return new List<Azure.Storage.Blobs.Models.BlobBlock>(); },
};
}
};
}
As ShimBlobBlock.AllInstances not contain a replacement for Constructors I can not use that what was my secound try.