private void AppendRoot(ApisRoot tree)
        {
            this.isDirty = true;

            if (this.root == null)
            {
                this.root = tree;
            }
            else
            {
                foreach (var apiGroup in tree.ApiGroups)
                {
                    var matchGroup = this.root.ApiGroups.SingleOrDefault(g => g.Name == apiGroup.Name);
                    if (matchGroup != null)
                    {
                        matchGroup.Methods.AddRange(apiGroup.Methods);
                        matchGroup.ReturnTypes.AddRange(apiGroup.ReturnTypes);
                    }
                    else
                    {
                        this.root.ApiGroups.Add(apiGroup);
                    }
                }
            }
        }
        private void AppendRoot(ApisRoot tree)
        {
            this.isDirty = true;

            if (this.root == null)
            {
                this.root = tree;
            }
            else
            {
                foreach (var apiGroup in tree.ApiGroups)
                {
                    var matchGroup = this.root.ApiGroups.SingleOrDefault(g => g.Name == apiGroup.Name);
                    if (matchGroup != null)
                    {
                        matchGroup.Methods.AddRange(apiGroup.Methods);
                        matchGroup.ReturnTypes.AddRange(apiGroup.ReturnTypes);
                    }
                    else
                    {
                        this.root.ApiGroups.Add(apiGroup);
                    }
                }
            }
        }
 public ServiceDefinition(ApisRoot apisRoot)
 {
     this.apisRoot = apisRoot;
 }
        public void MyTestMethod()
        {
            var stream = new System.IO.MemoryStream();
            var writer = new System.IO.StreamWriter(stream);
            var generator = new CSharpGenerator(writer);
            var root = new ApisRoot
            {
                ApiGroups = new List<ApiGroup>()
                {
                    new ApiGroup
                    {
                        Name = "g",
                        Methods = new List<ApiMethod>()
                        {
                            new ApiMethod
                            {
                                Path = "/v1/test1",
                                MethodName="mtd1",
                            },
                            new ApiMethod
                            {
                                Path = "/v1/test1/{UserId}",
                                MethodName="mtd2",
                            },
                        },
                        ReturnTypes = new List<ReturnType>(),
                    },
                },
            };
            var builder = new ServiceDefinitionBuilder();
            builder.AppendServiceDefinition(new ServiceDefinition(root));
            generator.Run(builder.Definition);

            writer.Flush();
            stream.Seek(0L, System.IO.SeekOrigin.Begin);
            var result = new StreamReader(stream).ReadToEnd();

            Assert.IsFalse(string.IsNullOrEmpty(result));
            Assert.IsTrue(result.Contains("public void mtd1("));
            Assert.IsTrue(result.Contains("public void mtd2("));
            Assert.IsTrue(result.Contains("string userId"));
        }
        public void ImplicitSubReturnTypes()
        {
            var stream = new System.IO.MemoryStream();
            var writer = new System.IO.StreamWriter(stream);
            var generator = new CSharpGenerator(writer);
            var root = new ApisRoot
            {
                ApiGroups = new List<ApiGroup>()
                {
                    new ApiGroup
                    {
                        Name = "g",
                        Methods = new List<ApiMethod>(),
                        ReturnTypes = new List<ReturnType>()
                        {
                            new ReturnType
                            {
                                Name = "r1",
                                Fields = new List<Field>()
                                {
                                    new Field
                                    {
                                        Name = "f1",
                                    },
                                    new Field
                                    {
                                        Name = "f2:(r2:(name))",
                                    },
                                },
                            },
                        },
                    },
                },
            };
            var builder = new ServiceDefinitionBuilder();
            builder.AppendServiceDefinition(new ServiceDefinition(root));
            generator.Run(builder.Definition);

            writer.Flush();
            stream.Seek(0L, System.IO.SeekOrigin.Begin);
            var result = new StreamReader(stream).ReadToEnd();

            Assert.IsFalse(string.IsNullOrEmpty(result));
            Assert.IsTrue(result.Contains("public class R1"));
            Assert.IsTrue(result.Contains("public class F2"));
            Assert.IsTrue(result.Contains("public string F1"));
            Assert.IsTrue(result.Contains("public F2 F2"));
            Assert.IsTrue(result.Contains("public string Name"));
        }
 public ServiceDefinition(ApisRoot apisRoot)
 {
     this.apisRoot = apisRoot;
 }