Esempio n. 1
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();
        }
        public async Task ExecuteAsync_InvokesSignOutAsyncOnAllConfiguredSchemes()
        {
            // Arrange
            var authProperties = new AuthenticationProperties();
            var httpContext    = new Mock <HttpContext>();
            var auth           = new Mock <IAuthenticationService>();

            auth
            .Setup(c => c.SignOutAsync(httpContext.Object, "Scheme1", authProperties))
            .Returns(Task.CompletedTask)
            .Verifiable();
            auth
            .Setup(c => c.SignOutAsync(httpContext.Object, "Scheme2", authProperties))
            .Returns(Task.CompletedTask)
            .Verifiable();
            httpContext.Setup(c => c.RequestServices).Returns(CreateServices(auth.Object));
            var result = new SignOutResult(new[] { "Scheme1", "Scheme2" }, authProperties);

            // Act
            await((IResult)result).ExecuteAsync(httpContext.Object);

            // Assert
            auth.Verify();
        }