Skip to content

Instantly share code, notes, and snippets.

@osya
Created October 24, 2016 11:00
Show Gist options
  • Save osya/78a3853a2cd4bda68eaf29775602c873 to your computer and use it in GitHub Desktop.
Save osya/78a3853a2cd4bda68eaf29775602c873 to your computer and use it in GitHub Desktop.
Mocking ExternalLoginCallbackTest #CSharp
[TestMethod]
public async Task ExternalLoginCallbackTest()
{
// Arrange
var authManager = new Mock<IAuthenticationManager>();
var externalUser = new ClaimsIdentity(new[] {
new Claim(ClaimTypes.NameIdentifier, "10154549708179846", "http://www.w3.org/2001/XMLSchema#string", "Facebook"),
new Claim(ClaimTypes.Name, DummyModel.UserName, "http://www.w3.org/2001/XMLSchema#string", "Facebook")
});
var authenticationResult = new AuthenticateResult(externalUser, new AuthenticationProperties(), new AuthenticationDescription());
authManager.Setup(x => x.AuthenticateAsync(It.IsAny<string>())).Returns(Task.FromResult(authenticationResult));
var signInManager = new Mock<ApplicationSignInManager>(UserManager, authManager.Object);
signInManager.Setup(x => x.ExternalSignInAsync(It.IsAny<ExternalLoginInfo>(), false)).Returns(Task.FromResult(SignInStatus.Success));
var controller = new AccountController { UserManager = UserManager, SignInManager = signInManager.Object, AuthenticationManager = authManager.Object};
// Act
var result = await controller.ExternalLoginCallback(null);
// Assert
Assert.Fail();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment