public void ValidateAllMethods() { var expectedMethods = new List <MethodArgs>() { { new MethodArgs(typeof(void), "LoadProduct", typeof(Product)) }, { new MethodArgs(typeof(Product), "Unload") }, }; var vehicleMethods = GetType("Vehicle").GetMethods(); foreach (var method in expectedMethods) { bool isNameValid = vehicleMethods.Any(x => x.Name == method.Name); Assert.That(isNameValid, "Method name is Invalid"); bool isReturnTypeValid = vehicleMethods.Any(x => x.ReturnType == method.ReturnType); Assert.That(isReturnTypeValid, "Method return type is invalid!"); MethodInfo currentActualMethod = vehicleMethods .FirstOrDefault(x => x.Name == method.Name); ParameterInfo[] currentActualMethodParams = currentActualMethod.GetParameters(); MethodArgs currentExpectedMethod = expectedMethods .FirstOrDefault(x => x.Name == method.Name && x.Parameters.Length == currentActualMethodParams.Length); foreach (var paramType in currentExpectedMethod.Parameters) { bool doesContain = currentActualMethodParams .Any(x => x.ParameterType == paramType); Assert.That(doesContain, Is.True, $"Method signature does not contain {paramType.Name} as parameter"); } } }
public async Task <T> PostAsync <T>(ServiceMethod serviceMethod, MethodArgs args = null, IDictionary <string, IEnumerable <Stream> > files = null) { var authData = _authDataRetriever.GetAuthData(); var endpoint = _apiEndpointFactory.GetEndpoint(serviceMethod); #region надо тестить! HttpContent content; if (files != null) { var dataContent = new MultipartFormDataContent { new FormUrlEncodedContent(args ?? new MethodArgs()) }; foreach (var filesPair in files) { var filesData = new MultipartContent(); filesPair.Value .ToList() .ForEach(stream => { var streamContent = new StreamContent(stream); streamContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data"); filesData.Add(streamContent); }); filesData.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data"); filesData.Headers.ContentType = MediaTypeHeaderValue.Parse("multipart/form-data"); dataContent.Add(filesData, filesPair.Key); } content = dataContent; } else { content = new FormUrlEncodedContent(args ?? new MethodArgs()); } #endregion var result = await endpoint.PostAsync( serviceMethod.MethodName, content, GetCookieFromAuthData(authData), _serviceUriBuilder ); if (!result.IsSuccessStatusCode) { throw new RequestFailedException( $"Attempt to load URL \"{result.RequestMessage.RequestUri}\" has failed.", result ); } return(JsonConvert.DeserializeObject <T>(await result.Content.ReadAsStringAsync())); }
public virtual void InvokeInterceptorsVoid(object[] args, object instance, string typeName, string methodName, string methodToken) { var methodArgs = new MethodArgs(typeName, methodName, args); var getNext = GetInterceptorChain(args, instance, typeName, methodName, methodToken); var first = getNext(); first.Execute(getNext, methodName, methodArgs, instance); }
public async Task <Stream> GetFileStreamByIdAsync(Guid id) { var args = new MethodArgs { { nameof(id), id.ToString() } }; return(await PostRequestAsync <Stream>(MethodNames.Files.GetFileById, args)); }
public async Task <IEnumerable <FileDto> > GetFilesByExtensionsAsync(IEnumerable <string> extensions) { var args = new MethodArgs { { nameof(extensions), extensions } }; return(await PostRequestAsync <IEnumerable <FileDto> >(MethodNames.Files.GetFilesByExtensions, args)); }
public async Task <bool> HasCurrentUserRightAsync(string rightAlias) { var args = new MethodArgs { { nameof(rightAlias), rightAlias } }; return(await GetRequestAsync <bool>(MethodNames.Users.HasCurrentUserRight, args)); }
public async Task <UserDto> GetByLoginAsync(string login) { var args = new MethodArgs { { nameof(login), login } }; return(await GetRequestAsync <UserDto>(MethodNames.Users.GetByLogin, args)); }
public void Should_return_arguments_as_object_array_without_touching_the_method_info() { var args = new object[] { 1, 2, 3 }; var methodArgs = new MethodArgs(string.Empty, string.Empty, args); var result = methodArgs.Arguments; Assert.Equal(args, result); }
public async Task <IEnumerable <GroupDto> > GetGroupsByTypeAsync(string groupTypeAlias) { var args = new MethodArgs { { nameof(groupTypeAlias), groupTypeAlias } }; return(await GetRequestAsync <IEnumerable <GroupDto> >(MethodNames.Groups.GetGroupsByType, args)); }
public async Task <bool> SetPerPageCountAsync(string count) { var args = new MethodArgs { { nameof(count), count } }; return(await PostRequestAsync <bool>(MethodNames.SiteSettings.SetPerPageCount, args)); }
public async Task <bool> SetDefaultNewsPageTitle(string title) { var args = new MethodArgs { { nameof(title), title } }; return(await PostRequestAsync <bool>(MethodNames.SiteSettings.SetDefaultNewsPageTitle, args)); }
public virtual T InvokeInterceptors <T>(object[] args, object instance, string typeName, string methodName, string methodToken) { var methodArgs = new MethodArgs(typeName, methodName, args); var getNext = GetInterceptorChain(args, instance, typeName, methodName, methodToken); var first = getNext(); var result = first.Execute <T>(getNext, methodName, methodArgs, instance); return(result); }
public async Task <bool> SetSiteName(string siteName) { var args = new MethodArgs { { nameof(siteName), siteName } }; return(await PostRequestAsync <bool>(MethodNames.SiteSettings.SetSiteName, args)); }
public async Task <PostTypeDto> GetByPostIdAsync(PostDto post) { var args = new MethodArgs { { "postId", post.Id.ToString() } }; return(await GetRequestAsync <PostTypeDto>(MethodNames.PostTypes.GetByPostId, args)); }
public async Task <int> GetPerPageCountAsync(int count = 18) { var args = new MethodArgs { { nameof(count), count.ToString() } }; return(await GetRequestAsync <int>(MethodNames.SiteSettings.GetPerPageCount, args)); }
protected async Task <TReturn> GetRequestAsync <TReturn>(string methodName, MethodArgs args = null) { var raiseOnFail = GetAndResetShouldRaiseException(); var response = await ApiRequester.GetAsync <ApiResponse <TReturn> >(GetMethod(methodName), args); return(raiseOnFail ? GetResponseOrFail(response) : GetResponseOrDefault(response)); }
public async Task <DirectoryDto> GetDirectoryWithPathAsync(string path) { var args = new MethodArgs { { nameof(path), path } }; return(await PostRequestAsync <DirectoryDto>(MethodNames.Directories.GetDirectoryWithPath, args)); }
public async Task <PostSeoSettingDto> GetByPostIdAsync(PostDto post)//TODO CHANGED { var args = new MethodArgs { { "postId", post.Id.ToString() } }; return(await GetRequestAsync <PostSeoSettingDto>(MethodNames.PostSeoSettings.GetByPostId, args)); }
public async Task <bool> SetTitleDelimiter(string delimiter) { var args = new MethodArgs { { nameof(delimiter), delimiter } }; return(await PostRequestAsync <bool>(MethodNames.SiteSettings.SetTitleDelimiter, args)); }
public async Task <bool> HasRightAsync(Guid userId, string rightAlias) { var args = new MethodArgs { { nameof(userId), userId.ToString() }, { nameof(rightAlias), rightAlias } }; return(await GetRequestAsync <bool>(MethodNames.Users.HasRight, args)); }
public async Task <bool> MoveAllAsync(DirectoryDto from, DirectoryDto to) { var args = new MethodArgs { { "from", from.Id.ToString() }, { "to", to.Id.ToString() }, }; return(await PostRequestAsync <bool>(MethodNames.Directories.MoveDirectories, args)); }
protected async Task PostRequestAsync(string methodName, MethodArgs args = null) { var raiseOnFail = GetAndResetShouldRaiseException(); var response = await ApiRequester.PostAsync <VoidApiResponse <string> >(GetMethod(methodName), args); if (raiseOnFail) { FailIfError(response); } }
public async Task <TokenDto> GetToken(string login, string password) { var args = new MethodArgs { { nameof(login), login }, { nameof(password), password } }; return(await PostRequestAsync <TokenDto>(MethodNames.Auth.GetToken, args)); }
protected async Task <TReturn> PostRequestAsync <TReturn>(string methodName, MethodArgs args = null, IDictionary <string, IEnumerable <Stream> > files = null) { var raiseOnFail = GetAndResetShouldRaiseException(); var response = await ApiRequester.PostAsync <ApiResponse <TReturn> >(GetMethod(methodName), args, files); return(raiseOnFail ? GetResponseOrFail(response) : GetResponseOrDefault(response)); }
public async Task <UserDto> GetByLoginAndPasswordAsync(string login, string password) { var args = new MethodArgs { { nameof(login), login }, { nameof(password), password } }; return(await PostRequestAsync <UserDto>(MethodNames.Users.GetByLoginAndPassword, args)); }
public async Task <PostDto> GetPostByUrlAndTypeAsync(string url, PostTypeDto postType) { var args = new MethodArgs { { nameof(url), url }, { "PostType.Id", postType.Id.ToString() }//TODO Canged Service }; return(await PostRequestAsync <PostDto>(MethodNames.Posts.GetPostByUrlAndType, args)); }
public void Execute(Func <IMethodInterceptor> getNext, string methodName, MethodArgs args, object instance) { try { _method.Invoke(instance, args.Arguments.ToArray()); } catch (TargetInvocationException ex) { throw ex.InnerException ?? ex; } }
public T Execute <T>(Func <IMethodInterceptor> getNext, string methodName, MethodArgs args, object instance) { string key = methodName + "_" + string.Join(",", args.Arguments.Select(a => a.ToString())); if (_cache[key] == null) { var result = getNext().Execute <T>(getNext, methodName, args, instance); _cache.Add(key, result, DateTimeOffset.Now.AddSeconds(3)); } return((T)_cache[key]); }
public void Should_return_list_of_argument_names_and_values_using_reflection() { var args = new object[] { 1, null }; var methodArgs = new MethodArgs(this.GetType().AssemblyQualifiedName, "TestMethod", args); var result = methodArgs.ArgumentPairs.ToList(); Assert.Equal(2, result.Count); Assert.Equal(new KeyValuePair <string, object>("foo", 1), result.First()); Assert.Equal(new KeyValuePair <string, object>("bar", null), result.Last()); }
protected override MethodArgs EntityToArgs(CategoryDto category, ActionType action) { var args = new MethodArgs { { nameof(category.Name), category.Name }, { nameof(category.Alias), category.Alias }, { nameof(category.Description), category.Description } }; if (action == ActionType.Create) { args.Add(nameof(category.Alias), category.Alias); } return(args); }
/* * Matches a method against its arguments in the Lua stack. Returns * if the match was succesful. It it was also returns the information * necessary to invoke the method. */ internal bool matchParameters(LuaCore.lua_State luaState, MethodBase method, ref MethodCache methodCache) { ExtractValue extractValue; bool isMethod = true; var paramInfo = method.GetParameters(); int currentLuaParam = 1; int nLuaParams = LuaLib.lua_gettop(luaState); var paramList = new ArrayList(); var outList = new List<int>(); var argTypes = new List<MethodArgs>(); foreach(var currentNetParam in paramInfo) { if(!currentNetParam.IsIn && currentNetParam.IsOut) // Skips out params outList.Add(paramList.Add(null)); else if(currentLuaParam > nLuaParams) // Adds optional parameters { if(currentNetParam.IsOptional) paramList.Add(currentNetParam.DefaultValue); else { isMethod = false; break; } } else if(_IsTypeCorrect(luaState, currentLuaParam, currentNetParam, out extractValue)) // Type checking { int index = paramList.Add(extractValue(luaState, currentLuaParam)); var methodArg = new MethodArgs(); methodArg.index = index; methodArg.extractValue = extractValue; argTypes.Add(methodArg); if(currentNetParam.ParameterType.IsByRef) outList.Add(index); currentLuaParam++; } // Type does not match, ignore if the parameter is optional else if(_IsParamsArray(luaState, currentLuaParam, currentNetParam, out extractValue)) { object luaParamValue = extractValue(luaState, currentLuaParam); var paramArrayType = currentNetParam.ParameterType.GetElementType(); Array paramArray; if(luaParamValue is LuaTable) { var table = (LuaTable)luaParamValue; var tableEnumerator = table.GetEnumerator(); paramArray = Array.CreateInstance(paramArrayType, table.Values.Count); tableEnumerator.Reset(); int paramArrayIndex = 0; while(tableEnumerator.MoveNext()) { paramArray.SetValue(Convert.ChangeType(tableEnumerator.Value, currentNetParam.ParameterType.GetElementType()), paramArrayIndex); paramArrayIndex++; } } else { paramArray = Array.CreateInstance(paramArrayType, 1); paramArray.SetValue(luaParamValue, 0); } int index = paramList.Add(paramArray); var methodArg = new MethodArgs(); methodArg.index = index; methodArg.extractValue = extractValue; methodArg.isParamsArray = true; methodArg.paramsArrayType = paramArrayType; argTypes.Add(methodArg); currentLuaParam++; } else if(currentNetParam.IsOptional) paramList.Add(currentNetParam.DefaultValue); else // No match { isMethod = false; break; } } if(currentLuaParam != nLuaParams + 1) // Number of parameters does not match isMethod = false; if(isMethod) { methodCache.args = paramList.ToArray(); methodCache.cachedMethod = method; methodCache.outList = outList.ToArray(); methodCache.argTypes = argTypes.ToArray(); } return isMethod; }