public void TestInitialize() { mockActionDescriptor = new Mock <HttpActionDescriptor>(); expectedModel = new RAMLModel { BaseUri = new Uri("http://www.test.com"), DefaultMediaType = "application/json", Description = "test", Title = "test", Version = "1", Routes = new List <RouteModel> { new RouteModel { UrlTemplate = "api/test", Verb = "get", Responses = null } } }; descriptions = new List <ApiDescription>() { new ApiDescription { HttpMethod = new System.Net.Http.HttpMethod("get"), RelativePath = "api/test", ActionDescriptor = mockActionDescriptor.Object } }; expectedResponseBody = new List <ResponseModel> { new ResponseModel { ContentType = "application/json", Description = "This is a json response.", Example = "{ 'value':'Hello World' }", StatusCode = System.Net.HttpStatusCode.OK }, new ResponseModel { ContentType = "application/xml", Description = "This is an error response in xml.", Example = "<error><message>opps</message></error>", StatusCode = System.Net.HttpStatusCode.BadRequest } }; expectedResponseBodyAttributes = new Collection <ResponseBodyAttribute>( expectedResponseBody.Select( p => new ResponseBodyAttribute { ContentType = p.ContentType, Description = p.Description, Example = p.Example, StatusCode = p.StatusCode } ).ToList()); }
public void TestInitialize() { expectedModel = new RAMLModel { BaseUri = new Uri("http://www.test.com"), DefaultMediaType = "application/json", Description = "test", Title = "test", Version = "1", Routes = new List <RouteModel>() }; }
public RAMLModel WebApiToRamlModel(Uri baseUri, string title, string version, string defaultMediaTypes, string description) { var model = new RAMLModel { BaseUri = baseUri, //new Uri("http://www.google.com"), Title = title, //"Super web api", Version = version, //"1" DefaultMediaType = defaultMediaTypes, Description = description, Routes = new List <RouteModel>() }; foreach (var api in _apiDescriptions) { IEnumerable <RequestHeadersAttribute> headers = null; IEnumerable <ResponseBodyAttribute> responseBody = null; if (api.ActionDescriptor != null) { headers = api.ActionDescriptor.GetCustomAttributes <RequestHeadersAttribute>(); responseBody = api.ActionDescriptor.GetCustomAttributes <ResponseBodyAttribute>(); } var routeModel = new RouteModel { Verb = api.HttpMethod.Method.ToLower(), UrlTemplate = api.RelativePath, Headers = GetHeaders(headers), //QueryParameters = GetQueryParameters(api), BodyParameters = GetBodyParameters(api), UriParameters = GetUriParameters(api), Responses = GetResponseBodies(responseBody), Description = api.Documentation }; if (routeModel.Verb == "put" || routeModel.Verb == "post") { routeModel.RequestContentType = "application/x-www-form-urlencoded:"; } model.Routes.Add(routeModel); } return(model); }
public void TestInitialize() { mockActionDescriptor = new Mock <HttpActionDescriptor>(); expectedModel = new RAMLModel { BaseUri = new Uri("http://www.test.com"), DefaultMediaType = "application/json", Description = "test", Title = "test", Version = "1", Routes = new List <RouteModel> { new RouteModel { UrlTemplate = "api/test", Verb = "get", Headers = null } } }; descriptions = new List <ApiDescription>() { new ApiDescription { HttpMethod = new System.Net.Http.HttpMethod("get"), RelativePath = "api/test", ActionDescriptor = mockActionDescriptor.Object } }; expectedHeader = new List <RequestHeaderModel> { new RequestHeaderModel { Name = "Accept", Description = "Used to tell the server what format it will accept.", Example = "application/json", IsRequired = false, Type = typeof(string) }, new RequestHeaderModel { Name = "Date", Description = "Used to tell the server when the request was made.", Example = "application/json", IsRequired = false, Type = typeof(DateTime) } }; expectedHeaderAttributes = new Collection <RequestHeadersAttribute>( expectedHeader.Select( p => new RequestHeadersAttribute { Name = p.Name, Description = p.Description, Example = p.Example, IsRequired = p.IsRequired, Type = p.Type } ).ToList()); }