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); }
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); } } }
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); } } }
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); } } }
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." ); }
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."); }
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); } } }
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); }