public RequestHandler( IArgumentBinder <RequestInfo> argumentBinder, IDelegateMapper <RequestInfo> delegateMapper, IResponseComposer responseComposer, IEnumerable <IPreRequestHandler> preRequestHandlers, IEnumerable <IPostRequestHandler> postRequestHandlers, IEnumerable <IModelTransformer> modelTransformers) { if (argumentBinder == null) { throw new ArgumentNullException("argumentBinder"); } if (delegateMapper == null) { throw new ArgumentNullException("delegateMapper"); } if (responseComposer == null) { throw new ArgumentNullException("responseComposer"); } _responseComposer = responseComposer; _argumentBinder = argumentBinder; _handlerMapper = delegateMapper; _preRequestHandlers = new List <IPreRequestHandler>(); _postRequestHandlers = new List <IPostRequestHandler>(); _authenticationProviders = new List <IPreRequestHandler>(); _modelTransformers = modelTransformers ?? new IModelTransformer[0]; _defaultAuthenticationScheme = Initialize(preRequestHandlers, postRequestHandlers); }
public void Setup() { var method = typeof(TestController).GetMethod("Add"); _controller = new TestController(); _operation = new OperationInfo<Verb>( method, (HttpUrl)UrlParser.Parse("/add"), "/api/test/add?{?operandA}&{?operandB}", new Regex(".*"), Verb.GET, method.GetParameters().Select(parameter => (ValueInfo)new ArgumentInfo(parameter, FromQueryStringAttribute.For(parameter), "add?{?" + parameter.Name + "}", parameter.Name)).ToArray()); var controllerInfo = new ControllerInfo<TestController>(null, (HttpUrl)UrlParser.Parse("api/test"), _operation); Mock<IHttpControllerDescriptionBuilder> controllerDescriptionBuilder = new Mock<IHttpControllerDescriptionBuilder>(MockBehavior.Strict); controllerDescriptionBuilder.Setup(instance => instance.BuildDescriptor()).Returns(controllerInfo); Mock<IControllerActivator> controllerActivator = new Mock<IControllerActivator>(MockBehavior.Strict); controllerActivator.Setup(instance => instance.CreateInstance(It.IsAny<Type>(), It.IsAny<IDictionary<string, object>>())).Returns(_controller); _delegateMapper = new DelegateMapper(new[] { controllerDescriptionBuilder.Object }, controllerActivator.Object); }
public void Setup() { var method = typeof(TestController).GetMethod("Add"); _controller = new TestController(); _operation = new OperationInfo <Verb>( method, (HttpUrl)UrlParser.Parse("/add"), "/api/test/add?{?operandA}&{?operandB}", new Regex(".*"), Verb.GET, method.GetParameters().Select(parameter => (ValueInfo) new ArgumentInfo(parameter, FromQueryStringAttribute.For(parameter), "add?{?" + parameter.Name + "}", parameter.Name)).ToArray()); var controllerInfo = new ControllerInfo <TestController>(null, (HttpUrl)UrlParser.Parse("api/test"), _operation); Mock <IHttpControllerDescriptionBuilder> controllerDescriptionBuilder = new Mock <IHttpControllerDescriptionBuilder>(MockBehavior.Strict); controllerDescriptionBuilder.Setup(instance => instance.BuildDescriptor()).Returns(controllerInfo); Mock <IControllerActivator> controllerActivator = new Mock <IControllerActivator>(MockBehavior.Strict); controllerActivator.Setup(instance => instance.CreateInstance(It.IsAny <Type>(), It.IsAny <IDictionary <string, object> >())).Returns(_controller); _delegateMapper = new DelegateMapper(new[] { controllerDescriptionBuilder.Object }, controllerActivator.Object); }
public void Setup() { var method = typeof(TestController).GetMethod("Add"); var baseUri = (HttpUrl)UrlParser.Parse("/api/test/"); var operationUri = ((HttpUrl)UrlParser.Parse("/add")).InsertSegments(0, baseUri.Segments); var operation = new OperationInfo <Verb>( method, operationUri, operationUri + "?operandA={?operandA}&operandB={?operandB}", new Regex(operationUri.ToString(), RegexOptions.IgnoreCase), Verb.GET, new ArgumentInfo(method.GetParameters()[0], FromQueryStringAttribute.For(method.GetParameters()[0]), "&operandA={?operandA}", "operandA"), new ArgumentInfo(method.GetParameters()[1], FromQueryStringAttribute.For(method.GetParameters()[1]), "&operandB={?operandB}", "operandB")); var description = new ControllerInfo <TestController>(null, (HttpUrl)UrlParser.Parse("/api/test/"), operation); Mock <IHttpControllerDescriptionBuilder <TestController> > builder = new Mock <IHttpControllerDescriptionBuilder <TestController> >(); builder.As <IControllerDescriptionBuilder>().Setup(instance => instance.BuildDescriptor()).Returns(description); Mock <IControllerActivator> activator = new Mock <IControllerActivator>(); activator.Setup(instance => instance.CreateInstance(It.IsAny <Type>(), It.IsAny <IDictionary <string, object> >())).Returns(new TestController()); _mapper = new DelegateMapper(new IHttpControllerDescriptionBuilder[] { builder.Object }, activator.Object); }
public void Teardown() { _mapper = null; }
public void Setup() { var method = typeof(TestController).GetMethod("Add"); var baseUri = (HttpUrl)UrlParser.Parse("/api/test/"); var operationUri = ((HttpUrl)UrlParser.Parse("/add")).InsertSegments(0, baseUri.Segments); var operation = new OperationInfo<Verb>( method, operationUri, operationUri + "?operandA={?operandA}&operandB={?operandB}", new Regex(operationUri.ToString(), RegexOptions.IgnoreCase), Verb.GET, new ArgumentInfo(method.GetParameters()[0], FromQueryStringAttribute.For(method.GetParameters()[0]), "&operandA={?operandA}", "operandA"), new ArgumentInfo(method.GetParameters()[1], FromQueryStringAttribute.For(method.GetParameters()[1]), "&operandB={?operandB}", "operandB")); var description = new ControllerInfo<TestController>(null, (HttpUrl)UrlParser.Parse("/api/test/"), operation); Mock<IHttpControllerDescriptionBuilder<TestController>> builder = new Mock<IHttpControllerDescriptionBuilder<TestController>>(); builder.As<IControllerDescriptionBuilder>().Setup(instance => instance.BuildDescriptor()).Returns(description); Mock<IControllerActivator> activator = new Mock<IControllerActivator>(); activator.Setup(instance => instance.CreateInstance(It.IsAny<Type>(), It.IsAny<IDictionary<string, object>>())).Returns(new TestController()); _mapper = new DelegateMapper(new IHttpControllerDescriptionBuilder[] { builder.Object }, activator.Object); }
public void Teardown() { _controller = null; _operation = null; _delegateMapper = null; }