@@ -248,62 +248,74 @@ public async Task BicepResourceHasPipelineStepAnnotationWithCorrectConfiguration
248248 }
249249
250250 [ Fact ]
251- public async Task AzureBicepResourceWithTemplateFile_CanBePublished ( )
251+ public void GetBicepTemplateFile_WithTemplateFile_ReturnsOriginalPathWhenDirectoryProvided ( )
252252 {
253- // Arrange
253+ // This test verifies the fix for https://github.com/dotnet/aspire/issues/13967
254+ // When a templateFile is specified, GetBicepTemplateFile should return the original path
255+ // and not combine it with the directory parameter.
256+
254257 using var tempDir = new TestTempDirectory ( ) ;
255-
256- // Create a bicep file (simulating a file in the AppHost project)
258+
259+ // Create a test bicep file
257260 var bicepFileName = "test-template.bicep" ;
258261 var bicepFilePath = Path . Combine ( tempDir . Path , bicepFileName ) ;
259-
260- var bicepContent = """
261- param location string = resourceGroup().location
262- param testParameter string
263-
264- resource testResource 'Microsoft.Storage/storageAccounts@2021-09-01' = {
265- name: 'teststorage${uniqueString(resourceGroup().id)}'
266- location: location
267- sku: {
268- name: 'Standard_LRS'
269- }
270- kind: 'StorageV2'
271- tags: {
272- testParam: testParameter
273- }
274- }
262+ File . WriteAllText ( bicepFilePath , "param location string = resourceGroup().location" ) ;
275263
276- output storageEndpoint string = testResource.properties.primaryEndpoints.blob
277- """ ;
278- await File . WriteAllTextAsync ( bicepFilePath , bicepContent ) ;
279-
264+ // Create the AzureBicepResource with the templateFile
265+ var resource = new AzureBicepResource ( "test-resource" , templateFile : bicepFilePath ) ;
266+
267+ // Create a different directory to pass to GetBicepTemplateFile
280268 var outputDir = Path . Combine ( tempDir . Path , "output" ) ;
281- using var builder = TestDistributedApplicationBuilder . Create ( DistributedApplicationOperation . Publish , outputDir ) ;
269+ Directory . CreateDirectory ( outputDir ) ;
282270
283- // Add Azure Container App Environment (required for publishing)
284- builder . AddAzureContainerAppEnvironment ( "acaEnv" ) ;
271+ // Get the bicep template file with a directory parameter
272+ using var templateFile = resource . GetBicepTemplateFile ( outputDir ) ;
285273
286- // Add a bicep resource with a template file (using absolute path for test, but in real scenario this would be relative)
287- var bicepResource = builder . AddBicepTemplate ( "myresource" , bicepFilePath )
288- . WithParameter ( "testParameter" , "test-value" ) ;
274+ // The path should be the original template file path, not combined with outputDir
275+ Assert . Equal ( bicepFilePath , templateFile . Path ) ;
276+ Assert . True ( File . Exists ( templateFile . Path ) , $ "The template file should exist at { templateFile . Path } ") ;
277+ }
289278
290- // Act
291- using var app = builder . Build ( ) ;
292- app . Run ( ) ;
279+ [ Fact ]
280+ public void GetBicepTemplateFile_WithTemplateFile_ReturnsOriginalPathWithoutDirectory ( )
281+ {
282+ using var tempDir = new TestTempDirectory ( ) ;
293283
294- // Assert - Verify the bicep files were created
295- var mainBicepPath = Path . Combine ( outputDir , "main.bicep" ) ;
296- Assert . True ( File . Exists ( mainBicepPath ) , "main.bicep should be generated" ) ;
284+ // Create a test bicep file
285+ var bicepFileName = "test-template.bicep" ;
286+ var bicepFilePath = Path . Combine ( tempDir . Path , bicepFileName ) ;
287+ File . WriteAllText ( bicepFilePath , "param location string = resourceGroup().location" ) ;
288+
289+ // Create the AzureBicepResource with the templateFile
290+ var resource = new AzureBicepResource ( "test-resource" , templateFile : bicepFilePath ) ;
291+
292+ // Get the bicep template file without a directory parameter
293+ using var templateFile = resource . GetBicepTemplateFile ( ) ;
294+
295+ // The path should be the original template file path
296+ Assert . Equal ( bicepFilePath , templateFile . Path ) ;
297+ }
298+
299+ [ Fact ]
300+ public void GetBicepTemplateFile_WithTemplateString_WritesToDirectory ( )
301+ {
302+ using var tempDir = new TestTempDirectory ( ) ;
297303
298- var resourceBicepPath = Path . Combine ( outputDir , "myresource" , "myresource.bicep" ) ;
299- Assert . True ( File . Exists ( resourceBicepPath ) , "myresource/myresource.bicep should be generated" ) ;
304+ var bicepContent = "param location string = resourceGroup().location" ;
305+
306+ // Create the AzureBicepResource with a template string (not a file)
307+ var resource = new AzureBicepResource ( "test-resource" , templateString : bicepContent ) ;
308+
309+ // Create a directory to pass to GetBicepTemplateFile
310+ var outputDir = Path . Combine ( tempDir . Path , "output" ) ;
311+ Directory . CreateDirectory ( outputDir ) ;
300312
301- // Verify the content of the copied file matches the original
302- var copiedContent = await File . ReadAllTextAsync ( resourceBicepPath ) ;
303- Assert . Equal ( bicepContent , copiedContent ) ;
313+ // Get the bicep template file with a directory parameter
314+ using var templateFile = resource . GetBicepTemplateFile ( outputDir ) ;
304315
305- // Verify the main.bicep references the resource
306- var mainBicepContent = await File . ReadAllTextAsync ( mainBicepPath ) ;
307- Assert . Contains ( "module myresource 'myresource/myresource.bicep'" , mainBicepContent ) ;
316+ // The path should be in the output directory
317+ Assert . StartsWith ( outputDir , templateFile . Path ) ;
318+ Assert . True ( File . Exists ( templateFile . Path ) , $ "The template file should exist at { templateFile . Path } ") ;
319+ Assert . Equal ( bicepContent , File . ReadAllText ( templateFile . Path ) ) ;
308320 }
309321}
0 commit comments