Permalink
Browse files

better calls to OnActionExecuting

  • Loading branch information...
1 parent 9a52aec commit 662081bf217dcb486b6338da7a008300a58b478c @vurt007 vurt007 committed Apr 23, 2012
View
@@ -20,4 +20,5 @@ src/packages
src/Snooze.Package.Solution/packages
src/Snooze.Testing.Package.Solution/packages
/src/Snooze.sln.DotSettings.user
-/srcpackages
+/srcpackages
+/src/Snooze.Testing/Castle.Windsor.dll
@@ -1,9 +0,0 @@
-<ProjectConfiguration>
- <CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
- <RunPreBuildEvents>false</RunPreBuildEvents>
- <RunPostBuildEvents>false</RunPostBuildEvents>
- <PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
- <InstrumentAssembly>true</InstrumentAssembly>
- <DefaultTestTimeout>60000</DefaultTestTimeout>
- <UseBuildConfiguration />
-</ProjectConfiguration>
@@ -131,14 +131,14 @@
<Content Include="Content\themes\base\jquery-ui.css" />
</ItemGroup>
<ItemGroup>
+ <None Include="Views\Home\Home.spark" />
+ </ItemGroup>
+ <ItemGroup>
<ProjectReference Include="..\Snooze\Snooze.csproj">
<Project>{290C5812-2A16-4BA3-9A40-0DF6E0E63288}</Project>
<Name>Snooze</Name>
</ProjectReference>
</ItemGroup>
- <ItemGroup>
- <None Include="Views\Home\Home.spark" />
- </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
@@ -1,19 +1,16 @@
<ProjectConfiguration>
<CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
+ <ConsiderInconclusiveTestsAsPassing>false</ConsiderInconclusiveTestsAsPassing>
<IgnoreThisComponentCompletely>false</IgnoreThisComponentCompletely>
<RunPreBuildEvents>false</RunPreBuildEvents>
<RunPostBuildEvents>false</RunPostBuildEvents>
<PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
<InstrumentAssembly>true</InstrumentAssembly>
+ <PreventSigningOfAssembly>false</PreventSigningOfAssembly>
<AnalyseExecutionTimes>true</AnalyseExecutionTimes>
<IncludeStaticReferencesInWorkspace>true</IncludeStaticReferencesInWorkspace>
<DefaultTestTimeout>60000</DefaultTestTimeout>
- <UseBuildConfiguration></UseBuildConfiguration>
+ <UseBuildConfiguration />
<ProxyProcessPath />
<UseCPUArchitecture>AutoDetect</UseCPUArchitecture>
- <IgnoredTests>
- <RegexTestSelector>
- <RegularExpression>.*</RegularExpression>
- </RegexTestSelector>
- </IgnoredTests>
</ProjectConfiguration>
@@ -1,9 +0,0 @@
-<ProjectConfiguration>
- <CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
- <RunPreBuildEvents>false</RunPreBuildEvents>
- <RunPostBuildEvents>false</RunPostBuildEvents>
- <PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
- <InstrumentAssembly>true</InstrumentAssembly>
- <DefaultTestTimeout>60000</DefaultTestTimeout>
- <UseBuildConfiguration />
-</ProjectConfiguration>
@@ -0,0 +1,2 @@
+*.dll
+*.xml
Binary file not shown.
View
Binary file not shown.
@@ -95,34 +95,47 @@ public static FakeCachePolicy cachepolicy
public static void has_etag(string etag) { cachepolicy.Etag.ShouldEqual(etag); }
- static void InvokeAction(string httpMethod,
- RouteData route,
- object[] additionalParameters,
- NameValueCollection queryString)
+ static void InvokeAction(string httpMethod, RouteData route, object[] additionalParameters, NameValueCollection queryString)
{
var urlType = route.Route.GetType().GetGenericArguments()[0];
var methods =
- from m in typeof (THandler).GetMethods()
+ (from m in typeof (THandler).GetMethods()
where m.Name.Equals(httpMethod, StringComparison.OrdinalIgnoreCase)
let parameters = m.GetParameters()
where parameters.Length > 0
- && parameters[0].ParameterType.Equals(route.Route.GetType().GetGenericArguments()[0])
- select m;
+ && parameters[0].ParameterType == route.Route.GetType().GetGenericArguments()[0]
+ select m).ToList();
autoMocker.ClassUnderTest.HttpVerb = (SnoozeHttpVerbs)Enum.Parse(typeof(SnoozeHttpVerbs), httpMethod, true);
- if (methods.Count() == 0)
+ if (methods.Count==0)
throw new InvalidOperationException("No action for uri " + urlType.Name + " method " + httpMethod);
- var actionDict = new Dictionary<string, object>();
+ var methodParams = methods[0].GetParameters();
+ var hasMultipleParams = methodParams.Length > 1;
+
+ var command = additionalParameters.Any() ? CreateCommandFromAdditionalParameters(route, additionalParameters, queryString) : CreateCommandFromUri(route, queryString);
+
+
+ var actionDict = new Dictionary<string, object>();
+
+ if(command!=null)
+ {
+ var name = methodParams.Length > 0 ? methodParams[0].Name : "Command";
+ actionDict.Add(name,command);
+ }
+
+ if (additionalParameters.Length > 1)
+ {
+ for (var i = 1; i < additionalParameters.Length; i++)
+ {
+ actionDict[methodParams[i].Name] = additionalParameters[i];
+ }
+ }
- for(var i = 0;i != additionalParameters.Length; i++)
- {
- actionDict[methods.First().GetParameters()[i].Name] = additionalParameters[i];
- }
- var filterContext = CallActionExecuting(httpMethod, actionDict, methods);
+ var filterContext = CallActionExecuting(httpMethod, actionDict, methods);
if (filterContext.Result != null)
@@ -131,23 +144,18 @@ where m.Name.Equals(httpMethod, StringComparison.OrdinalIgnoreCase)
return;
}
- if (methods.First().GetParameters().Count() > 1)
- {
- InvokeUrlAndModel(route, additionalParameters, queryString, methods);
- }
+ if (hasMultipleParams)
+ InvokeUrlAndModel(route, additionalParameters, queryString, methods);
else
- {
- InvokeCommand(route, additionalParameters, queryString, methods);
- }
+ InvokeCommand(command, methods);
+
}
static ActionExecutingContext CallActionExecuting(string httpMethod, Dictionary<string, object> actionDict, IEnumerable<MethodInfo> methods)
{
- var executingContext = new ActionExecutingContext(ControllerContext(),
- new ReflectedActionDescriptor(methods.First(), httpMethod, new ReflectedControllerDescriptor(typeof(THandler))),
- actionDict
- );
+ var executingContext = new ActionExecutingContext(ControllerContext(),
+ new ReflectedActionDescriptor(methods.First(), httpMethod, new ReflectedControllerDescriptor(typeof(THandler))), actionDict);
typeof(THandler).InvokeMember("OnActionExecuting",
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod,
@@ -159,23 +167,12 @@ static ActionExecutingContext CallActionExecuting(string httpMethod, Dictionary<
}
- static void InvokeCommand(
- RouteData route, object[] additionalParameters,
- NameValueCollection queryString,
- IEnumerable<MethodInfo> methods)
+ static void InvokeCommand(object command, IEnumerable<MethodInfo> methods)
{
-
- object command;
-
- if (additionalParameters.Any())
- command = CreateCommandFromAdditionalParameters(route, additionalParameters, queryString);
- else
- command = CreateCommandFromUri(route, queryString);
var args = new List<object>(new[] {command});
- result = (ResourceResult) methods.First().Invoke(autoMocker.ClassUnderTest,
- args.ToArray());
+ result = (ResourceResult) methods.First().Invoke(autoMocker.ClassUnderTest, args.ToArray());
}
static object CreateCommandFromUri(RouteData route, NameValueCollection queryString)
@@ -196,15 +193,12 @@ static object CreateCommandFromUri(RouteData route, NameValueCollection queryStr
return command;
}
- static void InvokeUrlAndModel(RouteData route, object[] additionalParameters,
- NameValueCollection queryString,
- IEnumerable<MethodInfo> methods)
+ static void InvokeUrlAndModel(RouteData route, object[] additionalParameters, NameValueCollection queryString, IEnumerable<MethodInfo> methods)
{
var args = new List<object>(new[] {FromContext(route, queryString)});
args.AddRange(additionalParameters);
- result = (ResourceResult) methods.First().Invoke(autoMocker.ClassUnderTest,
- args.ToArray());
+ result = (ResourceResult) methods.First().Invoke(autoMocker.ClassUnderTest, args.ToArray());
}
protected static Url FromContext(RouteData data, NameValueCollection queryString)
@@ -100,89 +100,93 @@ public static FakeCachePolicy cachepolicy
public static void has_etag(string etag) { cachepolicy.Etag.ShouldEqual(etag); }
- static void InvokeAction(string httpMethod,
- RouteData route,
- object[] additionalParameters,
- NameValueCollection queryString)
+ static void InvokeAction(string httpMethod, RouteData route, object[] additionalParameters, NameValueCollection queryString)
{
var urlType = route.Route.GetType().GetGenericArguments()[0];
var methods =
- from m in typeof(THandler).GetMethods()
- where m.Name.Equals(httpMethod, StringComparison.OrdinalIgnoreCase)
- let parameters = m.GetParameters()
- where parameters.Length > 0
- && parameters[0].ParameterType.Equals(route.Route.GetType().GetGenericArguments()[0])
- select m;
+ (from m in typeof(THandler).GetMethods()
+ where m.Name.Equals(httpMethod, StringComparison.OrdinalIgnoreCase)
+ let parameters = m.GetParameters()
+ where parameters.Length > 0
+ && parameters[0].ParameterType == route.Route.GetType().GetGenericArguments()[0]
+ select m).ToList();
autoMocker.ClassUnderTest.HttpVerb = (SnoozeHttpVerbs)Enum.Parse(typeof(SnoozeHttpVerbs), httpMethod, true);
- if (methods.Count() == 0)
+ if (methods.Count == 0)
throw new InvalidOperationException("No action for uri " + urlType.Name + " method " + httpMethod);
+ var methodParams = methods[0].GetParameters();
+ var hasMultipleParams = methodParams.Length > 1;
+
+ var command = additionalParameters.Any() ? CreateCommandFromAdditionalParameters(route, additionalParameters, queryString) : CreateCommandFromUri(route, queryString);
+
+
var actionDict = new Dictionary<string, object>();
- for (var i = 0; i != additionalParameters.Length; i++)
+ if (command != null)
{
- actionDict[methods.First().GetParameters()[i].Name] = additionalParameters[i];
+ var name = methodParams.Length > 0 ? methodParams[0].Name : "Command";
+ actionDict.Add(name, command);
}
- CallActionExecuting(httpMethod, actionDict, methods);
-
- if (methods.First().GetParameters().Count() > 1)
+ if (additionalParameters.Length > 1)
{
- InvokeUrlAndModel(route, additionalParameters, queryString, methods);
+ for (var i = 1; i < additionalParameters.Length; i++)
+ {
+ actionDict[methodParams[i].Name] = additionalParameters[i];
+ }
}
- else
+
+
+ var filterContext = CallActionExecuting(httpMethod, actionDict, methods);
+
+
+ if (filterContext.Result != null)
{
- InvokeCommand(route, additionalParameters, queryString, methods);
+ result = filterContext.Result as ResourceResult;
+ return;
}
+
+ if (hasMultipleParams)
+ InvokeUrlAndModel(route, additionalParameters, queryString, methods);
+ else
+ InvokeCommand(command, methods);
+
}
- static void CallActionExecuting(string httpMethod, Dictionary<string, object> actionDict, IEnumerable<MethodInfo> methods)
+ static ActionExecutingContext CallActionExecuting(string httpMethod, Dictionary<string, object> actionDict, IEnumerable<MethodInfo> methods)
{
var executingContext = new ActionExecutingContext(ControllerContext(),
- new ReflectedActionDescriptor(methods.First(), httpMethod, new ReflectedControllerDescriptor(typeof(THandler))),
- actionDict
- );
+ new ReflectedActionDescriptor(methods.First(), httpMethod, new ReflectedControllerDescriptor(typeof(THandler))), actionDict);
typeof(THandler).InvokeMember("OnActionExecuting",
BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.InvokeMethod,
null,
class_under_test,
new[] { executingContext });
+
+ return executingContext;
}
- static void InvokeCommand(
- RouteData route, object[] additionalParameters,
- NameValueCollection queryString,
- IEnumerable<MethodInfo> methods)
+ static void InvokeCommand(object command, IEnumerable<MethodInfo> methods)
{
- object command;
-
- if (additionalParameters.Any())
- command = CreateCommandFromAdditionalParameters(route, additionalParameters, queryString);
- else
- command = CreateCommandFromUri(route, additionalParameters, queryString);
-
var args = new List<object>(new[] { command });
- result = (ResourceResult)methods.First().Invoke(autoMocker.ClassUnderTest,
- args.ToArray());
+ result = (ResourceResult)methods.First().Invoke(autoMocker.ClassUnderTest, args.ToArray());
}
- static object CreateCommandFromUri(RouteData route, object[] additionalParameters, NameValueCollection queryString)
+ static object CreateCommandFromUri(RouteData route, NameValueCollection queryString)
{
object command;
command = FromContext(route, queryString);
return command;
}
- static object CreateCommandFromAdditionalParameters(RouteData route,
- object[] additionalParameters,
- NameValueCollection queryString)
+ static object CreateCommandFromAdditionalParameters(RouteData route, object[] additionalParameters, NameValueCollection queryString)
{
object command;
command = additionalParameters.First();
@@ -1,9 +0,0 @@
-<ProjectConfiguration>
- <CopyReferencedAssembliesToWorkspace>false</CopyReferencedAssembliesToWorkspace>
- <RunPreBuildEvents>false</RunPreBuildEvents>
- <RunPostBuildEvents>false</RunPostBuildEvents>
- <PreviouslyBuiltSuccessfully>true</PreviouslyBuiltSuccessfully>
- <InstrumentAssembly>true</InstrumentAssembly>
- <DefaultTestTimeout>60000</DefaultTestTimeout>
- <UseBuildConfiguration />
-</ProjectConfiguration>
Oops, something went wrong.

0 comments on commit 662081b

Please sign in to comment.