question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUERY] How to mock GetArmDeployments

See original GitHub issue

Library name and version

Azure.ResourceManager.Resources 1.1.0

Query/Question

We’re deploying an arm template using the Azure.ResourceManager packages, like so:

ResourceGroupResource resourceGroup = armClient.GetResourceGroupResource(resourceGroupId);
await resourceGroup.GetArmDeployments().CreateOrUpdateAsync(WaitUntil.Completed, CommonConstants.DeploymentName, content);

However, we’re running into issues with unit testing this code, as GetArmDeployments() is a static method which cannot be mocked. Is there any guidance or documentation on how to work around this? I found a similar question here: https://github.com/Azure/azure-sdk-for-net/issues/28861, and I’m wondering if there’s a factory we need to use.

Environment

Windows 10 .NET 6.0 Visual Studio 17.3.0

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
Yao725commented, Feb 21, 2023

Sorry for the delayed response, we already have an internal discussion about mocking extension methods and now I’m working on it.

2reactions
jnlycklamacommented, Apr 18, 2023

+1 to this issue. Would love to be able to mock out these static methods for Azure.ResourceManager.* packages. Is there any update on this @Yao725 ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

ResourceGroupResource Class (Azure.ResourceManager. ...
Initializes a new instance of the ResourceGroupResource class for mocking. ... Queries policy events for the resources under the resource group.
Read more >
ResourcesManagementGroupM...
Mocking. Assembly: Azure.ResourceManager.Resources.dll. Package: Azure.ResourceManager. ... ArmDeploymentCollection GetArmDeployments ();
Read more >
Mock Azure Function HttpTrigger and Setup Query String
You can create a new instance of QueryCollection (read this) and setup the mock. var mockDict = new Dictionary<string, StringValues> { { "key1", ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found