Ejemplo n.º 1
0
        public void Generate_docs_with_terms_of_services()
        {
            //Arrange
            string TermsOfService = "blah blah blah";
            var    module         = new FakeDocsModule(new DefaultRouteCacheProvider(() => new FakeRouteCache()), TermsOfService);

            //Act
            var    response = module.GetDocumentation();
            string body;

            using (var memoryStream = new MemoryStream())
            {
                response.Contents.Invoke(memoryStream);
                body = Encoding.UTF8.GetString(memoryStream.GetBuffer());
            }

            var spec = JsonConvert.DeserializeObject <OpenApiSpecification>(body);

            //Assert
            Assert.All(spec.Servers, item => Assert.Contains(item.Description, FakeDocsModule.Server.Description));
            Assert.All(spec.Servers, item => Assert.Contains(item.Url, FakeDocsModule.Server.Url));
            Assert.Equal(FakeDocsModule.Title, spec.Info.Title);
            Assert.Equal(FakeDocsModule.ApiVersion, spec.Info.Version);
            Assert.Equal(TermsOfService, spec.Info.TermsOfService);
        }
Ejemplo n.º 2
0
        public void Generate_docs_with_License()
        {
            //Arrange
            var module = new FakeDocsModule(new DefaultRouteCacheProvider(() => new FakeRouteCache()));
            var lic    = new FakeLicense();

            //Act
            module.FillLicense(lic.Name, lic.Url);

            var response = module.GetDocumentation();

            string body;

            using (var memoryStream = new MemoryStream())
            {
                response.Contents.Invoke(memoryStream);
                body = Encoding.UTF8.GetString(memoryStream.GetBuffer());
            }

            var spec = JsonConvert.DeserializeObject <OpenApiSpecification>(body);

            //Assert
            Assert.Equal(lic.Name, spec.Info.License.Name);
            Assert.Equal(lic.Url, spec.Info.License.Url);
        }
Ejemplo n.º 3
0
        public void Generate_docs_with_tags()
        {
            //Arrange
            Tag[] Tags = { new Tag()
                           {
                               Name = "Default"
                           } };
            var   module = new FakeDocsModule(new DefaultRouteCacheProvider(() => new FakeRouteCache()), Tags);

            //Act
            var    response = module.GetDocumentation();
            string body;

            using (var memoryStream = new MemoryStream())
            {
                response.Contents.Invoke(memoryStream);
                body = Encoding.UTF8.GetString(memoryStream.GetBuffer());
            }

            var spec = JsonConvert.DeserializeObject <OpenApiSpecification>(body);

            //Assert
            Assert.All(spec.Servers, item => Assert.Contains(item.Description, FakeDocsModule.Server.Description));
            Assert.All(spec.Servers, item => Assert.Contains(item.Url, FakeDocsModule.Server.Url));
            Assert.Equal(FakeDocsModule.Title, spec.Info.Title);
            Assert.Equal(FakeDocsModule.ApiVersion, spec.Info.Version);
            Assert.True(Tags.All(t => spec.Tags.Any(
                                     s => t.Name == s.Name &&
                                     t.Description == s.Description &&
                                     t.ExternalDocumentation == s.ExternalDocumentation
                                     )));
        }
Ejemplo n.º 4
0
        public void Generate_docs_with_external_doc()
        {
            //Arrange
            var module = new FakeDocsModule(new DefaultRouteCacheProvider(() => new FakeRouteCache()));
            var doc    = new FakeExternalDoc();

            //Act
            module.FillExternalDoc(doc.Description, doc.Url);

            var response = module.GetDocumentation();

            string body;

            using (var memoryStream = new MemoryStream())
            {
                response.Contents.Invoke(memoryStream);
                body = Encoding.UTF8.GetString(memoryStream.GetBuffer());
            }

            var spec = JsonConvert.DeserializeObject <OpenApiSpecification>(body);

            //Assert
            Assert.Equal(doc.Description, spec.ExternalDocs.Description);
            Assert.Equal(doc.Url, spec.ExternalDocs.Url);
        }