Hello All, I am migrating C# code from classic Azu...
# dotnet
f
Hello All, I am migrating C# code from classic Azure to Azure-Native which is going well so far but I am facing a small issue with unit tests. Here is the code that I’d like to test
Copy code
var resourceGroup = new ResourceGroup("mystaticsite");
var storageAccount = new StorageAccount("mysite", new StorageAccountArgs
{
    ResourceGroupName = resourceGroup.Name,
    EnableHttpsTrafficOnly = true,
    Sku = new SkuArgs
    {
        Name = SkuName.Standard_LRS
    },
    AccessTier = AccessTier.Hot,
    Kind = Kind.StorageV2,
});
PrimaryWebEndpoint = storageAccount.PrimaryEndpoints.Apply(x=>x.Web);
My test is trying to verify that the ResourceGroup was created
Copy code
private static Task<ImmutableArray<Pulumi.Resource>> TestAsync()
{
    return Pulumi.Deployment.TestAsync<WebsiteStack>(new Mocks(), new TestOptions {IsPreview = false});
}

[Fact]
public async Task ResourceGroup_ShouldExist()
{
    var resources = await TestAsync();

    var resourceGroups = resources.OfType<ResourceGroup>().ToList();

    resourceGroups.Count.ShouldBe(1);
}
I couldn’t get the test to pass because I can’t find a way to mock
EndpointsResponse
Are there a recommended way to handle this scenario?
p
You should be able to mock the response by adding the named output inside NewResourceAsync for example inside your mock NewResourceAsync
Copy code
outputs.Add("primaryEndpoints", new Dictionary<string, object?>()
{
    {"blob", "BlobEndpoint"},
    {"dfs", "DfsEndpoint"},
    {"file", "FileEndpoint"},
    {"internetEndpoints", null},
    {"microsoftEndpoints", null},
    {"queue", "QueueEndpoint"},
    {"table", "TableEndpoint"},
    {"web", "WebEndpoint"},
});
f
Nice, that worked like a charm