Exemplo n.º 1
0
        public void RequestBodyJsonBuilder_ArrayTypeInput_ProducesJValue(string itemSchemaFormat, string itemSchemaType)
        {
            Schema schema = CreateSchemaInputForArrayType(name: "test", itemFormat: itemSchemaFormat, itemType: itemSchemaType);
            RequestBodyJsonBuilder converter = new RequestBodyJsonBuilder(new DefaultValueFactory());
            JToken result = converter.GetJsonResult(schema, swaggerDocDefinitions: new Dictionary <string, Schema>());

            Assert.IsType <JArray>(result);
        }
Exemplo n.º 2
0
        public void RequestBodyJsonBuilder_ComplexTypeWithNestedTypeInput_ProducesJObjectForNestedChild()
        {
            var inputResult = CreateSchemaInputForComplexTypeWithNestedTypes();
            RequestBodyJsonBuilder converter = new RequestBodyJsonBuilder(new DefaultValueFactory());
            JObject result = (JObject)converter.GetJsonResult(inputResult.schema, swaggerDocDefinitions: inputResult.references);

            Assert.IsType <JObject>(result["nestedChild"]);
        }
Exemplo n.º 3
0
        public void RequestBodyJsonBuilder_ComplexTypeInput_ProducesJObject()
        {
            Schema schema = CreateSchemaInputForComplexType(name: "test");
            RequestBodyJsonBuilder converter = new RequestBodyJsonBuilder(new DefaultValueFactory());
            JToken result = converter.GetJsonResult(schema, swaggerDocDefinitions: new Dictionary <string, Schema>());

            Assert.IsType <JObject>(result);
        }
Exemplo n.º 4
0
        public void RequestBodyJsonBuilder_PrimitiveTypeInput_ProducesExpectedJObjectType(string schemaFormat, string schemaType, JTokenType expectedTokenType)
        {
            Schema schema = CreateSchemaInputForPrimitiveType(name: "test", format: schemaFormat, type: schemaType);
            RequestBodyJsonBuilder converter = new RequestBodyJsonBuilder(new DefaultValueFactory());
            JToken result    = converter.GetJsonResult(schema, swaggerDocDefinitions: new Dictionary <string, Schema>());
            JValue jsonValue = (JValue)result;

            Assert.Equal(expectedTokenType, jsonValue.Type);
        }
Exemplo n.º 5
0
        public void RequestBodyJsonBuilder_ArrayTypeInput_ProducesExpectedJObjectType(string itemSchemaFormat, string itemSchemaType, JTokenType expectedItemTokenType)
        {
            Schema schema = CreateSchemaInputForArrayType(name: "test", itemFormat: itemSchemaFormat, itemType: itemSchemaType);
            RequestBodyJsonBuilder converter = new RequestBodyJsonBuilder(new DefaultValueFactory());
            JToken result = converter.GetJsonResult(schema, swaggerDocDefinitions: new Dictionary <string, Schema>());

            JArray array = (JArray)result;

            Assert.All(array, i => Assert.Equal(expectedItemTokenType, (i as JValue).Type));
        }
Exemplo n.º 6
0
        public void RequestBodyJsonBuilder_ComplexTypeInput_ProducesJObjectWithCorrectPropertyTokenTypes()
        {
            Schema schema = CreateSchemaInputForComplexType(name: "test");
            RequestBodyJsonBuilder converter = new RequestBodyJsonBuilder(new DefaultValueFactory());
            JObject result      = (JObject)converter.GetJsonResult(schema, swaggerDocDefinitions: new Dictionary <string, Schema>());
            JValue  idElement   = result["id"] as JValue;
            JValue  nameElement = result["name"] as JValue;

            Assert.Equal(JTokenType.Integer, idElement.Type);
            Assert.Equal(JTokenType.String, nameElement.Type);
        }
Exemplo n.º 7
0
        public void RequestBodyJsonBuilder_ComplexTypeInput_ProducesJObjectWithCorrectProperties()
        {
            Schema schema = CreateSchemaInputForComplexType(name: "test");
            RequestBodyJsonBuilder converter = new RequestBodyJsonBuilder(new DefaultValueFactory());
            JObject result = (JObject)converter.GetJsonResult(schema, swaggerDocDefinitions: new Dictionary <string, Schema>());

            Assert.NotNull(result["id"]);
            Assert.IsType <JValue>(result["id"]);
            Assert.NotNull(result["name"]);
            Assert.IsType <JValue>(result["name"]);
        }
Exemplo n.º 8
0
        public void RequestBodyJsonBuilder_ComplexTypeWithNestedTypeInput_ProducesJObjectForNestedChild_WithCorrectPropertyTypes()
        {
            var inputResult = CreateSchemaInputForComplexTypeWithNestedTypes();
            RequestBodyJsonBuilder converter = new RequestBodyJsonBuilder(new DefaultValueFactory());
            JObject result = (JObject)converter.GetJsonResult(inputResult.schema, swaggerDocDefinitions: inputResult.references);

            JObject nestedChildObject = result["nestedChild"] as JObject;
            object  uuidValue         = (nestedChildObject["uuid"] as JValue).Value;
            object  codeValue         = (nestedChildObject["code"] as JValue).Value;

            Assert.IsType <string>(uuidValue);
            Assert.IsType <string>(codeValue);
        }