Esempio n. 1
0
 private RequestMethod(string name, string mvcAttributeName, bool hasBody)
 {
     Name         = name;
     HasBody      = hasBody;
     TypeFilter   = new IsOfAnyTypeFilter(MvcConstants.ToAspNetCoreFullName(mvcAttributeName));
     ActionFilter = new ActionHasAttributeFilter(TypeFilter);
 }
        public void HttpPatchRoute_WithIdPlaceholder_IsAppended()
        {
            ControllerBuilder.AddAttribute(MvcConstants.RouteAttributeFullName_AspNetCore)
            .AddStringConstructorArg("api/[controller]").Commit();

            Action.AddAttribute(MvcConstants.ToAspNetCoreFullName(MvcConstants.HttpPatchAttributeName))
            .AddStringConstructorArg("{id}/dostuff").Commit();

            AssertRouteEquals("/api/Things/{id}/dostuff");
        }
Esempio n. 3
0
        /// <summary>
        /// Creates a new parse context
        /// </summary>
        /// <param name="comp">The compilation</param>
        /// <param name="documentationProvider">The doc provider</param>
        public ParseContext(Compilation comp, DocumentationProvider documentationProvider)
        {
            Compilation           = comp;
            DocumentationProvider = documentationProvider;

            // Task<T>
            _returnTypeHandlers.Add(new TaskReturnTypeHandler(this));

            // ActionResult<T>
            _returnTypeHandlers.Add(new ActionResultReturnTypeHandler(this));

            // ActionResult, IActionResult, JsonResult, ActionResult<object>, object
            _returnTypeHandlers.Add(new ParseSyntaxForTypeMethodHandler(
                                        MvcConstants.ToAspNetCoreFullName("JsonResult"),
                                        MvcConstants.ToAspNetCoreFullName("ActionResult"),
                                        MvcConstants.ToAspNetCoreFullName("ActionResult") + "`1",
                                        MvcConstants.ToAspNetCoreFullName("IActionResult"),
                                        typeof(object).FullName
                                        ));

            _returnTypeHandlers.Add(new DefaultMethodReturnTypeHandler());
        }
        public void RoutedApiController_ScriptWritten()
        {
            ControllerBuilder
            .AddAttribute(MvcConstants.RouteAttributeFullName_AspNetCore)
            .AddConstructorArg("\"api/RoutedApi\"")
            .Commit()
            .AddMethod("GetThing", "string")
            .AddScriptActionAttribute()
            .AddAttribute(MvcConstants.HttpGetAttributeFullName_AspNetCore)
            .AddConstructorArg("\"thing/{thingId}\"").Commit()
            .AddParameter("thingId", "string")
            .AddLineOfCode("return null", 0)
            .Commit()
            .AddMethod("PutThingWithQuery", "string")
            .AddScriptActionAttribute()
            .AddAttribute(MvcConstants.HttpPutAttributeFullName_AspNetCore)
            .AddConstructorArg("\"thing/{thingId}/put\"").Commit()
            .AddParameter("thingId", "string")
            .AddParameter("query", "string", attribute: MvcConstants.FromQueryAttributeFullName_AspNetCore)
            .AddParameter("body", "bool", attribute: MvcConstants.FromBodyAttributeFullName_AspNetCore)
            .AddLineOfCode("return null", 0)
            .Commit()
            .AddMethod("DeleteThing", "string")
            .AddScriptActionAttribute()
            .AddAttribute(MvcConstants.ToAspNetCoreFullName(MvcConstants.HttpDeleteAttributeName))
            .AddConstructorArg("\"thing/{thingId}\"").Commit()
            .AddParameter("thingId", "string")
            .AddLineOfCode("return null", 0)
            .Commit()
            ;
            string queryHelpers = new QueryParameterHelperFunctions(false).TransformText();

            AssertControllerGeneratedText(
                #region ScriptText
                @"
import { fetchWrapper } from ""../../FolderM/FolderN/FetchFile"";

" + queryHelpers + @"
/**
 * 
 * @param thingId 
 */
export function DeleteThing(thingId: string): void {
	fetchWrapper(""DELETE"", `/api/RoutedApi/thing/${thingId}`, null);
}

/**
 * 
 * @param thingId 
 */
export function GetThing(thingId: string): void {
	fetchWrapper(""GET"", `/api/RoutedApi/thing/${thingId}`, null);
}

/**
 * 
 * @param thingId 
 * @param query 
 * @param body 
 */
export function PutThingWithQuery(thingId: string, query: string, body: boolean): void {
	const urlParams = new URLSearchParams();
	tryAppendKeyValueToUrl(urlParams, ""query"", query);
	fetchWrapper(""PUT"", `/api/RoutedApi/thing/${thingId}/put${getQueryString(urlParams)}`, body);
}

"
                #endregion
                );
        }