public void FetchConfig_ImportIsWritten()
        {
            GivenFetchConfig(new FetchConfig()
            {
                FilePath   = TypeCollectionTester.FetchFilePath,
                Imports    = new List <ImportDefinition>(),
                Name       = "fetchWrapper",
                ReturnType = "void",
                Parameters = new List <ActionParameter>()
                {
                    ActionParameter.RequestMethod,
                    ActionParameter.Url,
                    ActionParameter.Body
                }
            });

            ControllerBuilder
            .AddMethod("QueryParameterWithBody", MvcConstants.JsonResult_AspNetCore)
            .AddScriptActionAttribute()
            .Commit()
            ;

            AssertImportsAre(@$ "
import {{ fetchWrapper }} from " "../../FolderM/FolderN/FetchFile" ";
");
        }
        public void StandardParams_ActionHasNoMethod_DefaultsGET()
        {
            ControllerBuilder
            .AddMethod("GetThing", "string")
            .AddScriptActionAttribute()
            .AddLineOfCode("return null", 0)
            .Commit()
            ;

            AssertScriptTextForFunctionIs(@"
export function GetThing(): void {
	fetchWrapper(""GET"", `/api/RoutedApi`, null);
}");
        }
Ejemplo n.º 3
0
        public void BaseRouteParameterOnly_IsFound_AddedToRoute()
        {
            ControllerBuilder
            .AddMethod("GetThing", "string")
            .AddScriptActionAttribute()
            .AddLineOfCode("return null", 0)
            .Commit()
            ;

            AssertScriptTextForFunctionIs(@"
export function GetThing(id: number): void {
	fetchWrapper(""GET"", `/api/things/${id}/action`, null);
}");
        }
        public void ImportFromServerObjects_AreWritten()
        {
            ControllerBuilder
            .AddMethod("QueryParameterWithBody", MvcConstants.JsonResult_AspNetCore)
            .AddScriptActionAttribute()
            .AddParameter("fromQuery", "string", attribute: MvcConstants.FromQueryAttributeFullName_AspNetCore)
            .AddParameter("fromBody", "TestClass", attribute: MvcConstants.FromBodyAttributeFullName_AspNetCore)
            .Commit()
            ;

            AssertImportsAre(@$ "
import * as DefaultResult from " "../../DefaultResult" ";
import {{ fetchWrapper }} from " "../../FolderM/FolderN/FetchFile" ";
");
        }
Ejemplo n.º 5
0
        public void BaseRouteParameterWithMethodSpecific_IsFound_AddedToRoute()
        {
            ControllerBuilder
            .AddMethod("GetThing", "string")
            .AddScriptActionAttribute()
            .AddAttribute(MvcConstants.HttpGetAttributeFullName_AspNetCore)
            .AddStringConstructorArg("sub/{other}/route")
            .Commit()
            .AddLineOfCode("return null", 0)
            .Commit()
            ;

            AssertScriptTextForFunctionIs(@"
export function GetThing(id: number, other: string): void {
	fetchWrapper(""GET"", `/api/things/${id}/action/sub/${other}/route`, null);
}");
        }
        public void ActionComments_FromServicesParameter_ParameterIsNotWritten()
        {
            ControllerBuilder
            .AddMethod("QueryParameterWithBody", MvcConstants.JsonResult_AspNetCore)
            .AddScriptActionAttribute()
            .AddParameter("fromQuery", "string", attribute: MvcConstants.FromQueryAttributeFullName_AspNetCore)
            .AddParameter("fromServices", "TestClass", attribute: MvcConstants.FromServicesAttributeFullName_AspNetCore)
            .Commit()
            ;

            AssertCommentsAre(@$ "
/**
 * 
 * @param fromQuery 
 */
");
        }
        public void StandardParams_BasicGetRequest_ScriptIsWritten()
        {
            ControllerBuilder
            .AddMethod("GetThing", "string")
            .AddScriptActionAttribute()
            .AddAttribute(MvcConstants.HttpGetAttributeFullName_AspNetCore)
            .AddConstructorArg("\"thing/{thingId}\"").Commit()
            .AddParameter("thingId", "string")
            .AddLineOfCode("return null", 0)
            .Commit()
            ;

            AssertScriptTextForFunctionIs(
                @"
export function GetThing(thingId: string): void {
	fetchWrapper(""GET"", `/api/RoutedApi/thing/${thingId}`, null);
}");
        }
        public void StandardParams_GetRequestWithQuery_ScriptIsWritten()
        {
            ControllerBuilder
            .AddMethod("GetThing", "string")
            .AddScriptActionAttribute()
            .AddAttribute(MvcConstants.HttpGetAttributeFullName_AspNetCore)
            .AddConstructorArg("\"thing/{thingId}\"").Commit()
            .AddParameter("thingId", "string")
            .AddParameter("queryP", "string", attribute: MvcConstants.FromQueryAttributeFullName_AspNetCore)
            .AddLineOfCode("return null", 0)
            .Commit()
            ;

            AssertScriptTextForFunctionIs(@"
export function GetThing(thingId: string, queryP: string): void {
	const urlParams = new URLSearchParams();
	tryAppendKeyValueToUrl(urlParams, ""queryP"", queryP);
	fetchWrapper(""GET"", `/api/RoutedApi/thing/${thingId}${getQueryString(urlParams)}`, null);
}", ScriptExtensions.KeyValueQueryParamHelper);
        }