Skip to content
Browse files

Make a type out of IList<RequestHandler>

  • Loading branch information...
1 parent 0cc8f7b commit d41a66642924fbe2144101ff4aa537f54ad0cb6c @hibri hibri committed Sep 5, 2011
View
12 src/HttpMock.Unit.Tests/RequestProcessorTests.cs
@@ -19,7 +19,7 @@ public class RequestProcessorTests
[SetUp]
public void SetUp() {
- _processor = new RequestProcessor(_ruleThatReturnsFirstHandler, new List<RequestHandler>());
+ _processor = new RequestProcessor(_ruleThatReturnsFirstHandler, new RequestHandlerList());
_requestHandlerFactory = new RequestHandlerFactory(_processor);
_dataProducer = MockRepository.GenerateStub<IDataProducer>();
_httpResponseDelegate = MockRepository.GenerateStub<IHttpResponseDelegate>();
@@ -65,7 +65,7 @@ public class RequestProcessorTests
[Test]
public void If_no_handlers_found_should_fire_onresponse_with_a_404() {
- _processor = new RequestProcessor(_ruleThatReturnsNoHandlers, new List<RequestHandler>());
+ _processor = new RequestProcessor(_ruleThatReturnsNoHandlers, new RequestHandlerList());
_processor.Add(_requestHandlerFactory.Get("test"));
_processor.OnRequest(new HttpRequestHead(), _dataProducer, _httpResponseDelegate);
@@ -74,7 +74,7 @@ public class RequestProcessorTests
[Test]
public void If_a_handler_found_should_fire_onresponse_with_that_repsonse() {
- _processor = new RequestProcessor(_ruleThatReturnsFirstHandler, new List<RequestHandler>());
+ _processor = new RequestProcessor(_ruleThatReturnsFirstHandler, new RequestHandlerList());
RequestHandler requestHandler = _requestHandlerFactory.Get("test");
_processor.Add(requestHandler);
@@ -86,7 +86,7 @@ public class RequestProcessorTests
[Test]
public void Matching_HEAD_handler_should_output_handlers_expected_response_with_null_body() {
- _processor = new RequestProcessor(_ruleThatReturnsFirstHandler, new List<RequestHandler>());
+ _processor = new RequestProcessor(_ruleThatReturnsFirstHandler, new RequestHandlerList());
RequestHandler requestHandler = _requestHandlerFactory.Head("test");
_processor.Add(requestHandler);
@@ -101,7 +101,7 @@ public class RequestProcessorTests
string expectedPath = "/blah/test";
string expectedMethod = "GET";
- var requestProcessor = new RequestProcessor(null, new List<RequestHandler>());
+ var requestProcessor = new RequestProcessor(null, new RequestHandlerList());
requestProcessor.Add(_requestHandlerFactory.Get(expectedPath));
@@ -118,7 +118,7 @@ public class RequestProcessorTests
string expectedPath = "/blah/test";
string expectedMethod = "GET";
- var requestProcessor = new RequestProcessor(_ruleThatReturnsFirstHandler, new List<RequestHandler>());
+ var requestProcessor = new RequestProcessor(_ruleThatReturnsFirstHandler, new RequestHandlerList());
requestProcessor.Add(_requestHandlerFactory.Get(expectedPath));
var httpRequestHead = new HttpRequestHead { Headers = new Dictionary<string, string>() };
View
1 src/HttpMock/HttpMock.csproj
@@ -70,6 +70,7 @@
<Compile Include="HttpMockRepository.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RequestHandler.cs" />
+ <Compile Include="RequestHandlerList.cs" />
<Compile Include="RequestProcessor.cs" />
<Compile Include="RequestWasCalled.cs" />
<Compile Include="RequestWasNotCalled.cs" />
View
2 src/HttpMock/HttpServer.cs
@@ -23,7 +23,7 @@ public class HttpServer : IHttpServer
public HttpServer(Uri uri) {
_uri = uri;
_scheduler = KayakScheduler.Factory.Create(new SchedulerDelegate());
- _requestProcessor = new RequestProcessor(new EndpointMatchingRule(), new List<RequestHandler>());
+ _requestProcessor = new RequestProcessor(new EndpointMatchingRule(), new RequestHandlerList());
_requestWasCalled = new RequestWasCalled(_requestProcessor);
_requestWasNotCalled = new RequestWasNotCalled(_requestProcessor);
_requestHandlerFactory = new RequestHandlerFactory(_requestProcessor);
View
9 src/HttpMock/RequestHandlerList.cs
@@ -0,0 +1,9 @@
+using System.Collections.Generic;
+
+namespace HttpMock
+{
+ public class RequestHandlerList : List<RequestHandler>
+ {
+
+ }
+}
View
7 src/HttpMock/RequestProcessor.cs
@@ -17,9 +17,9 @@ public class RequestProcessor : IHttpRequestDelegate, IRequestProcessor
{
private static readonly ILog _log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
private readonly IMatchingRule _matchingRule;
- private IList<RequestHandler> _handlers;
+ private RequestHandlerList _handlers;
- public RequestProcessor(IMatchingRule matchingRule, IList<RequestHandler> requestHandlers) {
+ public RequestProcessor(IMatchingRule matchingRule, RequestHandlerList requestHandlers) {
_matchingRule = matchingRule;
_handlers = requestHandlers;
}
@@ -66,6 +66,7 @@ public class RequestProcessor : IHttpRequestDelegate, IRequestProcessor
}
private RequestHandler MatchHandler(HttpRequestHead request) {
+
return _handlers.Where(x => _matchingRule.IsEndpointMatch(x, request)).FirstOrDefault();
}
@@ -94,7 +95,7 @@ public class RequestProcessor : IHttpRequestDelegate, IRequestProcessor
}
public void ClearHandlers() {
- _handlers = new List<RequestHandler>();
+ _handlers = new RequestHandlerList();
}
public void Add(RequestHandler requestHandler) {

0 comments on commit d41a666

Please sign in to comment.
Something went wrong with that request. Please try again.