// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNet.Builder; using Microsoft.AspNet.Http; using Microsoft.AspNet.Http.Security; using Microsoft.AspNet.Identity.Test; using Microsoft.AspNet.Security.Cookies; using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection.Fallback; using Moq; using System.Security.Claims; using System.Threading.Tasks; using Xunit; namespace Microsoft.AspNet.Identity.InMemory.Test { public class ApplicationUser : IdentityUser { } public class HttpSignInTest { [Theory] [InlineData(true)] [InlineData(false)] public async Task VerifyAccountControllerSignIn(bool isPersistent) { var app = new ApplicationBuilder(new ServiceCollection().BuildServiceProvider()); app.UseCookieAuthentication(); var context = new Mock(); var response = new Mock(); context.Setup(c => c.Response).Returns(response.Object).Verifiable(); response.Setup(r => r.SignIn(It.Is(v => v.IsPersistent == isPersistent), It.IsAny())).Verifiable(); var contextAccessor = new Mock>(); contextAccessor.Setup(a => a.Value).Returns(context.Object); app.UseServices(services => { services.AddInstance(contextAccessor.Object); services.AddIdentity().AddInMemory(); }); // Act var user = new ApplicationUser { UserName = "Yolo" }; const string password = "Yol0Sw@g!"; var userManager = app.ApplicationServices.GetRequiredService>(); var signInManager = app.ApplicationServices.GetRequiredService>(); IdentityResultAssert.IsSuccess(await userManager.CreateAsync(user, password)); var result = await signInManager.PasswordSignInAsync(user.UserName, password, isPersistent, false); // Assert Assert.Equal(SignInStatus.Success, result); context.VerifyAll(); response.VerifyAll(); contextAccessor.VerifyAll(); } } }