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();
        }
Exemplo n.º 2
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();
        }
        public async Task ListenStopsHttpListenerAsync()
        {
            var httpListener = CreateHttpListener("id1");
            var target       = new OAuthCallbackListener(httpListener);

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

            httpListener.Received(1).Stop();
        }
        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();
        }
        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();
        }
Exemplo n.º 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();
        }
        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();
        }
Exemplo n.º 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();
        }