public async Task Test_TwitterController_Pass() { //Arrange TwitterAuthModel twitterAuthModel = new TwitterAuthModel { APIKey = "<api key>" }; TwitterClient client = new TwitterClient(this.SecuritySettings, this.MockHttpClient.Object); TwitterAuthenticator authenticator = new TwitterAuthenticator(this.SecuritySettings.TwitterSecuritySettings, client); var controller = new TwitterController(authenticator); //Act var result = await controller.Create(twitterAuthModel); var twitterAccessToken = ((result as ObjectResult).Value as string); //Assert Assert.IsType <ObjectResult>(result); Assert.True(twitterAccessToken.IsValidJwtToken()); this.MockHttpClient.Verify(x => x.SendAsync <TwitterResponseModel>(It.IsAny <HttpRequestMessage>()), Times.Once); }
public async Task Test_TwitterController_NoAPIKey_Fail() { //Arrange //API Key absent TwitterAuthModel facebookAuthModel = new TwitterAuthModel(); TwitterClient client = new TwitterClient(this.SecuritySettings, this.MockHttpClient.Object); TwitterAuthenticator authenticator = new TwitterAuthenticator(this.SecuritySettings.TwitterSecuritySettings, client); var controller = new TwitterController(authenticator); try { //Act var result = await controller.Create(facebookAuthModel); } catch (SecurityException) { //Assert this.MockTwitterClient.Verify(x => x.PostSecurityRequest(), Times.Never); } }
public async Task Test_TwitterController_NoAuthorizationCode_Fail() { //Arrange //Authorization Code absent TwitterAuthModel twitterAuthModel = new TwitterAuthModel { APIKey = "<api key>" }; TwitterClient client = new TwitterClient(this.SecuritySettings, this.MockHttpClient.Object); TwitterAuthenticator authenticator = new TwitterAuthenticator(this.SecuritySettings.TwitterSecuritySettings, client); var controller = new TwitterController(authenticator); try { //Act var result = await controller.Create(twitterAuthModel); } catch (SecurityException ex) { //Assert Assert.IsType <SecurityException>(ex); this.MockTwitterClient.Verify(x => x.PostSecurityRequest(), Times.Never); } }
public async Task Test_TwitterController_TwitterAuth_Fail() { //Arrange //Twitter Client returns IsAuthenticated false this.MockTwitterClient = this.InitMockTwitterClient(this.SecuritySettings, false); TwitterAuthModel facebookAuthModel = new TwitterAuthModel { APIKey = "<api key>" }; TwitterAuthenticator authenticator = new TwitterAuthenticator(this.SecuritySettings.TwitterSecuritySettings, this.MockTwitterClient.Object); var controller = new TwitterController(authenticator); //Act var result = await controller.Create(facebookAuthModel); //Assert Assert.IsType <BadRequestResult>(result); this.MockTwitterClient.Verify(x => x.PostSecurityRequest(), Times.Once); }