Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 01b0c45

Browse files
Fixing tests adding test
1 parent fd4b95a commit 01b0c45

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

test/GitHub.App.UnitTests/Services/OAuthCallbackListenerTests.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using GitHub.Extensions;
66
using GitHub.Services;
77
using NSubstitute;
8+
using NSubstitute.ExceptionExtensions;
89
using Rothko;
910
using NUnit.Framework;
1011

@@ -32,6 +33,8 @@ public async Task ListenStopsHttpListenerAsync()
3233

3334
await target.Listen("id1", CancellationToken.None);
3435

36+
target.RedirectLastContext(new Uri("http://github.com"));
37+
3538
httpListener.Received(1).Stop();
3639
}
3740

@@ -70,9 +73,39 @@ public async Task SuccessfulResponseClosesResponseAsync()
7073

7174
await target.Listen("id1", CancellationToken.None);
7275

76+
target.RedirectLastContext(new Uri("http://github.com"));
77+
7378
context.Response.Received(1).Close();
7479
}
7580

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+
76109
static IHttpListener CreateHttpListener(string id)
77110
{
78111
var result = Substitute.For<IHttpListener>();

0 commit comments

Comments
 (0)