|
5 | 5 | using GitHub.Extensions; |
6 | 6 | using GitHub.Services; |
7 | 7 | using NSubstitute; |
| 8 | +using NSubstitute.ExceptionExtensions; |
8 | 9 | using Rothko; |
9 | 10 | using NUnit.Framework; |
10 | 11 |
|
@@ -32,6 +33,8 @@ public async Task ListenStopsHttpListenerAsync() |
32 | 33 |
|
33 | 34 | await target.Listen("id1", CancellationToken.None); |
34 | 35 |
|
| 36 | + target.RedirectLastContext(new Uri("http://github.com")); |
| 37 | + |
35 | 38 | httpListener.Received(1).Stop(); |
36 | 39 | } |
37 | 40 |
|
@@ -70,9 +73,39 @@ public async Task SuccessfulResponseClosesResponseAsync() |
70 | 73 |
|
71 | 74 | await target.Listen("id1", CancellationToken.None); |
72 | 75 |
|
| 76 | + target.RedirectLastContext(new Uri("http://github.com")); |
| 77 | + |
73 | 78 | context.Response.Received(1).Close(); |
74 | 79 | } |
75 | 80 |
|
| 81 | + [Test] |
| 82 | + public async Task ContextFailureStopsListener() |
| 83 | + { |
| 84 | + var httpListener = Substitute.For<IHttpListener>(); |
| 85 | + httpListener |
| 86 | + .When(x => x.Start()) |
| 87 | + .Do(_ => httpListener.IsListening.Returns(true)); |
| 88 | + |
| 89 | + var context = Substitute.For<IHttpListenerContext>(); |
| 90 | + context.Request.Url.Returns(new Uri($"https://localhost:42549?code=1234&state={"id1"}")); |
| 91 | + httpListener.GetContext().Returns(context); |
| 92 | + httpListener.GetContextAsync().Returns(context); |
| 93 | + |
| 94 | + httpListener.GetContextAsync().Throws(new Exception()); |
| 95 | + var target = new OAuthCallbackListener(httpListener); |
| 96 | + |
| 97 | + try |
| 98 | + { |
| 99 | + await target.Listen("id1", CancellationToken.None); |
| 100 | + } |
| 101 | + catch (Exception e) |
| 102 | + { |
| 103 | + |
| 104 | + } |
| 105 | + |
| 106 | + httpListener.Received(1).Stop(); |
| 107 | + } |
| 108 | + |
76 | 109 | static IHttpListener CreateHttpListener(string id) |
77 | 110 | { |
78 | 111 | var result = Substitute.For<IHttpListener>(); |
|
0 commit comments