public async Task Test_FacebookController_NoUserToken_Fail() { //Arrange //Facebook User Token absent FacebookAuthModel facebookAuthModel = new FacebookAuthModel(); FacebookAuthenticator authenticator = new FacebookAuthenticator(this.MockFacebookClient.Object); var securityService = new SecurityService <FacebookAuthModel>(this.SecuritySettings); var controller = new FacebookController(securityService, authenticator); try { //Act var result = await controller.Create(facebookAuthModel); } catch (SecurityException ex) { //Assert Assert.IsType <SecurityException>(ex); this.MockFacebookClient.Verify(x => x.PostSecurityRequest(facebookAuthModel), Times.Never); } }
public async Task Test_FacebookController_Pass() { //Arrange FacebookAuthModel facebookAuthModel = new FacebookAuthModel { UserAccessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }; var client = new FacebookClient(this.SecuritySettings, this.MockHttpClient.Object); FacebookAuthenticator authenticator = new FacebookAuthenticator(client); var securityService = new SecurityService <FacebookAuthModel>(this.SecuritySettings); var controller = new FacebookController(securityService, authenticator); //Act var result = await controller.Create(facebookAuthModel); //Assert Assert.IsType <ObjectResult>(result); Assert.True((result as ObjectResult).Value.ToString().IsValidJwtToken()); this.MockHttpClient.Verify(x => x.GetStringAsync <FacebookAppAccessToken>(It.IsAny <string>()), Times.Once); this.MockHttpClient.Verify(x => x.GetStringAsync <FacebookUserAccessTokenValidation>(It.IsAny <string>()), Times.Once); }
public async Task Test_FacebookController_FacebookAuth_Fail() { //Arrange //Facebook Client returns IsAuthenticated false this.MockFacebookClient = this.InitMockFacebookClient(this.SecuritySettings, false); FacebookAuthModel facebookAuthModel = new FacebookAuthModel { UserAccessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" }; FacebookAuthenticator authenticator = new FacebookAuthenticator(this.MockFacebookClient.Object); var securityService = new SecurityService <FacebookAuthModel>(this.SecuritySettings); var controller = new FacebookController(securityService, authenticator); //Act var result = await controller.Create(facebookAuthModel); //Assert Assert.IsType <BadRequestResult>(result); this.MockFacebookClient.Verify(x => x.PostSecurityRequest(facebookAuthModel), Times.Once); }