Skip to content

Commit c65fce1

Browse files
committed
add missing tests for supporting PUT in complex types
1 parent 92588da commit c65fce1

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/ComplexPropertyPathItemHandlerTests.cs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,35 @@ public void SetsDefaultOperations()
4141
Assert.True(pathItem.Operations.ContainsKey(OperationType.Delete));
4242
}
4343

44-
[Fact]
45-
public void SetsPutUpdateOperationWithUpdateMethodUpdateRestrictions()
44+
[Fact]
45+
public void SetsPutUpdateOperationWithUpdateMethodUpdateRestrictions()
4646
{
47-
string annotation = $@"
47+
string annotation = $@"
4848
<Annotation Term=""Org.OData.Capabilities.V1.UpdateRestrictions"">
4949
<Record>
5050
<PropertyValue Property=""UpdateMethod"">
5151
<EnumMember>Org.OData.Capabilities.V1.HttpMethod/PUT</EnumMember>
5252
</PropertyValue>
5353
</Record>
5454
</Annotation>";
55-
string target = $@"""NS.Default/Customers/BillingAddress""";
55+
string target = $@"""NS.Customer/BillingAddress""";
5656

57-
var model = EntitySetPathItemHandlerTests.GetEdmModel(annotation: annotation);
58-
var context = new ODataContext(model);
59-
var entitySet = model.EntityContainer.FindEntitySet("Customers");
60-
Assert.NotNull(entitySet); // guard
61-
var entityType = entitySet.EntityType();
62-
var property = entityType.FindProperty("BillingAddress");
63-
Assert.NotNull(property); // guard
64-
var path = new ODataPath(new ODataNavigationSourceSegment(entitySet), new ODataKeySegment(entityType), new ODataComplexPropertySegment(property as IEdmStructuralProperty));
65-
Assert.Equal(ODataPathKind.ComplexProperty, path.Kind); // guard
66-
var pathItem = _pathItemHandler.CreatePathItem(context, path);
67-
Assert.NotNull(pathItem);
68-
Assert.Equal(3, pathItem.Operations.Count);
69-
Assert.True(pathItem.Operations.ContainsKey(OperationType.Get));
70-
Assert.True(pathItem.Operations.ContainsKey(OperationType.Patch));
71-
Assert.True(pathItem.Operations.ContainsKey(OperationType.Delete));
72-
}
57+
var model = EntitySetPathItemHandlerTests.GetEdmModel(annotation: annotation, target: target);
58+
var context = new ODataContext(model);
59+
var entitySet = model.EntityContainer.FindEntitySet("Customers");
60+
Assert.NotNull(entitySet); // guard
61+
var entityType = entitySet.EntityType();
62+
var property = entityType.FindProperty("BillingAddress");
63+
Assert.NotNull(property); // guard
64+
var path = new ODataPath(new ODataNavigationSourceSegment(entitySet), new ODataKeySegment(entityType), new ODataComplexPropertySegment(property as IEdmStructuralProperty));
65+
Assert.Equal(ODataPathKind.ComplexProperty, path.Kind); // guard
66+
var pathItem = _pathItemHandler.CreatePathItem(context, path);
67+
Assert.NotNull(pathItem);
68+
Assert.Equal(3, pathItem.Operations.Count);
69+
Assert.True(pathItem.Operations.ContainsKey(OperationType.Get));
70+
Assert.True(pathItem.Operations.ContainsKey(OperationType.Put));
71+
Assert.True(pathItem.Operations.ContainsKey(OperationType.Delete));
72+
}
7373

7474
[Fact]
7575
public void DoesntSetDeleteOnNonNullableProperties()

test/Microsoft.OpenAPI.OData.Reader.Tests/PathItem/EntitySetPathItemHandlerTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ private void VerifyPathItemOperations(string annotation, OperationType[] expecte
153153
Assert.Equal(expected, pathItem.Operations.Select(e => e.Key));
154154
}
155155

156-
public static IEdmModel GetEdmModel(string annotation)
156+
public static IEdmModel GetEdmModel(string annotation, string target = "\"NS.Default/Customers\"")
157157
{
158158
const string template = @"<edmx:Edmx Version=""4.0"" xmlns:edmx=""http://docs.oasis-open.org/odata/ns/edmx"">
159159
<edmx:DataServices>
@@ -173,13 +173,13 @@ public static IEdmModel GetEdmModel(string annotation)
173173
<EntityContainer Name =""Default"">
174174
<EntitySet Name=""Customers"" EntityType=""NS.Customer"" />
175175
</EntityContainer>
176-
<Annotations Target=""NS.Default/Customers"">
177-
{0}
176+
<Annotations Target={0}>
177+
{1}
178178
</Annotations>
179179
</Schema>
180180
</edmx:DataServices>
181181
</edmx:Edmx>";
182-
string modelText = string.Format(template, annotation);
182+
string modelText = string.Format(template, target, annotation);
183183

184184
IEdmModel model;
185185
IEnumerable<EdmError> errors;

0 commit comments

Comments
 (0)