コード例 #1
0
        public void SupportedResponseFormatters_ReturnsFormattersWithoutTracers_WithTracing()
        {
            // Arrange
            HttpConfiguration config = new HttpConfiguration();

            config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = RouteParameter.Optional });
            ItemFormatter customFormatter = new ItemFormatter();

            config.Formatters.Add(customFormatter);
            ITraceWriter testTraceWriter = new Mock <ITraceWriter>().Object;

            config.Services.Replace(typeof(ITraceWriter), testTraceWriter);
            config.Initializer.Invoke(config);
            int expectedFormatterCount = config.Formatters.Count - 2;
            DefaultHttpControllerSelector controllerSelector = ApiExplorerHelper.GetStrictControllerSelector(config, typeof(ItemController));

            config.Services.Replace(typeof(IHttpControllerSelector), controllerSelector);
            IApiExplorer explorer = config.Services.GetApiExplorer();

            // Act
            ApiDescription description = explorer.ApiDescriptions.FirstOrDefault(desc => desc.ActionDescriptor.ActionName == "PostItem");
            Collection <MediaTypeFormatter> formatters = description.SupportedResponseFormatters;

            // Assert
            Assert.False(formatters.Any(f => f is IFormatterTracer), "Tracers are present");
            Assert.Equal(expectedFormatterCount, formatters.Count);
        }
コード例 #2
0
        public void VerifyDefaultDocumentationMessage()
        {
            HttpConfiguration config = new HttpConfiguration();

            config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = RouteParameter.Optional });
            ItemFormatter customFormatter = new ItemFormatter();

            config.Formatters.Add(customFormatter);

            DefaultHttpControllerFactory controllerFactory = ApiExplorerHelper.GetStrictControllerFactory(config, typeof(ItemController));

            config.ServiceResolver.SetService(typeof(IHttpControllerFactory), controllerFactory);

            IApiExplorer explorer = config.ServiceResolver.GetApiExplorer();

            foreach (ApiDescription description in explorer.ApiDescriptions)
            {
                Assert.Equal(
                    String.Format(SRResources.ApiExplorer_DefaultDocumentation, description.ActionDescriptor.ActionName),
                    description.Documentation);
                foreach (ApiParameterDescription param in description.ParameterDescriptions)
                {
                    Assert.Equal(
                        String.Format(SRResources.ApiExplorer_DefaultDocumentation, param.Name),
                        param.Documentation);
                }
            }
        }
コード例 #3
0
        public void VerifyCustomDocumentationProviderMessage()
        {
            HttpConfiguration config = new HttpConfiguration();

            config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = RouteParameter.Optional });
            ItemFormatter customFormatter = new ItemFormatter();

            config.Formatters.Add(customFormatter);

            DefaultHttpControllerSelector controllerSelector = ApiExplorerHelper.GetStrictControllerSelector(config, typeof(DocumentationController));

            config.Services.Replace(typeof(IHttpControllerSelector), controllerSelector);

            AttributeDocumentationProvider documentationProvider = new AttributeDocumentationProvider();

            config.Services.Replace(typeof(IDocumentationProvider), documentationProvider);

            IApiExplorer explorer = config.Services.GetApiExplorer();

            foreach (ApiDescription description in explorer.ApiDescriptions)
            {
                Assert.Equal(
                    String.Format("{0} action", description.ActionDescriptor.ActionName),
                    description.Documentation);
                foreach (ApiParameterDescription param in description.ParameterDescriptions)
                {
                    Assert.Equal(
                        String.Format("{0} parameter", param.Name),
                        param.Documentation);
                }
            }
        }
コード例 #4
0
        public void VerifyCustomDocumentationProviderMessage()
        {
            HttpConfiguration config = new HttpConfiguration();
            config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = RouteParameter.Optional });
            ItemFormatter customFormatter = new ItemFormatter();
            config.Formatters.Add(customFormatter);

            DefaultHttpControllerSelector controllerSelector = ApiExplorerHelper.GetStrictControllerSelector(config, typeof(DocumentationController));
            config.Services.Replace(typeof(IHttpControllerSelector), controllerSelector);

            AttributeDocumentationProvider documentationProvider = new AttributeDocumentationProvider();
            config.Services.Replace(typeof(IDocumentationProvider), documentationProvider);

            IApiExplorer explorer = config.Services.GetApiExplorer();
            foreach (ApiDescription description in explorer.ApiDescriptions)
            {
                Assert.Equal(
                    String.Format("{0} action", description.ActionDescriptor.ActionName),
                    description.Documentation);
                foreach (ApiParameterDescription param in description.ParameterDescriptions)
                {
                    Assert.Equal(
                        String.Format("{0} parameter", param.Name),
                        param.Documentation);
                }
            }
        }
コード例 #5
0
        public void VerifyDefaultDocumentationMessage()
        {
            HttpConfiguration config = new HttpConfiguration();

            config.Routes.MapHttpRoute(
                "Default",
                "{controller}/{id}",
                new { id = RouteParameter.Optional }
                );
            ItemFormatter customFormatter = new ItemFormatter();

            config.Formatters.Add(customFormatter);

            DefaultHttpControllerSelector controllerSelector =
                ApiExplorerHelper.GetStrictControllerSelector(config, typeof(ItemController));

            config.Services.Replace(typeof(IHttpControllerSelector), controllerSelector);

            IApiExplorer explorer = config.Services.GetApiExplorer();

            foreach (ApiDescription description in explorer.ApiDescriptions)
            {
                Assert.Null(description.Documentation);
                foreach (ApiParameterDescription param in description.ParameterDescriptions)
                {
                    Assert.Null(param.Documentation);
                }
            }
        }
コード例 #6
0
        public void CustomResponseFormatters_ShowUpOnDescription()
        {
            HttpConfiguration config = new HttpConfiguration();

            config.Routes.MapHttpRoute(
                "Default",
                "{controller}/{id}",
                new { id = RouteParameter.Optional }
                );
            ItemFormatter customFormatter = new ItemFormatter();

            config.Formatters.Add(customFormatter);

            DefaultHttpControllerSelector controllerSelector =
                ApiExplorerHelper.GetStrictControllerSelector(config, typeof(ItemController));

            config.Services.Replace(typeof(IHttpControllerSelector), controllerSelector);

            IApiExplorer   explorer    = config.Services.GetApiExplorer();
            ApiDescription description = explorer.ApiDescriptions.FirstOrDefault(
                desc => desc.ActionDescriptor.ActionName == "PostItem"
                );

            Assert.True(
                description.SupportedResponseFormatters.Any(
                    formatter => formatter == customFormatter
                    ),
                "Did not find the custom formatter on the SupportedResponseFormatters."
                );
        }
コード例 #7
0
        public void CustomResponseFormatters_ShowUpOnDescription()
        {
            HttpConfiguration config = new HttpConfiguration();
            config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = RouteParameter.Optional });
            ItemFormatter customFormatter = new ItemFormatter();
            config.Formatters.Add(customFormatter);

            DefaultHttpControllerSelector controllerSelector = ApiExplorerHelper.GetStrictControllerSelector(config, typeof(ItemController));
            config.Services.Replace(typeof(IHttpControllerSelector), controllerSelector);

            IApiExplorer explorer = config.Services.GetApiExplorer();
            ApiDescription description = explorer.ApiDescriptions.FirstOrDefault(desc => desc.ActionDescriptor.ActionName == "PostItem");
            Assert.True(description.SupportedResponseFormatters.Any(formatter => formatter == customFormatter), "Did not find the custom formatter on the SupportedResponseFormatters.");
        }
コード例 #8
0
        public void VerifyDefaultDocumentationMessage()
        {
            HttpConfiguration config = new HttpConfiguration();
            config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = RouteParameter.Optional });
            ItemFormatter customFormatter = new ItemFormatter();
            config.Formatters.Add(customFormatter);

            DefaultHttpControllerSelector controllerSelector = ApiExplorerHelper.GetStrictControllerSelector(config, typeof(ItemController));
            config.Services.Replace(typeof(IHttpControllerSelector), controllerSelector);

            IApiExplorer explorer = config.Services.GetApiExplorer();
            foreach (ApiDescription description in explorer.ApiDescriptions)
            {
                Assert.Null(description.Documentation);
                foreach (ApiParameterDescription param in description.ParameterDescriptions)
                {
                    Assert.Null(param.Documentation);
                }
            }
        }
コード例 #9
0
        public void SupportedResponseFormatters_ReturnsFormattersWithoutTracers_WithNoTracing()
        {
            // Arrange
            HttpConfiguration config = new HttpConfiguration();
            config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = RouteParameter.Optional });
            ItemFormatter customFormatter = new ItemFormatter();
            config.Formatters.Add(customFormatter);
            config.Initializer.Invoke(config);
            int expectedFormatterCount = config.Formatters.Count - 2;
            DefaultHttpControllerSelector controllerSelector = ApiExplorerHelper.GetStrictControllerSelector(config, typeof(ItemController));
            config.Services.Replace(typeof(IHttpControllerSelector), controllerSelector);
            IApiExplorer explorer = config.Services.GetApiExplorer();

            // Act 
            ApiDescription description = explorer.ApiDescriptions.FirstOrDefault(desc => desc.ActionDescriptor.ActionName == "PostItem");
            Collection<MediaTypeFormatter> formatters = description.SupportedResponseFormatters;

            // Assert
            Assert.False(formatters.Any(f => f is IFormatterTracer), "Tracers are present");
            Assert.Equal(expectedFormatterCount, formatters.Count);
        }
コード例 #10
0
        public void VerifyDefaultDocumentationMessage()
        {
            HttpConfiguration config = new HttpConfiguration();
            config.Routes.MapHttpRoute("Default", "{controller}/{id}", new { id = RouteParameter.Optional });
            ItemFormatter customFormatter = new ItemFormatter();
            config.Formatters.Add(customFormatter);

            DefaultHttpControllerFactory controllerFactory = ApiExplorerHelper.GetStrictControllerFactory(config, typeof(ItemController));
            config.ServiceResolver.SetService(typeof(IHttpControllerFactory), controllerFactory);

            IApiExplorer explorer = config.ServiceResolver.GetApiExplorer();
            foreach (ApiDescription description in explorer.ApiDescriptions)
            {
                Assert.Equal(
                    String.Format(SRResources.ApiExplorer_DefaultDocumentation, description.ActionDescriptor.ActionName),
                    description.Documentation);
                foreach (ApiParameterDescription param in description.ParameterDescriptions)
                {
                    Assert.Equal(
                        String.Format(SRResources.ApiExplorer_DefaultDocumentation, param.Name),
                        param.Documentation);
                }
            }
        }