Ejemplo n.º 1
0
        public void RamlMapper_CreateOneApiWithNullType_DoNotDisplayTypeField()
        {
            expectedHeader[0].Type           = null;
            expectedHeaderAttributes[0].Type = null;

            expectedModel.Routes[0].Headers = new List <RequestHeaderModel>
            {
                expectedHeader[0]
            };
            var headerAttribute = new Collection <RequestHeadersAttribute>
            {
                expectedHeaderAttributes[0]
            };

            mockActionDescriptor.Setup(p => p.GetCustomAttributes <RequestHeadersAttribute>())
            .Returns(headerAttribute);

            var subject = new RAMLMapper(descriptions);
            var result  = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", "1", "application/json", "test");

            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
            var r = result.ToString();

            Assert.IsTrue(result.ToString().Contains("headers:"));
            Assert.IsFalse(result.ToString().Contains("        type:"));
        }
Ejemplo n.º 2
0
        public void RAMLSharp_CreateRamlDocumentWithOneApi_GenerateRAMLWithOneAPI()
        {
            expectedModel.Routes = new List <RouteModel>
            {
                new RouteModel
                {
                    UrlTemplate = "api/test",
                    Verb        = "get"
                }
            };

            IEnumerable <ApiDescription> model = new List <ApiDescription>()
            {
                new ApiDescription
                {
                    HttpMethod   = new System.Net.Http.HttpMethod("get"),
                    RelativePath = "api/test"
                }
            };

            var subject = new RAMLMapper(model);
            var result  = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", "1", "application/json", "test");

            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
        }
Ejemplo n.º 3
0
        public void RAMLSharp_CreateRamlDocumentWithNullAPIs_DisplayBasicRAMLDocument()
        {
            IEnumerable<ApiDescription> modelApiDescription = null;

            var subject = new RAMLMapper(modelApiDescription);
            var result = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", "1", "application/json", "test");

            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
        }
Ejemplo n.º 4
0
        public void RAMLSharp_CreateRamlDocumentWithNullAPIs_DisplayBasicRAMLDocument()
        {
            IEnumerable <ApiDescription> modelApiDescription = null;

            var subject = new RAMLMapper(modelApiDescription);
            var result  = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", "1", "application/json", "test");

            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
        }
Ejemplo n.º 5
0
        public void RAMLSharp_CreateRamlDocumentWithProtocol_GenerateRAMLWithProtocol()
        {
            IEnumerable <ApiDescription> model = null;

            var subject = new RAMLMapper(model);
            var result  = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", "1", "application/json", "test");

            Assert.IsTrue(result.ToString().Contains("protocols: [HTTP]"));
        }
Ejemplo n.º 6
0
        public void RAMLSharp_CreateRamlDocumentWithDescription_GenerateRAMLWithDescription()
        {
            IEnumerable<ApiDescription> model = null;

            var subject = new RAMLMapper(model);
            var result = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", "1", "application/json", "test");

            Assert.IsTrue(result.ToString().Contains("content:"));
        }
Ejemplo n.º 7
0
        public void RAMLSharp_CreateRamlDocumentWithNullUri_DisplayBasicRAMLDocumentWithoutURI()
        {
            expectedModel.BaseUri = null;
            var model = new List <ApiDescription>();

            var subject = new RAMLMapper(model);
            var result  = subject.WebApiToRamlModel(expectedModel.BaseUri, "test", "1", "application/json", "test");

            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
        }
Ejemplo n.º 8
0
        public void RAMLSharp_CreateRamlDocumentWithNullBaseMediaType_DisplayBasicRAMLDocumentWithoutMediaType()
        {
            expectedModel.DefaultMediaType = null;
            var model = new List<ApiDescription>();

            var subject = new RAMLMapper(model);
            var result = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", "1", expectedModel.DefaultMediaType, "test");

            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
            Assert.IsFalse(result.ToString().Contains("mediaType:"));
        }
Ejemplo n.º 9
0
        public void RAMLSharp_CreateRamlDocumentWithNullVersion_DisplayBasicRAMLDocumentWithoutVersion()
        {
            expectedModel.Version = null;
            var model = new List <ApiDescription>();

            var subject = new RAMLMapper(model);
            var result  = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", expectedModel.Version, "application/json", "test");

            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
            Assert.IsFalse(result.ToString().Contains("version:"));
        }
Ejemplo n.º 10
0
        public void RAMLSharp_CreateRamlDocumentWithNullBaseMediaType_DisplayBasicRAMLDocumentWithoutMediaType()
        {
            expectedModel.DefaultMediaType = null;
            var model = new List <ApiDescription>();

            var subject = new RAMLMapper(model);
            var result  = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", "1", expectedModel.DefaultMediaType, "test");

            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
            Assert.IsFalse(result.ToString().Contains("mediaType:"));
        }
Ejemplo n.º 11
0
		public HttpResponseMessage RAML()
		{
			var result = new HttpResponseMessage(HttpStatusCode.OK);

			var r = new RAMLMapper(this);
			var data = r.WebApiToRamlModel (new Uri ("http://www.google.com"), "Test API", "1", "application/json", "This is a test");

			result.Content = new StringContent(data.ToString());
			result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/raml+yaml");
			result.Content.Headers.ContentLength = data.ToString().Length;
			return result;
		}
Ejemplo n.º 12
0
        public void RAMLSharp_CreateRamlDocumentWithNullTitle_DisplayBasicRAMLDocumentWithBlankTitle()
        {
            expectedModel.Title = null;
            var model = new List <ApiDescription>();

            var subject = new RAMLMapper(model);
            var result  = subject.WebApiToRamlModel(new Uri("http://www.test.com"), expectedModel.Title, "1", "application/json", "test");
            var r       = result.ToString();

            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
            Assert.IsTrue(result.ToString().Contains("title:"));
        }
Ejemplo n.º 13
0
        public HttpResponseMessage RAML()
        {
            var result = new HttpResponseMessage(HttpStatusCode.OK);

            var r    = new RAMLMapper(this);
            var data = r.WebApiToRamlModel(new Uri("http://www.google.com"), "Test API", "1", "application/json", "This is a test");

            result.Content = new StringContent(data.ToString());
            result.Content.Headers.ContentType   = new MediaTypeHeaderValue("application/raml+yaml");
            result.Content.Headers.ContentLength = data.ToString().Length;
            return(result);
        }
        public void RamlMapper_CreateNullResponseBody_GenerateRAML()
        {
            expectedResponseBodyAttributes = null;
            mockActionDescriptor.Setup(p => p.GetCustomAttributes <ResponseBodyAttribute>())
            .Returns(expectedResponseBodyAttributes);

            var subject = new RAMLMapper(descriptions);
            var result  = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", "1", "application/json", "test");

            Assert.IsFalse(result.ToString().Contains("    body:"));
            Assert.IsFalse(result.ToString().Contains("          application/json:"));
            Assert.IsFalse(result.ToString().Contains("          application/xml:"));
            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
        }
Ejemplo n.º 15
0
        public void RamlMapper_CreateOneApiWithMultipleHeaders_Display2Headers()
        {
            expectedModel.Routes[0].Headers = expectedHeader;

            mockActionDescriptor.Setup(p => p.GetCustomAttributes <RequestHeadersAttribute>())
            .Returns(expectedHeaderAttributes);

            var subject = new RAMLMapper(descriptions);
            var result  = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", "1", "application/json", "test");

            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
            Assert.IsTrue(result.ToString().Contains("headers:"));
            Assert.IsTrue(result.ToString().Contains("Accept:"));
            Assert.IsTrue(result.ToString().Contains("Date:"));
        }
Ejemplo n.º 16
0
        public void RamlMapper_CreateEmptyResponseBody_GenerateRAML()
        {
            expectedResponseBody = new List<ResponseModel>();
            expectedResponseBodyAttributes = new Collection<ResponseBodyAttribute>();

            mockActionDescriptor.Setup(p => p.GetCustomAttributes<ResponseBodyAttribute>())
                                .Returns(expectedResponseBodyAttributes);

            var subject = new RAMLMapper(descriptions);
            var result = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", "1", "application/json", "test");

            Assert.IsFalse(result.ToString().Contains("    body:"));
            Assert.IsFalse(result.ToString().Contains("          application/json:"));
            Assert.IsFalse(result.ToString().Contains("          application/xml:"));
            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
        }
Ejemplo n.º 17
0
        public void RamlMapper_CreateOneApiWithTwoNullName_DoNotDisplayHeaderSection()
        {
            expectedHeader[0].Name          = null;
            expectedHeader[1].Name          = null;
            expectedModel.Routes[0].Headers = expectedHeader;

            expectedHeaderAttributes[0].Name = null;
            expectedHeaderAttributes[1].Name = null;

            mockActionDescriptor.Setup(p => p.GetCustomAttributes <RequestHeadersAttribute>())
            .Returns(expectedHeaderAttributes);

            var subject = new RAMLMapper(descriptions);
            var result  = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", "1", "application/json", "test");

            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
            Assert.IsFalse(result.ToString().Contains("headers:"));
        }
Ejemplo n.º 18
0
        public void RamlMapper_CreateNullDescription_GenerateRAMLWithoutDescription()
        {
            expectedResponseBody[0].Example = null;
            expectedResponseBodyAttributes[0].Example = null;
            expectedResponseBody[1].Example = null;
            expectedResponseBodyAttributes[1].Example = null;

            expectedModel.Routes[0].Responses = expectedResponseBody;
            mockActionDescriptor.Setup(p => p.GetCustomAttributes<ResponseBodyAttribute>())
                                .Returns(expectedResponseBodyAttributes);

            var subject = new RAMLMapper(descriptions);
            var result = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", "1", "application/json", "test");

            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
            Assert.IsTrue(result.ToString().Contains("    body:"));
            Assert.IsTrue(result.ToString().Contains("          application/json:"));
            Assert.IsFalse(result.ToString().Contains("            description:"));
        }
Ejemplo n.º 19
0
        public void RAMLSharp_CreateRamlDocumentWithNullTitle_DisplayBasicRAMLDocumentWithBlankTitle()
        {
            expectedModel.Title = null;
            var model = new List<ApiDescription>();

            var subject = new RAMLMapper(model);
            var result = subject.WebApiToRamlModel(new Uri("http://www.test.com"), expectedModel.Title, "1", "application/json", "test");
            var r = result.ToString();
            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
            Assert.IsTrue(result.ToString().Contains("title:"));
        }
Ejemplo n.º 20
0
        public void RAMLSharp_CreateRamlDocumentWithNullUri_DisplayBasicRAMLDocumentWithoutURI()
        {
            expectedModel.BaseUri = null;
            var model = new List<ApiDescription>();

            var subject = new RAMLMapper(model);
            var result = subject.WebApiToRamlModel(expectedModel.BaseUri, "test", "1", "application/json", "test");

            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
        }
Ejemplo n.º 21
0
        public void RAMLSharp_CreateRamlDocumentWithNullVersion_DisplayBasicRAMLDocumentWithoutVersion()
        {
            expectedModel.Version = null;
            var model = new List<ApiDescription>();

            var subject = new RAMLMapper(model);
            var result = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", expectedModel.Version, "application/json", "test");

            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
            Assert.IsFalse(result.ToString().Contains("version:"));
        }
Ejemplo n.º 22
0
        public void RAMLSharp_CreateRamlDocumentWithOneApi_GenerateRAMLWithOneAPI()
        {
            expectedModel.Routes = new List<RouteModel>
            {
                new RouteModel
                {
                    UrlTemplate="api/test",
                    Verb="get"
                }
            };

            IEnumerable<ApiDescription> model = new List<ApiDescription>()
            {
                new ApiDescription
                {
                     HttpMethod = new System.Net.Http.HttpMethod("get"),
                     RelativePath = "api/test"
                }
            };

            var subject = new RAMLMapper(model);
            var result = subject.WebApiToRamlModel(new Uri("http://www.test.com"), "test", "1", "application/json", "test");

            Assert.AreEqual(expectedModel.ToString(), result.ToString(), "The RAML string must be the same.");
        }