@@ -263,4 +263,101 @@ public void CreatesComplexPropertyPathsBasedOnTargetPathAnnotations(string reada
263263 Assert . True ( pathItem . Operations . ContainsKey ( HttpMethod . Get ) ) ;
264264 }
265265 }
266+
267+ [ Theory ]
268+ [ InlineData ( false , 2 ) ]
269+ [ InlineData ( true , 2 ) ]
270+ public void CreatesComplexPropertyPathItemUsesHttpPutForUpdateWhenSettingIsEnabled ( bool useHttpPutForUpdate , int operationCount )
271+ {
272+ // Arrange
273+ var annotation = @"
274+ <Annotation Term=""Org.OData.Capabilities.V1.UpdateRestrictions"">
275+ <Record>
276+ <PropertyValue Property=""Updatable"" Bool=""true"" />
277+ </Record>
278+ </Annotation>
279+ <Annotation Term=""Org.OData.Capabilities.V1.ReadRestrictions"">
280+ <Record>
281+ <PropertyValue Property=""Readable"" Bool=""true"" />
282+ </Record>
283+ </Annotation>" ;
284+ var target = @"""NS.Customer/BillingAddress""" ;
285+ var model = EntitySetPathItemHandlerTests . GetEdmModel ( annotation : annotation , target : target ) ;
286+ var convertSettings = new OpenApiConvertSettings
287+ {
288+ UseHttpPutForUpdate = useHttpPutForUpdate
289+ } ;
290+ var context = new ODataContext ( model , convertSettings ) ;
291+ var entitySet = model . EntityContainer . FindEntitySet ( "Customers" ) ;
292+ Assert . NotNull ( entitySet ) ; // guard
293+ var entityType = entitySet . EntityType ;
294+ var property = entityType . FindProperty ( "BillingAddress" ) ;
295+ Assert . NotNull ( property ) ; // guard
296+ var path = new ODataPath ( new ODataNavigationSourceSegment ( entitySet ) , new ODataKeySegment ( entityType ) , new ODataComplexPropertySegment ( property as IEdmStructuralProperty ) ) ;
297+ Assert . Equal ( ODataPathKind . ComplexProperty , path . Kind ) ; // guard
298+
299+ // Act
300+ var pathItem = _pathItemHandler . CreatePathItem ( context , path ) ;
301+
302+ // Assert
303+ Assert . NotNull ( pathItem ) ;
304+ Assert . Equal ( operationCount , pathItem . Operations ? . Count ?? 0 ) ;
305+
306+ Assert . True ( pathItem . Operations . ContainsKey ( HttpMethod . Get ) ) ;
307+ if ( useHttpPutForUpdate )
308+ {
309+ Assert . True ( pathItem . Operations . ContainsKey ( HttpMethod . Put ) ) ;
310+ Assert . False ( pathItem . Operations . ContainsKey ( HttpMethod . Patch ) ) ;
311+ }
312+ else
313+ {
314+ Assert . True ( pathItem . Operations . ContainsKey ( HttpMethod . Patch ) ) ;
315+ Assert . False ( pathItem . Operations . ContainsKey ( HttpMethod . Put ) ) ;
316+ }
317+ }
318+
319+ [ Fact ]
320+ public void CreateComplexPropertyPathItemPrefersUpdateMethodAnnotationOverUseHttpPutForUpdateSetting ( )
321+ {
322+ // Arrange - annotation specifies PUT explicitly, setting is disabled (default PATCH)
323+ var annotation = @"
324+ <Annotation Term=""Org.OData.Capabilities.V1.UpdateRestrictions"">
325+ <Record>
326+ <PropertyValue Property=""UpdateMethod"">
327+ <EnumMember>Org.OData.Capabilities.V1.HttpMethod/PUT</EnumMember>
328+ </PropertyValue>
329+ <PropertyValue Property=""Updatable"" Bool=""true"" />
330+ </Record>
331+ </Annotation>
332+ <Annotation Term=""Org.OData.Capabilities.V1.ReadRestrictions"">
333+ <Record>
334+ <PropertyValue Property=""Readable"" Bool=""true"" />
335+ </Record>
336+ </Annotation>" ;
337+ var target = @"""NS.Customer/BillingAddress""" ;
338+ var model = EntitySetPathItemHandlerTests . GetEdmModel ( annotation : annotation , target : target ) ;
339+ var convertSettings = new OpenApiConvertSettings
340+ {
341+ UseHttpPutForUpdate = false // Setting says use PATCH (default)
342+ } ;
343+ var context = new ODataContext ( model , convertSettings ) ;
344+ var entitySet = model . EntityContainer . FindEntitySet ( "Customers" ) ;
345+ Assert . NotNull ( entitySet ) ; // guard
346+ var entityType = entitySet . EntityType ;
347+ var property = entityType . FindProperty ( "BillingAddress" ) ;
348+ Assert . NotNull ( property ) ; // guard
349+ var path = new ODataPath ( new ODataNavigationSourceSegment ( entitySet ) , new ODataKeySegment ( entityType ) , new ODataComplexPropertySegment ( property as IEdmStructuralProperty ) ) ;
350+ Assert . Equal ( ODataPathKind . ComplexProperty , path . Kind ) ; // guard
351+
352+ // Act
353+ var pathItem = _pathItemHandler . CreatePathItem ( context , path ) ;
354+
355+ // Assert
356+ Assert . NotNull ( pathItem ) ;
357+ Assert . Equal ( 2 , pathItem . Operations ? . Count ?? 0 ) ;
358+ Assert . True ( pathItem . Operations . ContainsKey ( HttpMethod . Get ) ) ;
359+ // Should use PUT from annotation, not PATCH from setting
360+ Assert . True ( pathItem . Operations . ContainsKey ( HttpMethod . Put ) ) ;
361+ Assert . False ( pathItem . Operations . ContainsKey ( HttpMethod . Patch ) ) ;
362+ }
266363}
0 commit comments