public void checkSecurityMappings(Allowed_User allowedUser, List <SecurityMapping> securityMappings, Func <SecurityMapping, string, bool> getResult) { foreach (var securityMapping in securityMappings) { var targetMethod = securityMapping.MethodName.format(securityMapping.MethodParameters); var result = getResult(securityMapping, targetMethod); if (securityMapping.AllowedUser <= allowedUser) { Assert.IsTrue(result, "On method: '{0}' for user '{1}'".format(targetMethod, allowedUser)); } else { Assert.IsFalse(result, "On method: '{0}' for user '{1}'".format(targetMethod, allowedUser)); } } }
//helper methods public void checkSecurityMappings(Allowed_User allowedUser) { foreach (var securityMapping in SecurityMappings) { var targetMethod = WebServices_BaseType.method(securityMapping.MethodName); var methodParameters = securityMapping.MethodParameters; if (securityMapping.AllowedUser <= allowedUser) { Assert.DoesNotThrow(() => targetMethod.Invoke(webServices, methodParameters), "\n\n ************************\n\n On method: '{0}' for user '{1}' \n\n ************************\n\n".format(targetMethod, allowedUser)); } else { Assert.Throws <TargetInvocationException>(() => targetMethod.Invoke(webServices, methodParameters), "\n\n ************************\n\n On method: '{0}' for user '{1}' \n\n ************************\n\n".format(targetMethod, allowedUser)); } } }
//helper methods public void checkSecurityMappings(Allowed_User allowedUser, Func <Test_User> loginFunction) { Action loginUser = () => { if (loginFunction.notNull()) // we need to login before each invocation since there are GET and POST calls that reset the current user { Assert.NotNull(loginFunction.invoke().notNull()); } }; loginUser(); checkSecurityMappings(allowedUser, SecurityMappings_GET, getResult_GET); loginUser(); checkSecurityMappings(allowedUser, SecurityMappings_POST, getResult_POST); loginUser(); checkSecurityMappings(allowedUser, SecurityMappings_PUT, getResult_PUT); }
public void checkSecurityMappings(Allowed_User allowedUser, List<SecurityMapping> securityMappings, Func<SecurityMapping, string, bool> getResult) { foreach(var securityMapping in securityMappings) { var targetMethod = securityMapping.MethodName.format(securityMapping.MethodParameters); var result = getResult(securityMapping, targetMethod); if (securityMapping.AllowedUser <= allowedUser) { if(result.isFalse()) { //set breakpoint here } Assert.IsTrue(result , "On method: '{0}' for user '{1}'".format(targetMethod, allowedUser)); } else { if (result) { //set breakpoint here } Assert.IsFalse(result, "On method: '{0}' for user '{1}'".format(targetMethod, allowedUser)); } } }
//helper methods public void checkSecurityMappings(Allowed_User allowedUser, Func<Test_User> loginFunction) { Action loginUser = ()=> { if (loginFunction.notNull()) // we need to login before each invocation since there are GET and POST calls that reset the current user { Assert.NotNull(loginFunction.invoke().notNull()); } }; loginUser(); checkSecurityMappings(allowedUser, SecurityMappings_GET, getResult_GET); loginUser(); checkSecurityMappings(allowedUser, SecurityMappings_POST, getResult_POST); loginUser(); checkSecurityMappings(allowedUser, SecurityMappings_PUT, getResult_PUT); }
public static List <SecurityMapping> add_Mapping(this List <SecurityMapping> securityMappings, Allowed_User allowedUser, string methodName, object[] methodParameters) { securityMappings.Add(new SecurityMapping { MethodName = methodName, MethodParameters = methodParameters, AllowedUser = allowedUser }); return(securityMappings); }