Package | NuGet Stable | Downloads |
---|---|---|
Route.Generator |
PM> Install-Package Route.Generator
Insert code services.AddRouteAnalyzer();
and required using
directive into Startup.cs as follows.
using Route.Generator; // Add
....
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddRouteAnalyzer(); // Add
}
....
Eg. input http://localhost:27634/routes.html
Eg. input http://localhost:27634/routes, the address is used to generate async methods,
please make it accessible.
If you want more powerful features, you can install Route.Generator.CLI to Generate Routes Generated Files
PM> Install-Package Route.Generator.CLI
PM> routegen gen -p <Your project name> -u <The base address>
Eg. routegen gen -p Api -u http://localhost:27634/
command | description |
---|---|
-p | Your project name |
-u | The base address |
-o | The out put file name. default name is Routes.Generated.cs. |
-g | Whether generate async method or not, 1 or true meanings will generate, otherwise will not. |
- Http Delete Unit Test
- Http Get Unit Test
- Http Patch Unit Test
- Http Post Unit Test
- Http Put Unit Test
- Route Generator Unit Test
- [Get]
- [Post]
- [Delete]
- [Post]
- [Put]
[Route("api/[controller]/[action]")]
[ApiController]
public class ExampleController : StandardController
{
[HttpGet("{key}")]
public Dictionary<string, string> GetVlues(string key, string value)
{
return this.ResponseDictionary(key, value, nameof(this.GetVlues));
}
[HttpPost]
public Dictionary<string, string> Edit(PointModel model)
{
return this.ResponseDictionary(null, null, nameof(this.Edit));
}
[HttpDelete]
public Dictionary<string, string> Delete(string id)
{
return this.ResponseDictionary(null, null, nameof(this.Delete));
}
}
/// <summary>
/// <see cref="Controllers.ExampleController"/>
/// </summary>
public class ExampleRoute
{
/// <summary>
/// <see cref="Controllers.ExampleController.GetVlues"/>
/// </summary>
public const string GetVlues = "/api/Example/GetVlues/{key}";
public static async Task<T> GetVluesAsync<T>(string key, string value)
{
var routeInfo = new RouteInfo
{
HttpMethods = "GET",
Path = GetVlues,
Parameters = new List<ParameterInfo>
{
new ParameterInfo() {Name = "key", Type = "string"},
new ParameterInfo() {Name = "value", Type = "string"},
}
};
return await HttpClientAsync.Async<T>(routeInfo, key, value);
}
/// <summary>
/// <see cref="Controllers.ExampleController.Edit"/>
/// </summary>
public const string Edit = "/api/Example/Edit";
public static async Task<T> EditAsync<T>(Api.Models.PointModel model)
{
var routeInfo = new RouteInfo
{
HttpMethods = "POST",
Path = Edit,
Parameters = new List<ParameterInfo>
{
new ParameterInfo() {Name = "model", Type = "Api.Models.PointModel"},
}
};
return await HttpClientAsync.Async<T>(routeInfo, model);
}
/// <summary>
/// <see cref="Controllers.ExampleController.Delete"/>
/// </summary>
public const string Delete = "/api/Example/Delete";
public static async Task<T> DeleteAsync<T>(string id)
{
var routeInfo = new RouteInfo
{
HttpMethods = "DELETE",
Path = Delete,
Parameters = new List<ParameterInfo>
{
new ParameterInfo() {Name = "id", Type = "string"},
}
};
return await HttpClientAsync.Async<T>(routeInfo, id);
}
}
/// <summary>
/// <see cref="Controllers.HomeController"/>
/// </summary>
public class HomeRoute
{
/// <summary>
/// <see cref="Controllers.HomeController.Index"/>
/// </summary>
public const string Index = "/Admin/Home/Index";
/// <summary>
/// <see cref="Controllers.HomeController.About"/>
/// </summary>
public const string About = "/Admin/Home/About";
/// <summary>
/// <see cref="Controllers.HomeController.Contact"/>
/// </summary>
public const string Contact = "/Admin/Home/Contact";
/// <summary>
/// <see cref="Controllers.HomeController.Privacy"/>
/// </summary>
public const string Privacy = "/Admin/Home/Privacy";
/// <summary>
/// <see cref="Controllers.HomeController.Error"/>
/// </summary>
public const string Error = "/Admin/Home/Error";
}