public async Task LoginWithFacebookAsync_ShouldSignIn_WhenUserExists() { var accessToken = "EAABw3KiLV1QBACrZCNuvHBaijiPEURQzAhVqZCG"; var facebookTokenValidationResult = new FacebookTokenValidationResult { FacebookTokenValidationData = new FacebookTokenValidationData { IsValid = true } }; var facebookInfoResult = new FacebookUserInfoResult { Id = Guid.NewGuid().ToString(), FirstName = "test", LastName = "user", Email = "*****@*****.**", }; _facebookAuthService.ValidateAccessTokenAsync(accessToken).Returns(facebookTokenValidationResult); _facebookAuthService.GetUserInfoAsync(accessToken).Returns(facebookInfoResult); var user = new User(facebookInfoResult.Email, facebookInfoResult.Email); _userRepository.GetByEmailAsync(facebookInfoResult.Email).Returns(user); var jwtDto = _fixture.Create <JwtDto>(); _jwtHandler.CreateToken(Arg.Any <int>(), Arg.Any <string>(), Arg.Any <string>()).Returns(jwtDto); var refreshToken = _fixture.Create <RefreshToken>(); var jwt = await _sut.LoginWithFacebookAsync(accessToken); jwt.ShouldNotBeNull(); jwt.ShouldBeOfType(typeof(JwtDto)); jwt.UserId.ShouldBe(jwtDto.UserId); jwt.Username.ShouldBe(jwtDto.Username); jwt.Role.ShouldBe(jwtDto.Role); jwt.AccessToken.ShouldBe(jwtDto.AccessToken); jwt.Expires.ShouldBe(jwtDto.Expires); jwt.RefreshToken.ShouldBe(jwtDto.RefreshToken); }
public async Task LoginWithFacebookAsync_ShouldThrowException_WhenTokenIsNotValid() { var accessToken = "EAABw3KiLV1QBACrZCNuvHBaijiPEURQzAhVqZCG"; var facebookTokenValidationResult = new FacebookTokenValidationResult { FacebookTokenValidationData = new FacebookTokenValidationData { IsValid = false } }; _facebookAuthService.ValidateAccessTokenAsync(accessToken).Returns(facebookTokenValidationResult); var exception = await Record.ExceptionAsync(() => _sut.LoginWithFacebookAsync(accessToken)); exception.ShouldNotBeNull(); exception.ShouldBeOfType(typeof(InvalidFacebookTokenException)); exception.Message.ShouldBe("Invalid facebook token."); }