コード例 #1
0
        public async Task ContextFailureStopsListener()
        {
            var httpListener = Substitute.For <IHttpListener>();

            httpListener
            .When(x => x.Start())
            .Do(_ => httpListener.IsListening.Returns(true));

            var context = Substitute.For <IHttpListenerContext>();

            context.Request.Url.Returns(new Uri($"https://localhost:42549?code=1234&state={"id1"}"));
            httpListener.GetContext().Returns(context);
            httpListener.GetContextAsync().Returns(context);

            httpListener.GetContextAsync().Throws(new Exception());
            var target = new OAuthCallbackListener(httpListener);

            try
            {
                await target.Listen("id1", CancellationToken.None);
            }
            catch (Exception e)
            {
            }

            httpListener.Received(1).Stop();
        }
コード例 #2
0
        public async Task ListenStopsHttpListenerAsync()
        {
            var httpListener = CreateHttpListener("id1");
            var target       = new OAuthCallbackListener(httpListener);

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

            httpListener.Received(1).Stop();
        }
コード例 #3
0
        public void CallingListenWhenAlreadyListeningCancelsFirstListen()
        {
            var httpListener = CreateHttpListener(null);

            var target = new OAuthCallbackListener(httpListener);
            var task1  = target.Listen("id1", CancellationToken.None);
            var task2  = target.Listen("id2", CancellationToken.None);

            httpListener.Received(1).Stop();
        }
コード例 #4
0
        public void ListenStartsHttpListener()
        {
            var httpListener = CreateHttpListener("id1");
            var target       = new OAuthCallbackListener(httpListener);

            target.Listen("id1", CancellationToken.None).Forget();

            httpListener.Prefixes.Received(1).Add("http://localhost:42549/");
            httpListener.Received(1).Start();
        }
コード例 #5
0
        public async Task SuccessfulResponseClosesResponse()
        {
            var httpListener = CreateHttpListener("id1");
            var context      = httpListener.GetContext();
            var target       = new OAuthCallbackListener(httpListener);

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

            context.Response.Received(1).Close();
        }
コード例 #6
0
        public async Task ListenStopsHttpListenerAsync()
        {
            var httpListener = CreateHttpListener("id1");
            var target       = new OAuthCallbackListener(httpListener);

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

            target.RedirectLastContext(new Uri("http://github.com"));

            httpListener.Received(1).Stop();
        }
コード例 #7
0
        public void CancelStopsHttpListener()
        {
            var httpListener = CreateHttpListener(null);
            var cts          = new CancellationTokenSource();
            var target       = new OAuthCallbackListener(httpListener);

            var task = target.Listen("id1", cts.Token);

            httpListener.Received(0).Stop();

            cts.Cancel();
            httpListener.Received(1).Stop();
        }
コード例 #8
0
        public async Task SuccessfulResponseClosesResponseAsync()
        {
            var httpListener = CreateHttpListener("id1");
            var context      = await httpListener.GetContextAsync();

            var target = new OAuthCallbackListener(httpListener);

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

            target.RedirectLastContext(new Uri("http://github.com"));

            context.Response.Received(1).Close();
        }