@@ -33,11 +33,11 @@ public void WithReference_WhenAADDisabled_UsesPasswordSecret()
3333
3434 // First check if there are any resources with the annotation
3535 Assert . NotEmpty ( resourcesWithAnnotation ) ;
36-
36+
3737 // Now check for a specific resource
38- var daprStateStore = Assert . Single ( appModel . Resources . OfType < IDaprComponentResource > ( ) ,
38+ var daprStateStore = Assert . Single ( appModel . Resources . OfType < IDaprComponentResource > ( ) ,
3939 r => r . Name == "statestore" ) ;
40-
40+
4141 // Check there's an annotation on it
4242 Assert . Contains ( daprStateStore . Annotations , a => a is AzureDaprComponentPublishingAnnotation ) ;
4343
@@ -96,15 +96,15 @@ param redisstate_kv_outputs_name string
9696 // Get the actual bicep template and rearrange the ordering if needed
9797 var actualLines = redisBicep . Split ( Environment . NewLine ) ;
9898 var expectedLines = expectedRedisBicep . Split ( Environment . NewLine ) ;
99-
99+
100100 // Compare the Redis resource configuration which is what we actually care about
101- var redisResourceSection = string . Join ( Environment . NewLine ,
102- actualLines . Where ( line => line . Contains ( "resource redisState" ) ||
103- line . Contains ( "name:" ) ||
104- line . Contains ( "sku:" ) ||
105- line . Contains ( "family:" ) ||
101+ var redisResourceSection = string . Join ( Environment . NewLine ,
102+ actualLines . Where ( line => line . Contains ( "resource redisState" ) ||
103+ line . Contains ( "name:" ) ||
104+ line . Contains ( "sku:" ) ||
105+ line . Contains ( "family:" ) ||
106106 line . Contains ( "capacity:" ) ) ) ;
107-
107+
108108 Assert . Contains ( "'Microsoft.Cache/redis@2024-11-01'" , redisResourceSection ) ;
109109
110110 // Verify that resources with Dapr publishing annotations exist
@@ -133,11 +133,11 @@ public void WithReference_WhenAADEnabled_SkipsPasswordSecret()
133133
134134 // First check if there are any resources with the annotation
135135 Assert . NotEmpty ( resourcesWithAnnotation ) ;
136-
136+
137137 // Now check for a specific resource
138- var daprStateStore = Assert . Single ( appModel . Resources . OfType < IDaprComponentResource > ( ) ,
138+ var daprStateStore = Assert . Single ( appModel . Resources . OfType < IDaprComponentResource > ( ) ,
139139 r => r . Name == "statestore" ) ;
140-
140+
141141 // Check there's an annotation on it
142142 Assert . Contains ( daprStateStore . Annotations , a => a is AzureDaprComponentPublishingAnnotation ) ;
143143
@@ -174,6 +174,8 @@ public void WithReference_WhenAADEnabled_SkipsPasswordSecret()
174174
175175 output name string = redisState.name
176176
177+ output hostName string = redisState.properties.hostName
178+
177179 output daprConnectionString string = '${redisState.properties.hostName}:${redisState.properties.sslPort}'
178180 """ ;
179181
@@ -210,11 +212,11 @@ public void WithReference_WhenTLSDisabled_UsesNonSslPort()
210212
211213 // First check if there are any resources with the annotation
212214 Assert . NotEmpty ( resourcesWithAnnotation ) ;
213-
215+
214216 // Now check for a specific resource
215- var daprStateStore = Assert . Single ( appModel . Resources . OfType < IDaprComponentResource > ( ) ,
217+ var daprStateStore = Assert . Single ( appModel . Resources . OfType < IDaprComponentResource > ( ) ,
216218 r => r . Name == "statestore" ) ;
217-
219+
218220 // Check there's an annotation on it
219221 Assert . Contains ( daprStateStore . Annotations , a => a is AzureDaprComponentPublishingAnnotation ) ;
220222
@@ -252,6 +254,8 @@ public void WithReference_WhenTLSDisabled_UsesNonSslPort()
252254
253255 output name string = redisState.name
254256
257+ output hostName string = redisState.properties.hostName
258+
255259 output daprConnectionString string = '${redisState.properties.hostName}:${redisState.properties.port}'
256260 """ ;
257261
@@ -271,32 +275,34 @@ public void WithReference_WhenNonStateType_ThrowsException()
271275 using var builder = TestDistributedApplicationBuilder . Create ( DistributedApplicationOperation . Publish ) ;
272276
273277 var redisState = builder . AddAzureRedis ( "redisState" ) . RunAsContainer ( ) ;
274-
278+
275279 // The Redis connection should only be used with state store components
276- var unknownComponent = builder . AddDaprComponent ( "unknown" , "component" ) ;
277-
280+ var unknownComponent = builder . AddDaprComponent ( "unknown" , "component" ) ;
281+
278282 // Create an app with a sidecar that references the unknown component
279283 var appBuilder = builder . AddContainer ( "myapp" , "image" )
280- . WithDaprSidecar ( sidecar => {
284+ . WithDaprSidecar ( sidecar =>
285+ {
281286 // Reference the unknown component first
282287 sidecar . WithReference ( unknownComponent ) ;
283288 } ) ;
284-
289+
285290 // Attempting to create a non-state store reference to Redis should throw
286- var exception = Assert . Throws < InvalidOperationException > ( ( ) => {
291+ var exception = Assert . Throws < InvalidOperationException > ( ( ) =>
292+ {
287293 unknownComponent . WithReference ( redisState ) ;
288294 } ) ;
289-
295+
290296 // Verify the exception message contains information about the unsupported component type
291297 Assert . Contains ( "Unsupported Dapr component" , exception . Message , StringComparison . OrdinalIgnoreCase ) ;
292-
298+
293299 // Demonstrate the correct way to reference Redis
294300 var stateStore = builder . AddDaprStateStore ( "statestore" ) ;
295301 stateStore . WithReference ( redisState ) ; // This should work correctly
296-
302+
297303 using var app = builder . Build ( ) ;
298304 }
299-
305+
300306 [ Fact ]
301307 public void PreferredPattern_ReferencingRedisStateComponent ( )
302308 {
@@ -306,31 +312,32 @@ public void PreferredPattern_ReferencingRedisStateComponent()
306312 // Add the Redis state and Dapr state store
307313 var redisState = builder . AddAzureRedis ( "redisState" ) . RunAsContainer ( ) ;
308314 var daprState = builder . AddDaprStateStore ( "statestore" ) ;
309-
315+
310316 // Add an app with a sidecar
311317 builder . AddContainer ( "myapp" , "image" )
312- . WithDaprSidecar ( sidecar => {
318+ . WithDaprSidecar ( sidecar =>
319+ {
313320 // Reference both components through the sidecar
314321 sidecar . WithReference ( daprState ) ;
315322 // We can't directly reference Redis from the sidecar due to interface incompatibilities
316323 // This line would fail with a compile error: sidecar.WithReference(redisState);
317-
324+
318325 // We need to first create a Dapr component that references Redis
319326 var anotherState = builder . AddDaprStateStore ( "anotherstate" ) ;
320327 anotherState . WithReference ( redisState ) ;
321328 sidecar . WithReference ( anotherState ) ;
322329 } ) ;
323-
330+
324331 using var app = builder . Build ( ) ;
325-
332+
326333 var appModel = app . Services . GetRequiredService < DistributedApplicationModel > ( ) ;
327334 var sidecarResource = Assert . Single ( appModel . Resources . OfType < IDaprSidecarResource > ( ) ) ;
328-
335+
329336 // Check for component reference annotations
330337 var referenceAnnotations = sidecarResource . Annotations
331338 . OfType < DaprComponentReferenceAnnotation > ( )
332339 . ToList ( ) ;
333-
340+
334341 Assert . Equal ( 2 , referenceAnnotations . Count ) ;
335342 }
336343}
0 commit comments