public static IMockedRequestContext HttpMethod(this IMockedRequestContext context, string httpMethod) { InstanceDictionary.Set(context, "HttpMethod", httpMethod); SetHttpMethodCallback(context); return(context); }
private static void SetHttpMethodCallback(IMockedRequestContext context) { if (context.Request.HttpMethod != null) { return; } context.Request.Stub(requestBase => requestBase.HttpMethod) .WhenCalled(invocation => invocation.ReturnValue = InstanceDictionary.Get <string>(context, "HttpMethod")) .Return(null).Repeat.Any(); }
public static IMockedRequestContext Role(this IMockedRequestContext context, string role) { if (string.IsNullOrEmpty(role)) { context.Context.User = new GenericPrincipal(new GenericIdentity(""), null); } else { context.Context.User = new GenericPrincipal(new GenericIdentity("AnUser"), new[] { role }); } return(context); }
public static IMockedRequestContext AntiForgeryToken(this IMockedRequestContext context) { HttpContext.Current = new HttpContext(new HttpRequest("/", "http://localhost/", ""), new HttpResponse(TextWriter.Null)); var viewContext = new ViewContext { HttpContext = context.Context }; var htmlHelper = new HtmlHelper(viewContext, MockRepository.GenerateStub <IViewDataContainer>()); var str = htmlHelper.AntiForgeryToken().ToHtmlString(); var name = GetValue(str, "name"); var value = GetValue(str, "value"); context.Request.Form.Add(name, value); return(context); }
public static IMockedRequestContext SerializeModelToForm( this IMockedRequestContext context, object model, string parameterName) { var properties = model.GetType().GetProperties(); foreach (var propertyInfo in properties) { var formName = propertyInfo.Name; if (!string.IsNullOrEmpty(parameterName)) { formName = parameterName + "." + formName; } var value = propertyInfo.GetValue(model, null) ?? ""; context.Request.Form.Add(formName, value.ToString()); } return(context); }
protected virtual void PrepareRequestContext(IMockedRequestContext requestContext) { }