public void should_build_uri_parameter_objects()
        {
            var doc = new RamlDocument { Title = "test" };

            var uriParams = new Dictionary<string, Parameter>()
                            {
                                {
                                    "code", new Parameter
                                            {
                                                DisplayName = "code",
                                                Type = "integer"
                                            }
                                },
                                {
                                    "token", new Parameter
                                             {
                                                 DisplayName = "token",
                                                 Type = "string"
                                             }
                                }
                            };



            var methods = new List<Method>
                          {
                              new Method
                              {
                                  Verb = "get",
                              },
                              new Method
                              {
                                  Verb = "post"
                              }
                          };

            var resources = new Collection<Resource>
                            {
                                new Resource
                                {
                                    RelativeUri = "/movies",
                                    UriParameters = uriParams,
                                    Methods = methods
                                }
                            };

            doc.Resources = resources;

            var service = new ClientGeneratorService(doc, "test");
            var model = service.BuildModel();

            Assert.AreEqual(1, model.UriParameterObjects.Count);
            Assert.AreEqual(2, model.UriParameterObjects.First().Value.Properties.Count);
            Assert.IsTrue(model.Classes.First().Methods.All(m => m.UriParametersType == "MoviesUriParameters"));
            Assert.AreEqual(1, model.Objects.Count());
        }
        public void Should_Build_Multiple_Headers_When_Many_Response_With_Headers()
        {
            var doc = new RamlDocument {Title = "test"};

            var okHeaders = new List<Parameter>
                            {
                                new Parameter
                                {
                                    DisplayName = "code",
                                    Type = "integer"
                                },
                                new Parameter
                                {
                                    DisplayName = "token",
                                    Type = "string"
                                }
                            };

            var errorHeaders = new List<Parameter>
                            {
                                new Parameter
                                {
                                    DisplayName = "code",
                                    Type = "integer"
                                },
                                new Parameter
                                {
                                    DisplayName = "error",
                                    Type = "string"
                                }
                            };

            var badRequestHeaders = new List<Parameter>
                            {
                                new Parameter
                                {
                                    DisplayName = "code",
                                    Type = "integer"
                                },
                                new Parameter
                                {
                                    DisplayName = "description",
                                    Type = "string"
                                }
                            };

            var okResponse = new Response
                             {
                                 Code = "200",
                                 Headers = okHeaders
                             };

            var errorResponse = new Response
                                {
                                    Code = "400",
                                    Headers = errorHeaders
                                };

            var notFoundResponse = new Response
                                   {
                                       Code = "404",
                                       Headers = badRequestHeaders
                                   };

            var methods = new List<Method>
                          {
                              new Method
                              {
                                  Verb = "get",
                                  Responses = new[] { okResponse, errorResponse, notFoundResponse }
                              }
                          };

            var resources = new Collection<Resource>
                            {
                                new Resource
                                {
                                    RelativeUri = "movies",
                                    Methods = methods
                                }
                            };

            doc.Resources = resources;

            var service = new ClientGeneratorService(doc, "test", "TargetNamespace");
            var model = service.BuildModel();
            Assert.AreEqual(4, model.ResponseHeaderObjects.Count);

            var multipleModel = model.ResponseHeaderObjects.First(o => o.Key.Contains("Multiple")).Value;

            Assert.AreEqual(3, multipleModel.Properties.Count);

            Assert.AreEqual("Models." + model.ResponseHeaderObjects.First(o => o.Key.Contains("Multiple")).Value.Name,
                model.Classes.First().Methods.First().ResponseHeaderType);
        }
        public void should_keep_original_names()
        {
            var doc = new RamlDocument { Title = "test" };

            var uriParams = new Dictionary<string, Parameter>()
                            {
                                {
                                    "code-oneOne", new Parameter
                                            {
                                                DisplayName = "code",
                                                Type = "integer"
                                            }
                                },
                                {
                                    "token_Two", new Parameter
                                             {
                                                 DisplayName = "token",
                                                 Type = "string"
                                             }
                                }
                            };

            var methods = new List<Method>
                          {
                              new Method
                              {
                                  Verb = "get",
                              },
                              new Method
                              {
                                  Verb = "post"
                              }
                          };

            var resources = new Collection<Resource>
                            {
                                new Resource
                                {
                                    RelativeUri = "/movies",
                                    UriParameters = uriParams,
                                    Methods = methods
                                }
                            };

            doc.Resources = resources;

            var service = new ClientGeneratorService(doc, "test", "TestNs");
            var model = service.BuildModel();

            Assert.AreEqual("code-oneOne", model.UriParameterObjects.First().Value.Properties.First(p => p.Name == "CodeoneOne").OriginalName);
            Assert.AreEqual("token_Two", model.UriParameterObjects.First().Value.Properties.First(p => p.Name == "Token_Two").OriginalName);
        }
        public void Should_Get_Multiple_Type_When_Many_Response_Schemas_On_Resource()
        {
            var doc = new RamlDocument { Title = "test" };

            var okResponse = new Response
            {
                Code = "200",
                Body = new Dictionary<string, MimeType>
                                        {
                                            {
                                                "application/json", new MimeType
                                                                    {
                                                                        Schema = movieSchema
                                                                    }
                                            }
                                        }
            };

            var errorResponse = new Response
            {
                Code = "400",
                Body = new Dictionary<string, MimeType>
                                           {
                                               {
                                                   "application/json", new MimeType
                                                                       {
                                                                           Schema = errorSchema
                                                                       }
                                               }
                                           }
            };

            var notFoundResponse = new Response
            {
                Code = "404",
                Body = new Dictionary<string, MimeType>
                                              {
                                                  {
                                                      "application/json", new MimeType
                                                                          {
                                                                              Schema = notFoundSchema
                                                                          }
                                                  }
                                              }
            };

            var methods = new List<Method>
                          {
                              new Method
                              {
                                  Verb = "get",
                                  Responses = new[] { okResponse, errorResponse, notFoundResponse }
                              }
                          };

            var resources = new Collection<Resource>
                            {
                                new Resource
                                {
                                    RelativeUri = "/movies",
                                    Methods = methods
                                }
                            };

            doc.Resources = resources;

            var service = new ClientGeneratorService(doc, "test", "TestNs");
            var model = service.BuildModel();
            Assert.AreEqual(4, model.ResponseObjects.Count);

            var multipleModel = model.ResponseObjects.First(o => o.Key.Contains("Multiple")).Value;

            Assert.AreEqual(3, multipleModel.Properties.Count);
        }
        public void Should_Get_Multiple_Type_When_Many_Response_Schemas_On_Root()
        {
            var doc = new RamlDocument {Title = "test"};
            var schemas = new List<Dictionary<string, string>>();
            var schemaMovie = new Dictionary<string, string>();
            schemaMovie.Add("movie", movieSchema);
            var schemaError = new Dictionary<string, string>();
            schemaMovie.Add("error", errorSchema);
            var schemaNotFound = new Dictionary<string, string>();
            schemaMovie.Add("notfound", notFoundSchema);
            schemas.Add(schemaMovie);
            schemas.Add(schemaError);
            schemas.Add(schemaNotFound);
            doc.Schemas = schemas;

            var okResponse = new Response
                             {
                                 Code = "200",
                                 Body = new Dictionary<string, MimeType>
                                        {
                                            {
                                                "application/json", new MimeType
                                                                    {
                                                                        Schema = "movie"
                                                                    }
                                            }
                                        }
                             };

            var errorResponse = new Response
                                {
                                    Code = "400",
                                    Body = new Dictionary<string, MimeType>
                                           {
                                               {
                                                   "application/json", new MimeType
                                                                       {
                                                                           Schema = "error"
                                                                       }
                                               }
                                           }
                                };

            var notFoundResponse = new Response
                                   {
                                       Code = "404",
                                       Body = new Dictionary<string, MimeType>
                                              {
                                                  {
                                                      "application/json", new MimeType
                                                                          {
                                                                              Schema = "notfound"
                                                                          }
                                                  }
                                              }
                                   };

            var methods = new List<Method>
                          {
                              new Method
                              {
                                  Verb = "get",
                                  Responses = new[] { okResponse, errorResponse, notFoundResponse }
                              }
                          };

            var resources = new Collection<Resource>
                            {
                                new Resource
                                {
                                    RelativeUri = "/movies",
                                    Methods = methods
                                }
                            };

            doc.Resources = resources;

            var service = new ClientGeneratorService(doc, "test", "TestNs");
            var model = service.BuildModel();
            Assert.AreEqual(1, model.ResponseObjects.Count);
            Assert.AreEqual(3, model.SchemaObjects.Count);

            var multipleModel = model.ResponseObjects.First(o => o.Key.Contains("Multiple")).Value;

            Assert.AreEqual(3, multipleModel.Properties.Count);

            Assert.AreEqual(1, multipleModel.Properties.Count(p => p.Type == "Movie"));
            Assert.AreEqual(1, multipleModel.Properties.Count(p => p.Type == "Error"));
            Assert.AreEqual(1, multipleModel.Properties.Count(p => p.Type == "Notfound"));
        }
        public void Should_Build_Uri_Parameters_From_Resources()
        {
            var doc = new RamlDocument { Title = "test" };

            var uriParameters = new Dictionary<string, Parameter>
                                {
                                    {
                                        "code", new Parameter
                                                {
                                                    DisplayName = "code",
                                                    Type = "integer"
                                                }
                                    },
                                    {
                                        "token", new Parameter
                                                 {
                                                     DisplayName = "token",
                                                     Type = "string"
                                                 }
                                    }
                                };

            var methods = new List<Method>
                          {
                              new Method
                              {
                                  Verb = "get"
                              }
                          };

            var resources = new Collection<Resource>
                            {
                                new Resource
                                {
                                    RelativeUri = "/movies/{token}/abc/{code}/asd/{extra}",
                                    Methods = methods,
                                    UriParameters = uriParameters
                                },
                                new Resource
                                {
                                    RelativeUri = "/directors/{a}/abc/{b}{c}/asd/{d}",
                                    Methods = methods
                                }
                            };

            doc.Resources = resources;

            var service = new ClientGeneratorService(doc, "test");
            var model = service.BuildModel();
            Assert.AreEqual(2, model.UriParameterObjects.Count);

            var moviesUriParamObj = model.UriParameterObjects.First(o => o.Key.ToLowerInvariant().Contains("movies")).Value;
            var directorsUriParamObj = model.UriParameterObjects.First(o => o.Key.ToLowerInvariant().Contains("directors")).Value;

            Assert.AreEqual(3, moviesUriParamObj.Properties.Count);
            Assert.AreEqual(4, directorsUriParamObj.Properties.Count);
        }
        public void Should_Build_Uri_Parameters_When_Nested_Resources()
        {
            var doc = new RamlDocument { Title = "test" };

            var uriParameters = new Dictionary<string, Parameter>
                                {
                                    {
                                        "code", new Parameter
                                                {
                                                    DisplayName = "code",
                                                    Type = "integer"
                                                }
                                    },
                                    {
                                        "token", new Parameter
                                                 {
                                                     DisplayName = "token",
                                                     Type = "string"
                                                 }
                                    }
                                };

            var methods = new List<Method>
                          {
                              new Method
                              {
                                  Verb = "get"
                              }
                          };

            var resources = new Collection<Resource>
                            {
                                new Resource
                                {
                                    RelativeUri = "/movies/{token}{extra}/abc/{code}{extra}/asd",
                                    Methods = methods,
                                    UriParameters = uriParameters,
                                    Resources = new[]
                                                {
                                                    new Resource
                                                    {
                                                        RelativeUri = "/{a}{b}",
                                                        Methods = methods
                                                    }

                                                }
                                }
                            };

            doc.Resources = resources;

            var service = new ClientGeneratorService(doc, "test");
            var model = service.BuildModel();
            Assert.AreEqual(2, model.UriParameterObjects.Count);

            var moviesUriParamObj = model.UriParameterObjects.First().Value;
            var directorsUriParamObj = model.UriParameterObjects.Last().Value;

            Assert.AreEqual(3, moviesUriParamObj.Properties.Count);
            Assert.AreEqual(5, directorsUriParamObj.Properties.Count);
        }
        public void Should_Inherit_Uri_Parameters_When_Nested_Resources_ClientCase2()
        {
            var doc = new RamlDocument { Title = "test" };

            var uriParameters1 = new Dictionary<string, Parameter>
                                {
                                    {
                                        "id", new Parameter
                                                {
                                                    DisplayName = "id",
                                                    Type = "integer"
                                                }
                                    }
                                };

            var uriParameters2 = new Dictionary<string, Parameter>
                                {
                                    {
                                        "current", new Parameter
                                                 {
                                                     DisplayName = "current",
                                                     Type = "boolean"
                                                 }
                                    }
                                };

            var methods = new List<Method>
                          {
                              new Method
                              {
                                  Verb = "get"
                              }
                          };

            var resources = new Collection<Resource>
            {
                new Resource
                {
                    RelativeUri = "/{id}",
                    Methods = methods,
                    UriParameters = uriParameters1,
                    Resources = new Collection<Resource>
                    {
                        new Resource
                        {
                            RelativeUri = "/something",
                            Methods = methods,
                            Resources = new Collection<Resource>
                            {
                                new Resource
                                {
                                    RelativeUri = "/{current}",
                                    Methods = methods,
                                    UriParameters = uriParameters2,
                                    Resources = new Collection<Resource>
                                    {
                                        new Resource
                                        {
                                            RelativeUri = "/deep",
                                            Methods = methods
                                        }
                                    }

                                }
                            }
                        }
                    }
                }
            };

            doc.Resources = resources;

            var service = new ClientGeneratorService(doc, "test", "TargetNamespace");
            var model = service.BuildModel();
            Assert.AreEqual("bool", model.Classes.First(m => m.Name.Contains("Deep")).Methods.First().UriParameters.First(p => p.Name == "current").Type);
            Assert.AreEqual("int", model.Classes.First(m => m.Name.Contains("Deep")).Methods.First().UriParameters.First(p => p.Name == "id").Type);
        }