static void createRequestContext(IFakeAccessor context) { var routeData = context.An<RouteData>(); var requestContext = context.The<RequestContext>(); requestContext.WhenToldTo(x => x.HttpContext).Return(context.The<HttpContextBase>()); // Used by UrlHelper.GenerateUrl(...) requestContext.WhenToldTo(x => x.RouteData).Return(routeData); }
static void createHttpRequest(IFakeAccessor context) { // MvcContrib.FakeHttpRequest doesn't implement RawUrl. var uri = new Uri(_currentUrl); context.The<HttpRequestBase>().WhenToldTo(x => x.Url).Return(uri); context.The<HttpRequestBase>().WhenToldTo(x => x.RawUrl) .Return(uri.AbsoluteUri.Substring(uri.GetLeftPart(UriPartial.Authority).Length)); // Used by PathHelpers.GenerateClientUrl(...) context.The<HttpRequestBase>().WhenToldTo(x => x.ApplicationPath).Return("/"); }
static void createHttpContext(IFakeAccessor context) { context.The<HttpContextBase>().WhenToldTo(x => x.Request).Return(context.The<HttpRequestBase>()); // Used by RouteCollection.GetUrlWithApplicationPath(...) context.The<HttpContextBase>().WhenToldTo(x => x.Response).Return(new FakeHttpResponse()); }
static void createUrlHelper(IFakeAccessor context) { context.Configure(FakeUrlHelper.ConfigureRouteCollection()); context.Configure(new UrlHelper(context.The<RequestContext>(), context.The<RouteCollection>())); }
public static FakeHtmlHelper <T> Create(IFakeAccessor accessor, ControllerContext controllerContext) { ViewContext viewContext = new MockViewContext(accessor, controllerContext).ViewContext; var container = accessor.An <IViewDataContainer>(); container.WhenToldTo(c => c.ViewData).Return(viewContext.ViewData); return(new FakeHtmlHelper <T>(viewContext, container)); }
/// <summary> /// Registered the type specified via <typeparamref name = "TImplementationType" /> as the default type /// for the interface specified via <typeparamref name = "TInterfaceType" />. With this the type gets automatically /// build when the subject is resolved. /// </summary> /// <param name = "accessor"> /// Specifies the fake accessor /// </param> /// <typeparam name = "TInterfaceType"> /// Specifies the interface type. /// </typeparam> /// <typeparam name = "TImplementationType"> /// Specifies the implementation type. /// </typeparam> public static void Configure <TInterfaceType, TImplementationType>( this IFakeAccessor accessor) where TImplementationType : TInterfaceType { Guard.AgainstArgumentNull(accessor, "accessor"); accessor.Configure(Registrar.New(config => config.For <TInterfaceType>().Use <TImplementationType>())); }
/// <summary> /// Uses the instance supplied by <paramref name="instance"/> during the /// creation of the sut. The specified instance will be injected into the constructor. /// </summary> /// <typeparam name="TInterfaceType">Specifies the interface type.</typeparam> /// <param name="accessor">Specifies the fake accessor</param> /// <param name="instance">Specifies the instance to be used for the specification.</param> public static void Configure <TInterfaceType>( this IFakeAccessor accessor, TInterfaceType instance) { Guard.AgainstArgumentNull(accessor, "accessor"); accessor.Configure(Registrar.New(config => config.For <TInterfaceType>().Use(instance))); }
/// <summary> /// Shortcut for <see cref = "IFakeAccessor.Configure" />. This one will create /// a registrar for you and allow configuration via the delegate passed /// in via <paramref name = "registrarExpression" />. /// </summary> /// <param name = "accessor"> /// Specifies the fake accessor /// </param> /// <param name = "registrarExpression"> /// Specifies the configuration for the registrar. /// </param> /// <exception cref = "ArgumentNullException"> /// Thrown when the supplied registrar expression is <c>null</c>. /// </exception> public static void Configure( this IFakeAccessor accessor, Action <Registrar> registrarExpression) { Guard.AgainstArgumentNull(accessor, "accessor"); Guard.AgainstArgumentNull(registrarExpression, "registrarExpression"); accessor.Configure(Registrar.New(registrarExpression)); }
public MockViewContext(IFakeAccessor fakes, ControllerContext controllerContext) { this.fakes = fakes; viewContext = fakes.An <ViewContext>(); viewContext.WhenToldTo(v => v.HttpContext).Return(controllerContext.HttpContext); viewContext.WhenToldTo(c => c.RouteData).Return(controllerContext.RouteData); viewContext.WhenToldTo(c => c.View).Return(this.fakes.An <IView>()); MockIt(); }
public MockHttpContext(IFakeAccessor fakes) { this.fakes = fakes; httpContext = this.fakes.An <HttpContextBase>(); httpRequest = new Lazy <HttpRequestBase>(() => new MockHttpRequest(fakes).Request); httpResponse = new Lazy <HttpResponseBase>(() => new MockHttpResponse(fakes).Response); httpSessionState = new Lazy <HttpSessionStateBase>(() => new MockHttpSessionState(fakes).Session); MockIt(); }
static void createRequestContext(IFakeAccessor context) { var routeData = context.An <RouteData>(); var requestContext = context.The <RequestContext>(); requestContext.WhenToldTo(x => x.HttpContext).Return(context.The <HttpContextBase>()); // Used by UrlHelper.GenerateUrl(...) requestContext.WhenToldTo(x => x.RouteData).Return(routeData); }
public void Establish(object behaviorConfig, IFakeAccessor fakeAccessor) { Guard.AgainstArgumentNull(behaviorConfig, "behaviorConfig"); Guard.AgainstArgumentNull(fakeAccessor, "fakeAccessor"); behaviorConfig .GetFieldValues<OnEstablish>() .ForEach(establishDelegate => establishDelegate(fakeAccessor)); _behaviorConfigs.Add(behaviorConfig); }
static void createHttpRequest(IFakeAccessor context) { // MvcContrib.FakeHttpRequest doesn't implement RawUrl. var uri = new Uri(_currentUrl); context.The <HttpRequestBase>().WhenToldTo(x => x.Url).Return(uri); context.The <HttpRequestBase>().WhenToldTo(x => x.RawUrl) .Return(uri.AbsoluteUri.Substring(uri.GetLeftPart(UriPartial.Authority).Length)); // Used by PathHelpers.GenerateClientUrl(...) context.The <HttpRequestBase>().WhenToldTo(x => x.ApplicationPath).Return("/"); }
public void Establish(object behaviorConfig, IFakeAccessor fakeAccessor) { Guard.AgainstArgumentNull(behaviorConfig, "behaviorConfig"); Guard.AgainstArgumentNull(fakeAccessor, "fakeAccessor"); behaviorConfig .GetFieldValues <OnEstablish>() .Each(establishDelegate => establishDelegate(fakeAccessor)); _behaviorConfigs.Add(behaviorConfig); }
public FakesAdapter(IFakeAccessor original_controller) { this.original_controller = original_controller; }
public MockHttpRequest(IFakeAccessor fakes) { this.fakes = fakes; request = fakes.An <HttpRequestBase>(); MockIt(); }
public MockHttpSessionState(IFakeAccessor fakes) { this.fakes = fakes; session = fakes.An <FakeHttpSessionStateBase>(); session.WhenToldTo(s => s.SyncRoot).Return(new object()); }
static void createUrlHelper(IFakeAccessor context) { context.Configure(FakeUrlHelper.ConfigureRouteCollection()); context.Configure(new UrlHelper(context.The <RequestContext>(), context.The <RouteCollection>())); }
public MockHttpResponse(IFakeAccessor fakes) { this.fakes = fakes; response = fakes.An <HttpResponseBase>(); MockIt(); }
static void createHttpContext(IFakeAccessor context) { context.The <HttpContextBase>().WhenToldTo(x => x.Request).Return(context.The <HttpRequestBase>()); // Used by RouteCollection.GetUrlWithApplicationPath(...) context.The <HttpContextBase>().WhenToldTo(x => x.Response).Return(new FakeHttpResponse()); }