Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Registered handlers now overwrite previous ones rather than getting s…

…ilently appended, never to be invoked.

10 test failures.
  • Loading branch information...
commit 257e43bcb3bf8f5181059450283eba832be5b1fa 1 parent 742e5d6
@AArnott AArnott authored
View
23 src/DotNetOpenAuth.Test/MockingHostFactories.cs
@@ -15,19 +15,16 @@ namespace DotNetOpenAuth.Test {
using DotNetOpenAuth.OpenId;
using Validation;
+ using System;
internal class MockingHostFactories : IHostFactories {
- private readonly List<TestBase.Handler> handlers;
-
- public MockingHostFactories(List<TestBase.Handler> handlers = null) {
- this.handlers = handlers ?? new List<TestBase.Handler>();
+ public MockingHostFactories(Dictionary<Uri, Func<HttpRequestMessage, Task<HttpResponseMessage>>> handlers = null) {
+ this.Handlers = handlers ?? new Dictionary<Uri, Func<HttpRequestMessage, Task<HttpResponseMessage>>>();
this.CookieContainer = new CookieContainer();
this.AllowAutoRedirects = true;
}
- public List<TestBase.Handler> Handlers {
- get { return this.handlers; }
- }
+ public Dictionary<Uri, Func<HttpRequestMessage, Task<HttpResponseMessage>>> Handlers { get; private set; }
public CookieContainer CookieContainer { get; set; }
@@ -36,7 +33,7 @@ internal class MockingHostFactories : IHostFactories {
public bool InstallUntrustedWebReqestHandler { get; set; }
public HttpMessageHandler CreateHttpMessageHandler() {
- var forwardingMessageHandler = new ForwardingMessageHandler(this.handlers, this);
+ var forwardingMessageHandler = new ForwardingMessageHandler(this.Handlers, this);
var cookieDelegatingHandler = new CookieDelegatingHandler(forwardingMessageHandler, this.CookieContainer);
if (this.InstallUntrustedWebReqestHandler) {
var untrustedHandler = new UntrustedWebRequestHandler(cookieDelegatingHandler);
@@ -54,11 +51,11 @@ internal class MockingHostFactories : IHostFactories {
}
private class ForwardingMessageHandler : HttpMessageHandler {
- private readonly IEnumerable<TestBase.Handler> handlers;
+ private readonly Dictionary<Uri, Func<HttpRequestMessage, Task<HttpResponseMessage>>> handlers;
private readonly IHostFactories hostFactories;
- public ForwardingMessageHandler(IEnumerable<TestBase.Handler> handlers, IHostFactories hostFactories) {
+ public ForwardingMessageHandler(Dictionary<Uri, Func<HttpRequestMessage, Task<HttpResponseMessage>>> handlers, IHostFactories hostFactories) {
Requires.NotNull(handlers, "handlers");
this.handlers = handlers;
@@ -66,9 +63,9 @@ private class ForwardingMessageHandler : HttpMessageHandler {
}
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
- foreach (var handler in this.handlers) {
- if (handler.Uri.IsBaseOf(request.RequestUri) && handler.Uri.AbsolutePath == request.RequestUri.AbsolutePath) {
- var response = await handler.MessageHandler(request);
+ foreach (var pair in this.handlers) {
+ if (pair.Key.IsBaseOf(request.RequestUri) && pair.Key.AbsolutePath == request.RequestUri.AbsolutePath) {
+ var response = await pair.Value(request);
if (response != null) {
if (response.RequestMessage == null) {
response.RequestMessage = request;
View
9 src/DotNetOpenAuth.Test/TestBase.cs
@@ -131,21 +131,16 @@ internal Handler(TestBase test, Uri uri)
this.Uri = uri;
}
- private Handler(Handler previous, Func<HttpRequestMessage, Task<HttpResponseMessage>> handler)
- : this(previous.test, previous.Uri) {
- this.MessageHandler = handler;
- }
-
internal Uri Uri { get; private set; }
internal Func<HttpRequestMessage, Task<HttpResponseMessage>> MessageHandler { get; private set; }
internal void By(Func<HttpRequestMessage, CancellationToken, Task<HttpResponseMessage>> handler) {
- this.test.HostFactories.Handlers.Add(new Handler(this, req => handler(req, CancellationToken.None)));
+ this.test.HostFactories.Handlers[this.Uri] = req => handler(req, CancellationToken.None);
}
internal void By(Func<HttpRequestMessage, Task<HttpResponseMessage>> handler) {
- this.test.HostFactories.Handlers.Add(new Handler(this, handler));
+ this.test.HostFactories.Handlers[this.Uri] = handler;
}
internal void By(Func<HttpRequestMessage, HttpResponseMessage> handler) {
Please sign in to comment.
Something went wrong with that request. Please try again.