You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.7 KiB

  1. using Microsoft.AspNetCore.Http;
  2. using Microsoft.AspNetCore.Http.Authentication;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Microsoft.eShopOnContainers.WebMVC.Controllers;
  5. using Moq;
  6. using System.Security.Claims;
  7. using Xunit;
  8. namespace UnitTest.Account
  9. {
  10. public class AccountControllerTest
  11. {
  12. private readonly Mock<HttpContext> _httpContextMock;
  13. public AccountControllerTest()
  14. {
  15. _httpContextMock = new Mock<HttpContext>();
  16. }
  17. /* TBD: Find a way to mock HttpContext GetTokenAsync method */
  18. //[Fact]
  19. //public void Signin_with_token_success()
  20. //{
  21. // //Arrange
  22. // var fakeCP = GenerateFakeClaimsIdentity();
  23. // var mockAuth = new Mock<AuthenticationManager>();
  24. // _httpContextMock.Setup(x => x.User)
  25. // .Returns(new ClaimsPrincipal(fakeCP));
  26. // _httpContextMock.Setup(c => c.Authentication)
  27. // .Returns(mockAuth.Object);
  28. // //Act
  29. // var accountController = new AccountController();
  30. // accountController.ControllerContext.HttpContext = _httpContextMock.Object;
  31. // var actionResult = accountController.SignIn("").Result;
  32. // //Assert
  33. // var redirectResult = Assert.IsType<RedirectToActionResult>(actionResult);
  34. // Assert.Equal(redirectResult.ActionName, "Index");
  35. // Assert.Equal(redirectResult.ControllerName, "Catalog");
  36. //}
  37. private ClaimsIdentity GenerateFakeClaimsIdentity()
  38. {
  39. var ci = new ClaimsIdentity();
  40. ci.AddClaim(new Claim("access_token", "fakeToken"));
  41. return ci;
  42. }
  43. }
  44. }