Testing: Postman and Swagger As Additions to Your Tests

Often I need to queue up some unit tests on-the-fly. I recently came across the following helpers:

1.  CREATE POSTMAN API TESTS FROM
SWAGGER

In case anyone else did not know, it is now an option to take the swagger document from your WebAPI, import it into Postman and, voila, test cases for controllers created.   

1.      Create swagger.json from API
2.      Open Postman
3.      Navigate to “Import” button

4.      Open swagger.json file (or paste, etc)

2.  RUN POSTMAN TESTS FROM VISUAL STUDIO

Postman Runner for VSCode allows you to run Postman tests from your VSCode. It analyze the workspace folder and locate collection and environment files.
  • Export your Postman collections and environments in a folder (or subfolders) and open it with VSCode.
  • Open the Command Palette
  • Choose Postman: Run > Question Mode ( Ctrl+Q , Cmd+R )


https://marketplace.visualstudio.com/items?itemName=eridem.vscode-postman



.NET : Adding custom ASP.NET WebApi Help Page

1.  Add annotations to model, controller, etc. using System.ComponentModel.DataAnnotations
2.  Navigate to project “Properties” –> “Build” –> Output
3.  Check “XML Documentation file:”, then type in a name for the help document xml, and save
4.  In the solution, navigate to “Areas” –> “App_Start” –> “HelpPageConfig.cs”
5.  Uncomment the “config.SetDocumentationProvider…” line, add your created name for the help document xml, and save:
config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath(“~/App_Data/DevOpsTaskHelp.XML”)));
6.  Build solution, navigate to help page “API”, and your annotations should be present.

Adding XML WebApi Comments To Swagger:
1.  Install-Package “Swashbuckle”
2.  Open the “SwaggerConfig.cs” file and uncomment the following line:
c.IncludeXmlComments(GetXmlCommentsPath());
3.  Generate method for “GetXmlCommentsPath()”
private static string GetXmlCommentsPath()
        {
            return System.String.Format(@”{0}binDevOpsTaskHelp.XML”, System.AppDomain.CurrentDomain.BaseDirectory);
        }

REFERENCE(S):
https://docs.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/creating-api-help-pages
https://blogs.msdn.microsoft.com/yaohuang1/2012/09/30/asp-net-web-api-help-page-part-1-basic-help-page-customizations/