public void CreateSingletonPatchOperationReturnsCorrectOperation(bool enableOperationId, bool useHTTPStatusCodeClass2XX) { // Arrange string annotation = @" <Annotation Term=""Org.OData.Capabilities.V1.UpdateRestrictions""> <Record> <PropertyValue Property=""Description"" String=""Update the signed-in user."" /> <PropertyValue Property=""LongDescription"" String=""Update the signed-in user."" /> </Record> </Annotation>"; IEdmModel model = SingletonGetOperationHandlerTests.GetEdmModel(annotation); IEdmSingleton singleton = model.EntityContainer.FindSingleton("Me"); OpenApiConvertSettings settings = new OpenApiConvertSettings { EnableOperationId = enableOperationId, UseSuccessStatusCodeRange = useHTTPStatusCodeClass2XX }; ODataContext context = new ODataContext(model, settings); ODataPath path = new ODataPath(new ODataNavigationSourceSegment(singleton)); // Act var patch = _operationHandler.CreateOperation(context, path); // Assert Assert.NotNull(patch); Assert.Equal("Update the signed-in user.", patch.Summary); Assert.Equal("Update the signed-in user.", patch.Description); Assert.NotNull(patch.Tags); var tag = Assert.Single(patch.Tags); Assert.Equal("Me.Customer", tag.Name); Assert.Empty(patch.Parameters); Assert.NotNull(patch.RequestBody); Assert.NotNull(patch.Responses); Assert.Equal(2, patch.Responses.Count); var statusCode = useHTTPStatusCodeClass2XX ? "2XX" : "204"; Assert.Equal(new[] { statusCode, "default" }, patch.Responses.Select(r => r.Key)); if (useHTTPStatusCodeClass2XX) { Assert.Single(patch.Responses[statusCode].Content); } else { Assert.Empty(patch.Responses[statusCode].Content); } if (enableOperationId) { Assert.Equal("Me.Customer.UpdateCustomer", patch.OperationId); } else { Assert.Null(patch.OperationId); } }
public void CreateSingletonPatchOperationReturnsCorrectOperation(bool enableOperationId) { // Arrange IEdmModel model = SingletonGetOperationHandlerTests.GetEdmModel(""); IEdmSingleton singleton = model.EntityContainer.FindSingleton("Me"); OpenApiConvertSettings settings = new OpenApiConvertSettings { EnableOperationId = enableOperationId }; ODataContext context = new ODataContext(model, settings); ODataPath path = new ODataPath(new ODataNavigationSourceSegment(singleton)); // Act var patch = _operationHandler.CreateOperation(context, path); // Assert Assert.NotNull(patch); Assert.Equal("Update Me", patch.Summary); Assert.NotNull(patch.Tags); var tag = Assert.Single(patch.Tags); Assert.Equal("Me.Customer", tag.Name); Assert.Empty(patch.Parameters); Assert.NotNull(patch.RequestBody); Assert.NotNull(patch.Responses); Assert.Equal(2, patch.Responses.Count); Assert.Equal(new[] { "204", "default" }, patch.Responses.Select(r => r.Key)); if (enableOperationId) { Assert.Equal("Me.Customer.UpdateCustomer", patch.OperationId); } else { Assert.Null(patch.OperationId); } }