https://pulumi.com logo
#dotnet
Title
# dotnet
f

flat-mouse-20634

03/29/2021, 8:01 AM
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

prehistoric-coat-10166

03/29/2021, 9:47 AM
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

flat-mouse-20634

03/29/2021, 10:52 AM
Nice, that worked like a charm