Esempio n. 1
0
        public void VerifyInputMappingsForResources()
        {
            var serviceClient = new ServiceClient();

            serviceClient.Name = "test service client";

            var flattenedPropertyType = new CompositeType();

            flattenedPropertyType.Name = "FooFlattened";
            flattenedPropertyType.Properties.Add(new Property
            {
                Name = "Sku",
                Type = new PrimaryType(KnownPrimaryType.String)
            });
            flattenedPropertyType.Properties.Add(new Property
            {
                Name = "ProvState",
                Type = new PrimaryType(KnownPrimaryType.String)
            });
            flattenedPropertyType.Properties.Add(new Property
            {
                Name = "Id",
                Type = new PrimaryType(KnownPrimaryType.Int)
            });

            var customObjectPropertyType = new CompositeType();

            customObjectPropertyType.Name = "FooProperty";
            customObjectPropertyType.Properties.Add(new Property
            {
                Name = "Sku",
                Type = new PrimaryType(KnownPrimaryType.String)
            });
            customObjectPropertyType.Properties.Add(new Property
            {
                Name = "ProvState",
                Type = new PrimaryType(KnownPrimaryType.String)
            });

            var customObjectType = new CompositeType();

            customObjectType.Name = "Foo";
            customObjectType.Properties.Add(new Property
            {
                Name = "Property",
                Type = customObjectPropertyType
            });
            customObjectType.Properties.Add(new Property
            {
                Name = "Id",
                Type = new PrimaryType(KnownPrimaryType.Int)
            });

            var method = new Method
            {
                Name       = "method1",
                Group      = "mGroup",
                ReturnType = new Response(flattenedPropertyType, null)
            };
            var inputParameter = new Parameter {
                Name = "prop", Type = flattenedPropertyType
            };

            serviceClient.Methods.Add(method);
            method.Parameters.Add(inputParameter);
            method.InputParameterTransformation.Add(new ParameterTransformation
            {
                OutputParameter = new Parameter {
                    Name = "body", Type = customObjectType, SerializedName = "body"
                }
            });
            method.InputParameterTransformation.Last().ParameterMappings.Add(new ParameterMapping
            {
                InputParameter          = inputParameter,
                InputParameterProperty  = "Id",
                OutputParameterProperty = "Id"
            });
            method.InputParameterTransformation.Last().ParameterMappings.Add(new ParameterMapping
            {
                InputParameter          = inputParameter,
                InputParameterProperty  = "Sku",
                OutputParameterProperty = "Property.Sku"
            });
            method.InputParameterTransformation.Last().ParameterMappings.Add(new ParameterMapping
            {
                InputParameter          = inputParameter,
                InputParameterProperty  = "ProvState",
                OutputParameterProperty = "Property.ProvState"
            });

            MethodTemplateModel templateModel = new MethodTemplateModel(method, serviceClient, SyncMethodsGenerationMode.All);
            var    output   = templateModel.BuildInputMappings();
            string expected =
                @"String paramA = null;
            if (body != null)
            {
                paramA = body.A;
            }
            String paramB = default(String);
            if (body != null)
            {
                paramB = body.B;
            }";

            MultilineAreEqual(expected, output.Trim());
        }
Esempio n. 2
0
        public void VerifyInputMappingsForFlattening()
        {
            var serviceClient = new ServiceClient();

            serviceClient.Name = "test service client";

            var customObjectType = new CompositeType();

            customObjectType.Name = "Foo";
            customObjectType.Properties.Add(new Property
            {
                Name = "A",
                Type = new PrimaryType(KnownPrimaryType.Boolean)
            });
            customObjectType.Properties.Add(new Property
            {
                Name = "B",
                Type = new PrimaryType(KnownPrimaryType.String)
            });
            var method = new Method
            {
                Name       = "method1",
                Group      = "mGroup",
                ReturnType = new Response(customObjectType, null)
            };
            var outputParameter = new Parameter {
                Name = "body", Type = customObjectType
            };

            serviceClient.Methods.Add(method);
            method.Parameters.Add(new Parameter {
                Name = "paramA", Type = new PrimaryType(KnownPrimaryType.Boolean), SerializedName = "paramA"
            });
            method.Parameters.Add(new Parameter {
                Name = "paramB", Type = new PrimaryType(KnownPrimaryType.String), SerializedName = "paramB"
            });
            method.InputParameterTransformation.Add(new ParameterTransformation
            {
                OutputParameter = outputParameter
            });
            method.InputParameterTransformation[0].ParameterMappings.Add(new ParameterMapping
            {
                InputParameter          = method.Parameters[0],
                OutputParameterProperty = "A"
            });
            method.InputParameterTransformation[0].ParameterMappings.Add(new ParameterMapping
            {
                InputParameter          = method.Parameters[1],
                OutputParameterProperty = "B"
            });

            MethodTemplateModel templateModel = new MethodTemplateModel(method, serviceClient, SyncMethodsGenerationMode.All);
            var output = templateModel.BuildInputMappings();

            System.Console.WriteLine(output);
            string expected =
                @"Foo body = default(Foo);
            if (paramA != null || paramB != null)
            {
                body = new Foo();
                body.A = paramA;
                body.B = paramB;
            }";

            MultilineAreEqual(expected, output.Trim());
        }
        public void VerifyInputMappingsForResources()
        {
            var serviceClient = new ServiceClient();
            serviceClient.Name = "test service client";

            var flattenedPropertyType = new CompositeType();
            flattenedPropertyType.Name = "FooFlattened";
            flattenedPropertyType.Properties.Add(new Property
            {
                Name = "Sku",
                Type = PrimaryType.String
            });
            flattenedPropertyType.Properties.Add(new Property
            {
                Name = "ProvState",
                Type = PrimaryType.String
            });
            flattenedPropertyType.Properties.Add(new Property
            {
                Name = "Id",
                Type = PrimaryType.Int
            });

            var customObjectPropertyType = new CompositeType();
            customObjectPropertyType.Name = "FooProperty";
            customObjectPropertyType.Properties.Add(new Property
            {
                Name = "Sku",
                Type = PrimaryType.String
            });
            customObjectPropertyType.Properties.Add(new Property
            {
                Name = "ProvState",
                Type = PrimaryType.String
            });

            var customObjectType = new CompositeType();
            customObjectType.Name = "Foo";
            customObjectType.Properties.Add(new Property
            {
                Name = "Property",
                Type = customObjectPropertyType
            });
            customObjectType.Properties.Add(new Property
            {
                Name = "Id",
                Type = PrimaryType.Int
            });

            var method = new Method
            {
                Name = "method1",
                Group = "mGroup",
                ReturnType = new Response(flattenedPropertyType, null)
            };
            var inputParameter = new Parameter { Name = "prop", Type = flattenedPropertyType };
            serviceClient.Methods.Add(method);
            method.Parameters.Add(inputParameter);
            method.InputParameterTransformation.Add(new ParameterTransformation
            {
                OutputParameter = new Parameter { Name = "body", Type = customObjectType, SerializedName = "body" }
            });
            method.InputParameterTransformation.Last().ParameterMappings.Add(new ParameterMapping
            {
                InputParameter = inputParameter,
                InputParameterProperty = "Id",
                OutputParameterProperty = "Id"
            });
            method.InputParameterTransformation.Last().ParameterMappings.Add(new ParameterMapping
            {
                InputParameter = inputParameter,
                InputParameterProperty = "Sku",
                OutputParameterProperty = "Property.Sku"
            });
            method.InputParameterTransformation.Last().ParameterMappings.Add(new ParameterMapping
            {
                InputParameter = inputParameter,
                InputParameterProperty = "ProvState",
                OutputParameterProperty = "Property.ProvState"
            });            

            MethodTemplateModel templateModel = new MethodTemplateModel(method, serviceClient);
            var output = templateModel.BuildInputMappings();
            string expected =
          @"String paramA = null;
            if (body != null)
            {
                paramA = body.A;
            }
            String paramB = null;
            if (body != null)
            {
                paramB = body.B;
            }";

            MultilineAreEqual(expected, output.Trim());
        }
        public void VerifyInputMappingsForFlattening()
        {
            var serviceClient = new ServiceClient();
            serviceClient.Name = "test service client";

            var customObjectType = new CompositeType();
            customObjectType.Name = "Foo";
            customObjectType.Properties.Add(new Property
            {
                Name = "A",
                Type = PrimaryType.Boolean
            });
            customObjectType.Properties.Add(new Property
            {
                Name = "B",
                Type = PrimaryType.String
            });
            var method = new Method
            {
                Name = "method1",
                Group = "mGroup",
                ReturnType = new Response(customObjectType, null)
            };
            var outputParameter = new Parameter { Name = "body", Type = customObjectType };
            serviceClient.Methods.Add(method);
            method.Parameters.Add(new Parameter { Name = "paramA", Type = PrimaryType.Boolean, SerializedName = "paramA" });
            method.Parameters.Add(new Parameter { Name = "paramB", Type = PrimaryType.String, SerializedName = "paramB" });
            method.InputParameterTransformation.Add(new ParameterTransformation
            {
                OutputParameter = outputParameter
            });
            method.InputParameterTransformation[0].ParameterMappings.Add(new ParameterMapping
            {
                InputParameter = method.Parameters[0],
                OutputParameterProperty = "A"
            });
            method.InputParameterTransformation[0].ParameterMappings.Add(new ParameterMapping 
            { 
                InputParameter = method.Parameters[1],
                OutputParameterProperty = "B"
            });

            MethodTemplateModel templateModel = new MethodTemplateModel(method, serviceClient);
            var output = templateModel.BuildInputMappings();
            string expected =
          @"Foo body = null;
            if (paramA != null || paramB != null)
            {
                body = new Foo();
                body.A = paramA;
                body.B = paramB;
            }";

            MultilineAreEqual(expected, output.Trim());
        }
Esempio n. 5
0
        public void VerifyInputMappingsForGrouping()
        {
            var serviceClient = new ServiceClient();

            serviceClient.Name = "test service client";

            var customObjectType = new CompositeType();

            customObjectType.Name = "Foo";
            customObjectType.Properties.Add(new Property
            {
                Name = "A",
                Type = PrimaryType.Boolean
            });
            customObjectType.Properties.Add(new Property
            {
                Name = "B",
                Type = PrimaryType.String
            });
            var method = new Method
            {
                Name       = "method1",
                Group      = "mGroup",
                ReturnType = new Response(customObjectType, null)
            };
            var inputParameter = new Parameter {
                Name = "body", Type = customObjectType
            };

            serviceClient.Methods.Add(method);
            method.Parameters.Add(inputParameter);
            method.InputParameterTransformation.Add(new ParameterTransformation
            {
                OutputParameter = new Parameter {
                    Name = "paramA", Type = PrimaryType.String, SerializedName = "paramA"
                }
            });
            method.InputParameterTransformation.Last().ParameterMappings.Add(new ParameterMapping
            {
                InputParameter         = inputParameter,
                InputParameterProperty = "A"
            });
            method.InputParameterTransformation.Add(new ParameterTransformation
            {
                OutputParameter = new Parameter {
                    Name = "paramB", Type = PrimaryType.String, SerializedName = "paramB"
                }
            });
            method.InputParameterTransformation.Last().ParameterMappings.Add(new ParameterMapping
            {
                InputParameter         = inputParameter,
                InputParameterProperty = "B"
            });

            MethodTemplateModel templateModel = new MethodTemplateModel(method, serviceClient);
            var    output   = templateModel.BuildInputMappings();
            string expected =
                @"String paramA = null;
            if (body != null)
            {
                paramA = body.A;
            }
            String paramB = null;
            if (body != null)
            {
                paramB = body.B;
            }";

            MultilineAreEqual(expected, output.Trim());
        }
        public void VerifyInputMappingsForGrouping()
        {
            var serviceClient = new ServiceClient();
            serviceClient.Name = "test service client";

            var customObjectType = new CompositeType();
            customObjectType.Name = "Foo";
            customObjectType.Properties.Add(new Property
            {
                Name = "A",
                Type = PrimaryType.Boolean
            });
            customObjectType.Properties.Add(new Property
            {
                Name = "B",
                Type = new PrimaryType(KnownPrimaryType.String)
            });
            var method = new Method
            {
                Name = "method1",
                Group = "mGroup",
                ReturnType = new Response(customObjectType, null)
            };
            var inputParameter = new Parameter { Name = "body", Type = customObjectType };
            serviceClient.Methods.Add(method);
            method.Parameters.Add(inputParameter);
            method.InputParameterTransformation.Add(new ParameterTransformation
            {
                OutputParameter = new Parameter { Name = "paramA", Type = new PrimaryType(KnownPrimaryType.String), SerializedName = "paramA" }
            });
            method.InputParameterTransformation.Last().ParameterMappings.Add(new ParameterMapping
            {
                InputParameter = inputParameter,
                InputParameterProperty = "A"
            });
            method.InputParameterTransformation.Add(new ParameterTransformation
            {
                OutputParameter = new Parameter { Name = "paramB", Type = new PrimaryType(KnownPrimaryType.String), SerializedName = "paramB" }
            });
            method.InputParameterTransformation.Last().ParameterMappings.Add(new ParameterMapping
            {
                InputParameter = inputParameter,
                InputParameterProperty = "B"
            });

            MethodTemplateModel templateModel = new MethodTemplateModel(method, serviceClient);
            var output = templateModel.BuildInputMappings();
            string expected =
          @"String paramA = null;
            if (body != null)
            {
                paramA = body.A;
            }
            String paramB = null;
            if (body != null)
            {
                paramB = body.B;
            }";

            MultilineAreEqual(expected, output.Trim());
        }