@@ -279,6 +279,95 @@ public void CreateKeyParametersForCompositeKeyWorks(bool prefix)
279279 Assert . Equal ( expected . ChangeLineBreaks ( ) , json ) ;
280280 }
281281
282+ [ Fact ]
283+ public void CreateKeyParametersForAlternateKeyWithSinglePropertyWorks ( )
284+ {
285+ // Arrange
286+ EdmModel model = new EdmModel ( ) ;
287+ EdmEntityType customer = new EdmEntityType ( "NS" , "Customer" ) ;
288+ customer . AddKeys ( customer . AddStructuralProperty ( "Id" , EdmPrimitiveTypeKind . String ) ) ;
289+
290+ IEdmProperty alternateId = customer . AddStructuralProperty ( "AlternateId" , EdmPrimitiveTypeKind . String ) ;
291+ model . AddAlternateKeyAnnotation ( customer , new Dictionary < string , IEdmProperty > { { "AltId" , alternateId } } ) ;
292+
293+ model . AddElement ( customer ) ;
294+ ODataContext context = new ( model ) ;
295+ ODataKeySegment keySegment = new ( customer ) ;
296+
297+ // Act
298+ var parameters = context . CreateKeyParameters ( keySegment ) ;
299+ var altParameter = parameters . Last ( ) ;
300+
301+ // Assert
302+ Assert . NotNull ( parameters ) ;
303+ Assert . Equal ( 2 , parameters . Count ) ;
304+ string json = altParameter . SerializeAsJson ( OpenApiSpecVersion . OpenApi3_0 ) ;
305+ Assert . Equal ( @"{
306+ ""name"": ""AltId"",
307+ ""in"": ""path"",
308+ ""description"": ""Alternate key: AlternateId of Customer"",
309+ ""style"": ""simple"",
310+ ""schema"": {
311+ ""type"": ""string"",
312+ ""nullable"": true
313+ }
314+ }" . ChangeLineBreaks ( ) , json ) ;
315+ }
316+
317+ [ Fact ]
318+ public void CreateKeyParametersForAlternateKeyWithMultiplePropertiesWorks ( )
319+ {
320+ // Arrange
321+ EdmModel model = new EdmModel ( ) ;
322+ EdmEntityType customer = new EdmEntityType ( "NS" , "Customer" ) ;
323+ customer . AddKeys ( customer . AddStructuralProperty ( "Id" , EdmPrimitiveTypeKind . String ) ) ;
324+
325+ IEdmProperty alternateId1 = customer . AddStructuralProperty ( "AlternateId1" , EdmPrimitiveTypeKind . String ) ;
326+ IEdmProperty alternateId2 = customer . AddStructuralProperty ( "AlternateId2" , EdmPrimitiveTypeKind . String ) ;
327+ model . AddAlternateKeyAnnotation ( customer ,
328+ new Dictionary < string , IEdmProperty >
329+ {
330+ { "AltId1" , alternateId1 } ,
331+ { "AltId2" , alternateId2 }
332+ } ) ;
333+
334+ model . AddElement ( customer ) ;
335+ ODataContext context = new ( model ) ;
336+ ODataKeySegment keySegment = new ( customer ) ;
337+
338+ // Act
339+ var parameters = context . CreateKeyParameters ( keySegment ) ;
340+ var altParameter1 = parameters . Skip ( 1 ) . First ( ) ;
341+ var altParameter2 = parameters . Last ( ) ;
342+
343+ // Assert
344+ Assert . NotNull ( parameters ) ;
345+ Assert . Equal ( 3 , parameters . Count ) ;
346+ string json1 = altParameter1 . SerializeAsJson ( OpenApiSpecVersion . OpenApi3_0 ) ;
347+ Assert . Equal ( @"{
348+ ""name"": ""AltId1"",
349+ ""in"": ""path"",
350+ ""description"": ""Composite alternate key: AlternateId1 of Customer"",
351+ ""style"": ""simple"",
352+ ""schema"": {
353+ ""type"": ""string"",
354+ ""nullable"": true
355+ }
356+ }" . ChangeLineBreaks ( ) , json1 ) ;
357+
358+ string json2 = altParameter2 . SerializeAsJson ( OpenApiSpecVersion . OpenApi3_0 ) ;
359+ Assert . Equal ( @"{
360+ ""name"": ""AltId2"",
361+ ""in"": ""path"",
362+ ""description"": ""Composite alternate key: AlternateId2 of Customer"",
363+ ""style"": ""simple"",
364+ ""schema"": {
365+ ""type"": ""string"",
366+ ""nullable"": true
367+ }
368+ }" . ChangeLineBreaks ( ) , json2 ) ;
369+ }
370+
282371 [ Fact ]
283372 public void CreateOrderByAndSelectAndExpandParametersWorks ( )
284373 {
0 commit comments