public void CreateRequestBodyForActionImportReturnCorrectRequestBody()
        {
            // Arrange
            ODataContext context = new ODataContext(_model);

            // Act
            var requestBody = context.CreateRequestBody(_actionImport);

            // Assert
            Assert.NotNull(requestBody);
            Assert.Equal("Action parameters", requestBody.Description);
            Assert.NotNull(requestBody.Content);
            var content = Assert.Single(requestBody.Content);

            Assert.Equal("application/json", content.Key);
            Assert.NotNull(content.Value);

            Assert.NotNull(content.Value.Schema);
            var schema = content.Value.Schema;

            Assert.Equal("object", schema.Type);
            Assert.NotNull(schema.Properties);
            var parameter = Assert.Single(schema.Properties);

            Assert.Equal("param", parameter.Key);
            Assert.Equal("string", parameter.Value.Type);
        }
        public void CanSerializeAsJsonFromTheCreatedRequestBody()
        {
            // Arrange
            ODataContext context = new ODataContext(_model);

            // Act
            var requestBody = context.CreateRequestBody(_actionImport);

            // Assert
            string json = requestBody.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);

            Assert.Equal(@"{
  ""description"": ""Action parameters"",
  ""content"": {
    ""application/json"": {
      ""schema"": {
        ""type"": ""object"",
        ""properties"": {
          ""param"": {
            ""type"": ""string"",
            ""nullable"": true
          }
        }
      }
    }
  },
  ""required"": true
}".ChangeLineBreaks(), json);
        }
        /// <summary>
        /// Create a <see cref="OpenApiRequestBody"/> for a <see cref="IEdmActionImport"/>.
        /// </summary>
        /// <param name="context">The OData context.</param>
        /// <param name="actionImport">The Edm action import.</param>
        /// <returns>The created <see cref="OpenApiRequestBody"/> or null.</returns>
        public static OpenApiRequestBody CreateRequestBody(this ODataContext context, IEdmActionImport actionImport)
        {
            Utils.CheckArgumentNull(context, nameof(context));
            Utils.CheckArgumentNull(actionImport, nameof(actionImport));

            return(context.CreateRequestBody(actionImport.Action));
        }
        public void CreateRequestBodyForActionImportThrowArgumentNullActionImport()
        {
            // Arrange
            ODataContext context = new ODataContext(EdmModelHelper.BasicEdmModel);

            // Act & Assert
            Assert.Throws <ArgumentNullException>("actionImport", () => context.CreateRequestBody(actionImport: null));
        }
        public void CreateRequestBodyForActionImportThrowArgumentNullContext()
        {
            // Arrange
            ODataContext context = null;

            // Act & Assert
            Assert.Throws <ArgumentNullException>("context", () => context.CreateRequestBody(actionImport: null));
        }