[QUERY] - How do I mock an IPage<DeploymentOperation> for my unit tests
See original GitHub issueQuery/Question
I saw this blog post which provides an example of making a Page using the .FromValues
method but with the Azure Resource Manager SDK, I don’t see this exposed as an option when trying to mock a DeploymentOperations object.
We are specifically trying to setup a moq for this method:
ResourceManagerClient.DeploymentOperations.ListAtScopeWithHttpMessagesAsync
This method returns an object of type
Task<AzureOperationResponse<IPage<DeploymentOperation>>>
We have tried a number of things and been unable to create a Mock object of this type for unit testing. How do we convert our test response object into a Paged version? Note: making an AzureOperationResponce isn’t too hard, it’s the Page/IPage that is giving us grief.
var operationProperties = new DeploymentOperationProperties(
provisioningOperation: ProvisioningOperation.Create,
provisioningState:"complete",
DateTime.UtcNow,
duration:"2 minutes",
serviceRequestId:null,
statusCode: "OK",
statusMessage: new StatusMessage("OK"));
var myOperation = new DeploymentOperation(
id:"someid123", operationId:"hello",
properties: operationProperties);
var l = myOperation as Page<DeploymentOperation>;
This gives an error of:
Cannot convert type ‘Microsoft.Azure.Management.ResourceManager.Models.DeploymentOperation’ to ‘Microsoft.Azure.Management.ResourceManager.Models.Page<Microsoft.Azure.Management.ResourceManager.Models.DeploymentOperation>’ via a reference conversion, boxing conversion, unboxing conversion, wrapping conversion, or null type conversion
Documentation for this shows people using Page<T>.FromValues
which we do not see as available.
Environment:
- Name and version of the Library package used:
Microsoft.Azure.Management.ResourceManager. 3.13.1-preview - Hosting platform or OS and .NET runtime version (
dotnet --info
output for .NET Core projects): [e.g. Azure AppService or Windows 10 .NET Framework 4.8] - IDE and version : [e.g. Visual Studio 16.3]
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
The easiest might be to compy one of the existing page models that implement IPage and use it in tests:
https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/redis/Microsoft.Azure.Management.Redis/src/Generated/Models/Page.cs
Hi @1RedOne, since you haven’t asked that we “
/unresolve
” the issue, we’ll close this out. If you believe further discussion is needed, please add a comment “/unresolve
” to reopen the issue.