コード例 #1
0
        public async Task ExecuteResultAsync_InvokesSignOutAsyncOnAuthenticationManager()
        {
            // Arrange
            var httpContext = new Mock <HttpContext>();
            var auth        = new Mock <IAuthenticationService>();

            auth
            .Setup(c => c.SignOutAsync(httpContext.Object, "", null))
            .Returns(Task.CompletedTask)
            .Verifiable();
            httpContext.Setup(c => c.RequestServices).Returns(CreateServices(auth.Object));
            var result    = new SignOutResult("", null);
            var routeData = new RouteData();

            var actionContext = new ActionContext(
                httpContext.Object,
                routeData,
                new ActionDescriptor());

            // Act
            await result.ExecuteResultAsync(actionContext);

            // Assert
            auth.Verify();
        }
コード例 #2
0
        public async Task ExecuteResultAsync_InvokesSignOutAsyncOnAllConfiguredSchemes()
        {
            // Arrange
            var authProperties        = new AuthenticationProperties();
            var authenticationManager = new Mock <AuthenticationManager>();

            authenticationManager
            .Setup(c => c.SignOutAsync("Scheme1", authProperties))
            .Returns(TaskCache.CompletedTask)
            .Verifiable();
            authenticationManager
            .Setup(c => c.SignOutAsync("Scheme2", authProperties))
            .Returns(TaskCache.CompletedTask)
            .Verifiable();
            var httpContext = new Mock <HttpContext>();

            httpContext.Setup(c => c.RequestServices).Returns(CreateServices());
            httpContext.Setup(c => c.Authentication).Returns(authenticationManager.Object);
            var result    = new SignOutResult(new[] { "Scheme1", "Scheme2" }, authProperties);
            var routeData = new RouteData();

            var actionContext = new ActionContext(
                httpContext.Object,
                routeData,
                new ActionDescriptor());

            // Act
            await result.ExecuteResultAsync(actionContext);

            // Assert
            authenticationManager.Verify();
        }
コード例 #3
0
        public async Task ExecuteResultAsync_InvokesSignOutAsyncOnAllConfiguredSchemes()
        {
            // Arrange
            var authProperties = new AuthenticationProperties();
            var authenticationManager = new Mock<AuthenticationManager>();
            authenticationManager
                .Setup(c => c.SignOutAsync("Scheme1", authProperties))
                .Returns(TaskCache.CompletedTask)
                .Verifiable();
            authenticationManager
                .Setup(c => c.SignOutAsync("Scheme2", authProperties))
                .Returns(TaskCache.CompletedTask)
                .Verifiable();
            var httpContext = new Mock<HttpContext>();
            httpContext.Setup(c => c.RequestServices).Returns(CreateServices());
            httpContext.Setup(c => c.Authentication).Returns(authenticationManager.Object);
            var result = new SignOutResult(new[] { "Scheme1", "Scheme2" }, authProperties);
            var routeData = new RouteData();

            var actionContext = new ActionContext(
                httpContext.Object,
                routeData,
                new ActionDescriptor());

            // Act
            await result.ExecuteResultAsync(actionContext);

            // Assert
            authenticationManager.Verify();
        }