public void SerializeAdvancedParameterAsV3JsonWorks()
        {
            // Arrange
            var expected = @"{
  ""name"": ""name1"",
  ""in"": ""path"",
  ""description"": ""description1"",
  ""required"": true,
  ""style"": ""simple"",
  ""explode"": true,
  ""schema"": {
    ""title"": ""title2"",
    ""description"": ""description2""
  },
  ""examples"": [
    {
      ""summary"": ""summary3"",
      ""description"": ""description3""
    }
  ]
}";

            // Act
            var actual = AdvancedPathParameterWithSchema.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);

            // Assert
            actual   = actual.MakeLineBreaksEnvironmentNeutral();
            expected = expected.MakeLineBreaksEnvironmentNeutral();
            actual.Should().Be(expected);
        }
        public void SerializeBasicParameterAsV3JsonWorks()
        {
            // Arrange
            var expected = @"{
  ""name"": ""name1"",
  ""in"": ""path""
}";

            // Act
            var actual = BasicParameter.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);

            // Assert
            actual   = actual.MakeLineBreaksEnvironmentNeutral();
            expected = expected.MakeLineBreaksEnvironmentNeutral();
            actual.Should().Be(expected);
        }
Esempio n. 3
0
        public void CreateParametersWorks()
        {
            // Arrange
            IEdmModel     model      = EdmModelHelper.GraphBetaModel;
            ODataContext  context    = new(model);
            IEdmSingleton deviceMgmt = model.EntityContainer.FindSingleton("deviceManagement");

            Assert.NotNull(deviceMgmt);

            IEdmFunction function1 = model.SchemaElements.OfType <IEdmFunction>().First(f => f.Name == "getRoleScopeTagsByIds");

            Assert.NotNull(function1);

            IEdmFunction function2 = model.SchemaElements.OfType <IEdmFunction>().First(f => f.Name == "getRoleScopeTagsByResource");

            Assert.NotNull(function2);

            IEdmFunction function3 = model.SchemaElements.OfType <IEdmFunction>().First(f => f.Name == "roleScheduleInstances");

            Assert.NotNull(function3);

            // Act
            IList <OpenApiParameter> parameters1 = context.CreateParameters(function1);
            IList <OpenApiParameter> parameters2 = context.CreateParameters(function2);
            IList <OpenApiParameter> parameters3 = context.CreateParameters(function3);

            // Assert
            Assert.NotNull(parameters1);
            OpenApiParameter parameter1 = Assert.Single(parameters1);

            Assert.NotNull(parameters2);
            OpenApiParameter parameter2 = Assert.Single(parameters2);

            Assert.NotNull(parameters3);
            Assert.Equal(4, parameters3.Count);
            OpenApiParameter parameter3 = parameters3.First();

            string json1            = parameter1.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
            string expectedPayload1 = $@"{{
  ""name"": ""ids"",
  ""in"": ""path"",
  ""description"": ""The URL-encoded JSON object"",
  ""required"": true,
  ""content"": {{
    ""application/json"": {{
      ""schema"": {{
        ""type"": ""array"",
        ""items"": {{
          ""type"": ""string""
        }}
      }}
    }}
  }}
}}";

            string json2            = parameter2.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
            string expectedPayload2 = $@"{{
  ""name"": ""resource"",
  ""in"": ""path"",
  ""required"": true,
  ""schema"": {{
    ""type"": ""string"",
    ""nullable"": true
  }}
}}";

            string json3            = parameter3.SerializeAsJson(OpenApiSpecVersion.OpenApi3_0);
            string expectedPayload3 = $@"{{
  ""name"": ""directoryScopeId"",
  ""in"": ""query"",
  ""schema"": {{
    ""type"": ""string"",
    ""nullable"": true
  }}
}}";

            Assert.Equal(expectedPayload1.ChangeLineBreaks(), json1);
            Assert.Equal(expectedPayload2.ChangeLineBreaks(), json2);
            Assert.Equal(expectedPayload3.ChangeLineBreaks(), json3);
        }