|
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using Aspire.Hosting.Utils;
namespace Aspire.Hosting.Azure.Tests;
public class AzureAppServiceEnvironmentExtensionsTests
{
[Fact]
public void AddAsExistingResource_ShouldBeIdempotent_ForAzureAppServiceEnvironmentResource()
{
// Arrange
var appServiceEnvironmentResource = new AzureAppServiceEnvironmentResource("test-app-service-env", _ => { });
var infrastructure = new AzureResourceInfrastructure(appServiceEnvironmentResource, "test-app-service-env");
// Act - Call AddAsExistingResource twice
var firstResult = appServiceEnvironmentResource.AddAsExistingResource(infrastructure);
var secondResult = appServiceEnvironmentResource.AddAsExistingResource(infrastructure);
// Assert - Both calls should return the same resource instance, not duplicates
Assert.Same(firstResult, secondResult);
}
[Fact]
public async Task AddAsExistingResource_RespectsExistingAzureResourceAnnotation_ForAzureAppServiceEnvironmentResource()
{
using var builder = TestDistributedApplicationBuilder.Create();
var existingName = builder.AddParameter("existing-appenv-name");
var existingResourceGroup = builder.AddParameter("existing-appenv-rg");
var appServiceEnvironment = builder.AddAzureAppServiceEnvironment("test-app-service-env")
.AsExisting(existingName, existingResourceGroup);
var module = builder.AddAzureInfrastructure("mymodule", infra =>
{
_ = appServiceEnvironment.Resource.AddAsExistingResource(infra);
});
var (manifest, bicep) = await AzureManifestUtils.GetManifestWithBicep(module.Resource, skipPreparer: true);
await Verify(manifest.ToString(), "json")
.AppendContentAsFile(bicep, "bicep");
}
} |