protected override void Given() { this.container = new Container(); BinderCollection.Initialize(this.container); this.Request = Stub <IRequest>(); this.Request.Headers.Returns(new HeaderCollection()); this.Request.Form.Returns(new HeaderCollection()); }
public void Bootstrap() { Container.Global.RunAllTypeProcessors(); Container.Global.RunAllRegistries(); Container.Global.RemoveAllRegistrationsAndInstancesOf <IHandlerCache>(); Container.Global.Register <IHandlerCache>(c => { var cache = new HandlerCache(Container.Global); var types = this.GetType().Assembly.GetTypes().Where(t => typeof(IHandler).IsAssignableFrom(t)).ToArray(); cache.Warm(types); return(cache); }); BinderCollection.Initialize(Container.Global); }
protected override void Given() { var container = new Container(); subject = new RequestBinder(container, Substitute.For <IErrorMessageResolver>(), new ViolationPropertyNameResolver()); this.handler = new TestHandler(); this.methodInfo = this.handler.GetType().GetMethod("Get"); this.request = new TestRequest(); this.request.SetRequestBody("{\"Text\":\"some text\",\"Number\":3}"); this.request.ContentType = "application/json; charset=utf-8"; this.request.HttpMethod = HttpMethod.Post; this.routeValues = new RouteValues { { "routeParam", "3A814A58-C5B2-408D-BDA8-B80DDC725735" } }; BinderCollection.Initialize(container); }
void DoBindToForm(string method, NameValueCollection formValues, int bindIterations) { BinderCollection.Initialize(Container.Global); var parameterInfos = typeof(TestHandler).GetMethod(method)?.GetParameters(); var request = new TestRequest { HttpMethod = HttpMethod.Post, ContentType = "multipart/form-data", Form = formValues }; var requestBinder = this.Subject <RequestBinder>(); var stopwatch = Stopwatch.StartNew(); for (var i = 0; i < bindIterations; i++) { requestBinder.Bind(null, parameterInfos?.Single(), request, new RouteValues()); } Console.WriteLine(stopwatch.Elapsed); }