Skip to content

Instantly share code, notes, and snippets.

@ninjarobot
Created June 3, 2025 14:53
Show Gist options
  • Save ninjarobot/86e619d58f2328dc6ae4bcb68f51572f to your computer and use it in GitHub Desktop.
Save ninjarobot/86e619d58f2328dc6ae4bcb68f51572f to your computer and use it in GitHub Desktop.
ARM deployment mocking in F#
#r "nuget:Azure.ResourceManager.Resources"
#r "nuget:Azure.ResourceManager"
#r "nuget:Moq"
open Moq
open Azure.ResourceManager
open Azure.ResourceManager.Resources
open Azure.ResourceManager.Resources.Models
open Azure.ResourceManager.Resources.Mocking
// Build up the deployment to be returned.
let armDeploymentMock = Mock<ArmDeploymentResource>()
armDeploymentMock.SetupGet(_.Data).Returns(
ArmResourcesModelFactory.ArmDeploymentData(properties =
ArmResourcesModelFactory.ArmDeploymentPropertiesExtended(provisioningState = ResourcesProvisioningState.Succeeded)
)
)
// Create a Response with that deployment.
let responseMock = Mock<Azure.Response<ArmDeploymentResource>>()
responseMock.SetupGet(_.Value).Returns(armDeploymentMock.Object)
// Set up the mockable resource where the extension method is called.
let mockableRg = Mock<MockableResourcesResourceGroupResource>()
mockableRg.Setup(fun rg -> rg.GetArmDeployment(It.IsAny<string>())).Returns(responseMock.Object)
// Mock the resource to use the cached client from the mockable resource.
let rgMock = Mock<ResourceGroupResource>()
rgMock.Setup(fun rg -> rg.GetCachedClient(It.IsAny<System.Func<ArmClient,MockableResourcesResourceGroupResource>>())).Returns(mockableRg.Object)
// Finally call the mocked method.
let dep = rgMock.Object.GetArmDeployment("foo")
dep.Value.Data.Properties.ProvisioningState
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment