Exemplo n.º 1
0
        public void Generate_docs_with_external_doc()
        {
            //Arrange
            var module = new FakeModule(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.ASCII.GetString(memoryStream.GetBuffer());
            }

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

            //Assert
            Assert.NotNull(spec.ExternalDocs);
            Assert.Equal(doc.Description, spec.ExternalDocs.Description);
            Assert.Equal(doc.Url, spec.ExternalDocs.Url);
        }
Exemplo n.º 2
0
        public void Generate_docs_with_contact_info()
        {
            //Arrange
            var module  = new FakeModule(new DefaultRouteCacheProvider(() => new FakeRouteCache()));
            var contact = new FakeContact();

            //Act
            module.FillContact(contact.Name, contact.Email, contact.Url);

            var response = module.GetDocumentation();

            string body;

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

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

            //Assert
            Assert.NotNull(spec.Info);
            Assert.NotNull(spec.Info.Contact);
            Assert.Equal(contact.Name, spec.Info.Contact.Name);
            Assert.Equal(contact.Email, spec.Info.Contact.Email);
            Assert.Equal(contact.Url, spec.Info.Contact.Url);
        }
Exemplo n.º 3
0
        public void Generate_docs()
        {
            //Arrange
            var module = new FakeModule(new DefaultRouteCacheProvider(() => new FakeRouteCache()));

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

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

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

            //Assert
            Assert.NotNull(spec.Info);
            Assert.NotNull(spec.Servers);
            Assert.Equal(FakeModule.Server.Description, spec.Servers[0].Description);
            Assert.Equal(FakeModule.Server.Url, spec.Servers[0].Url);
            Assert.Equal(FakeModule.Title, spec.Info.Title);
            Assert.Equal(FakeModule.ApiVersion, spec.Info.Version);
            Assert.Equal(FakeModule.TermsOfService, spec.Info.TermsOfService);
            Assert.True(FakeModule.Tags.All(t => spec.Tags.Any(
                                                s => t.Name == s.Name &&
                                                t.Description == s.Description &&
                                                t.ExternalDocumentation == s.ExternalDocumentation
                                                )));
        }
Exemplo n.º 4
0
        public void Should_strip_module_from_name()
        {
            // Given
            NancyModule module = new FakeModule();

            // When
            var name = module.GetModuleName();

            // Then
            name.ShouldEqual("Fake");
        }
Exemplo n.º 5
0
        public void Should_strip_module_from_name()
        {
            // Given
            NancyModule module = new FakeModule();

            // When
            var name = module.GetModuleName();

            // Then
            name.ShouldEqual("Fake");
        }
Exemplo n.º 6
0
        public void Should_add_both_basic_and_requires_auth_pre_and_post_hooks_in_module_when_enabled()
        {
            // Given
            var module = new FakeModule();

            // When
            BasicAuthentication.Enable(module, this.config);

            // Then
            module.Before.PipelineDelegates.ShouldHaveCount(2);
        }
Exemplo n.º 7
0
        public void Should_add_both_token_and_requires_auth_pre_hook_in_module_when_enabled()
        {
            // Given
            var module = new FakeModule();

            // When
            TokenAuthentication.Enable(module, this.config);

            // Then
            module.Before.PipelineDelegates.ShouldHaveCount(2);
        }
        public void Should_add_both_basic_and_requires_auth_pre_and_post_hooks_in_module_when_enabled()
        {
            // Given
            var module = new FakeModule();

            // When
            BasicAuthentication.Enable(module, this.config);
            
            // Then
            module.Before.PipelineDelegates.ShouldHaveCount(2);
            module.After.PipelineDelegates.ShouldHaveCount(1);
        }
Exemplo n.º 9
0
        public void Should_add_both_basic_and_requires_auth_pre_and_post_hooks_in_module_when_enabled()
        {
            var module = new FakeModule();

            BasicAuthentication.Enable(module, this.config);

            module.Before.PipelineItems.ShouldHaveCount(2);
        }