Skip to content

Commit

Permalink
Make a type out of IList<RequestHandler>
Browse files Browse the repository at this point in the history
  • Loading branch information
hibri committed Sep 5, 2011
1 parent 0cc8f7b commit d41a666
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/HttpMock.Unit.Tests/RequestProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down Expand Up @@ -65,7 +65,7 @@ public void Head_should_return_handler_with_head_method_set() {

[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);
Expand All @@ -74,7 +74,7 @@ public void If_no_handlers_found_should_fire_onresponse_with_a_404() {

[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);
Expand All @@ -86,7 +86,7 @@ public void If_a_handler_found_should_fire_onresponse_with_that_repsonse() {
[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);
Expand All @@ -101,7 +101,7 @@ public void When_a_handler_is_added_should_be_able_to_find_it() {
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));

Expand All @@ -118,7 +118,7 @@ public void When_a_handler_is_hit_handlers_request_count_is_incremented() {
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>() };
Expand Down
1 change: 1 addition & 0 deletions src/HttpMock/HttpMock.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
2 changes: 1 addition & 1 deletion src/HttpMock/HttpServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 9 additions & 0 deletions src/HttpMock/RequestHandlerList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Collections.Generic;

namespace HttpMock
{
public class RequestHandlerList : List<RequestHandler>
{

}
}
7 changes: 4 additions & 3 deletions src/HttpMock/RequestProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -66,6 +66,7 @@ private int GetHandlerCount() {
}

private RequestHandler MatchHandler(HttpRequestHead request) {

return _handlers.Where(x => _matchingRule.IsEndpointMatch(x, request)).FirstOrDefault();
}

Expand Down Expand Up @@ -94,7 +95,7 @@ private static void ReturnHttpMockNotFound(IHttpResponseDelegate response) {
}

public void ClearHandlers() {
_handlers = new List<RequestHandler>();
_handlers = new RequestHandlerList();
}

public void Add(RequestHandler requestHandler) {
Expand Down

0 comments on commit d41a666

Please sign in to comment.