private async Task <bool> Login() { string errorString = ""; errorString += ErrorController.IsNull(Email, "Email"); errorString += ErrorController.IsEmail(Email, "Email"); errorString += ErrorController.IsNull(Password, "Password"); if (String.IsNullOrEmpty(errorString)) { UserController.SetLoginUserEmail(Email); errorString += await UserController.Login(Password); } if (!String.IsNullOrEmpty(errorString)) { Error = errorString; return(false); } else { await UserController.GetUserInfos(); await UserController.GetUserAccounts(); await TwitterController.SetToken(); return(true); } }
public void PostTweet_ShouldOnlyReplyOnce_Succeeds() { // Arrange var controller = new TwitterController(); var token = controller.GetAuthToken(OAuthConsumerKey, OAuthConsumerSecret); var applicationTweets = controller.GetApplicationTweets(token, HashTag); string lastId = "0"; foreach (var applicationTweet in applicationTweets) { var tweet = new SendTweetOptions { Status = String.Format("@{0} Thanks for applying! You'll receive a confirmation email shortly.", applicationTweet.in_reply_to_screen_name), InReplyToStatusId = Int64.Parse(applicationTweet.id_str), }; var actual = controller.PostTweet(token, tweet); lastId = applicationTweet.id_str; Assert.IsNotNull(actual); } applicationTweets = controller.GetApplicationTweets(token, HashTag, lastId); Assert.IsTrue(!applicationTweets.Any()); }
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); } }
protected override void OnStart(string[] args) { // Arrange var controller = new TwitterController(); var token = controller.GetAuthToken(OAuthConsumerKey, OAuthConsumerSecret); var applicationTweets = controller.GetApplicationTweets(token, HashTag); string lastId = "0"; using (var sr = new StreamReader(FileName)) { lastId = sr.ReadLine(); } foreach (var applicationTweet in applicationTweets) { var tweet = new SendTweetOptions { Status = String.Format("@{0} Thanks for applying! You'll receive a confirmation email shortly.", applicationTweet.in_reply_to_screen_name), InReplyToStatusId = Int64.Parse(applicationTweet.id_str), }; var actual = controller.PostTweet(token, tweet); lastId = applicationTweet.id_str; } using (var sw = new StreamWriter(FileName, false, Encoding.ASCII)) { sw.WriteLine(lastId); } }
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); } }
async Task ExecuteLoadTweetsCommand() { if (IsBusy) { return; } IsBusy = true; try { Tweets.Clear(); await TwitterController.GetTweets("熱ä¸ç—‡"); var tweets = TwitterController.GetTweetStatuses(); foreach (var t in tweets) { Tweet tweet = new Tweet(); tweet.Id = t["id"]; tweet.Name = t["user"]["name"]; tweet.Created = t["created_at"]; tweet.Text = t["text"]; tweet.Profile_image_url = t["user"]["profile_image_url"]; Tweets.Add(tweet); } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
public void loadGameLevel(int level) { senderName = FIXED_PABLO_NAME; imgUrl = FIXED_PABLO_IMAGE; bool isLiveFeed = false; TwitterController controller = GetComponent <TwitterController> (); if (level < defaultLevels.Length) { TextLevelHelper levelHelper = new TextLevelHelper(defaultLevels[level], senderName, FIXED_PABLO_IMAGE); if (!controller.isTweetsLoaded()) { controller.LoadTweets(); } if (controller.isAuthenticated && level % 2 == 1) { if (controller.tweets.Count > 0) { isLiveFeed = true; int index = Random.Range(0, controller.tweets.Count - 1); senderName = controller.tweets [index].username; imgUrl = controller.tweets [index].image; imgUrl = imgUrl.Replace("\\", ""); tokens = new List <string> (levelHelper.GetTokens(controller.tweets[index].text)); levelHelper.setUserId(senderName); controller.tweets.RemoveAt(index); } else { string[] newTokens = levelHelper.GetTokens(); tokens = new List <string> (newTokens); } } else { string[] newTokens = levelHelper.GetTokens(); if (newTokens != null) { tokens = new List <string> (newTokens); } } if (tokens == null || tokens.Count <= 0) { GetComponent <GameControler> ().Winning(); } else { StartCoroutine(GetComponent <GameControler> ().UpdateTwitterFeed(senderName, imgUrl, isLiveFeed)); isGameOver = false; SpawnNextPigeon(); } } else { GetComponent <GameControler> ().Winning(); } }
public async Task It_Should_Send_A_Tweet_When_A_Valid_Tweet_Object_Is_Sent(string message) { EnvironmentHelper.SetUpEnvironmentVariables(); Tweet tweet = new Tweet() { Text = message }; Assert.IsTrue(await TwitterController.ShareTweet(tweet)); }
public async Task It_Should_Not_Send_A_Tweet_When_A_Tweet_With_No_Text_Is_Sent() { EnvironmentHelper.SetUpEnvironmentVariables(); Tweet tweet = new Tweet() { Text = string.Empty }; Assert.IsTrue(await TwitterController.ShareTweet(tweet)); }
public Form1() { InitializeComponent(); settingController = new SettingController(new Setting(), new Users { UserNames = new List <string>() }); settingController.Road(); twitterController = new TwitterController(settingController.KeySetting); }
void CreateSingleton() { if (instance != null) { Destroy(gameObject); } else { instance = this; DontDestroyOnLoad(gameObject); } }
public TimelineStatus(Status stFrom, BasicAPI bAPI) { InitializeComponent(); m_bAPI = bAPI; m_bDisplayConversationButton = false; m_fntScreenNameFont = new Font("Arial", 10); m_fntRetweetedFont = new Font("Arial", 8); m_fntFromUser = new Font("Arial", 10, FontStyle.Bold); m_sbFromUser = new SolidBrush(Color.Black); m_sbRetweet = new SolidBrush(Color.FromArgb(70, 70, 70)); m_pnBorderPen = new Pen(Color.FromArgb(220, 220, 220)); m_stStatusObj = stFrom; ttfTextField.UpdateFromStatus(m_stStatusObj); Favorite = Boolean.Parse(m_stStatusObj["favorited"].ToString()); if (m_stStatusObj.IsRetweet) { if (m_stStatusObj.RetweetedStatus == null) { if ((m_stStatusObj.StatusText.Words.Count > 1) && (m_stStatusObj.StatusText.Words[1].Type == StatusTextElement.StatusTextElementType.ScreenName)) { m_sFromUser = m_stStatusObj.StatusText.Words[1].Text.Substring(1); new Thread(new ThreadStart(UserLookup)).Start(); } } else { m_sFromUser = m_stStatusObj.RetweetedStatus.User["screen_name"].ToString(); AsyncContentManager.GetManager().RequestImage(m_stStatusObj.RetweetedStatus.User["profile_image_url"].ToString(), AvatarCallback); } } else { m_sFromUser = m_stStatusObj.User["screen_name"].ToString(); AsyncContentManager.GetManager().RequestImage(m_stStatusObj.User["profile_image_url"].ToString(), AvatarCallback); } User uActiveUser = TwitterController.GetController().ActiveAccount.UserObject; if (uActiveUser != null) { Retweet = m_stStatusObj.IsRetweet && (m_sFromUser == TwitterController.GetController().ActiveAccount.UserObject["screen_name"].ToString()); } ttfTextField.TextElementClicked += new TweetTextField.TextElementClickHandler(ttfTextField_TextElementClicked); abRetweet.Click += new EventHandler(abRetweet_Click); abFavorite.Click += new EventHandler(abFavorite_Click); abReply.Click += new EventHandler(abReply_Click); abConversation.Click += new EventHandler(abConversation_Click); }
public void GetAuthToken_WithValidCredentials_ReturnsToken() { // Arrange var controller = new TwitterController(); // Act var actual = controller.GetAuthToken(OAuthConsumerKey, OAuthConsumerSecret); // Assert Assert.IsFalse(actual.access_token.IsEmpty()); Assert.IsFalse(actual.token_type.IsEmpty()); Debug.WriteLine("Token - {0}, Type - {1}", actual.access_token, actual.token_type); }
public void GetTweet_WithValidCredentials_ReturnsTweet() { // Arrange var controller = new TwitterController(); var token = controller.GetAuthToken(OAuthConsumerKey, OAuthConsumerSecret); // Act var actual = controller.GetTweet(token, "474387738603450368"); actual.DebugPrint(); Assert.IsNotNull(actual); }
public static async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Function, "post", Route = null)] HttpRequest req, ILogger log) { log.LogWarning("We called it!!"); string requestBody = await new StreamReader(req.Body).ReadToEndAsync(); if (!string.IsNullOrEmpty(requestBody)) { var postData = JsonConvert.DeserializeObject <SharedPostData>(requestBody); if (string.IsNullOrEmpty(postData.PostContent)) { return(new BadRequestObjectResult("Pass in a value for the Property PostContent")); } if (string.IsNullOrEmpty(postData.Url)) { return(new BadRequestObjectResult("Pass in a value for the Property PostUrl")); } bool successfullySharedPost = false; switch (postData.IntegrationType) { case IntegrationTypes.Twitter: successfullySharedPost = await TwitterController.ShareTweet(postData.ToTweet()); break; case IntegrationTypes.Both: successfullySharedPost = await TwitterController.ShareTweet(postData.ToTweet()); break; } if (successfullySharedPost) { return(new OkObjectResult("All good")); } else { return(new BadRequestObjectResult("There was an issure with sharing your post")); } } return(new BadRequestObjectResult("Pass in a request body.")); }
public void Should_throw_exception_if_configuration_is_null() { try { var controllerWithNullAruguments = new TwitterController(_twitterViewModel, _twitterSettingsViewModel, null, _timerMock.Object, new NoUIInvokation(), _tweetFetcherMock.Object, new Mock<IProgressbar>().Object); Assert.IsFalse(true); } catch (ArgumentException e) { Assert.IsTrue(true); } }
public void GetApplicationTweets_WithValidCredentialsAndSinceId_ReturnsApplicationTweets() { // Arrange var controller = new TwitterController(); var token = controller.GetAuthToken(OAuthConsumerKey, OAuthConsumerSecret); var sinceId = "474433228799897600"; //Act var actual = controller.GetApplicationTweets(token, HashTag, sinceId); // Assert Assert.IsNotNull(actual); }
public void GetApplicationTweets_WithValidCredentials_ReturnsApplicationTweets() { // Arrange var controller = new TwitterController(); var token = controller.GetAuthToken(OAuthConsumerKey, OAuthConsumerSecret); var hashTag = "%23HackApply"; //Act var actual = controller.GetApplicationTweets(token, hashTag); // Assert Assert.IsTrue(actual.Any()); }
public void PostTweet_WithValidCredentials_Succeeds() { // Arrange var controller = new TwitterController(); var token = controller.GetAuthToken(OAuthConsumerKey, OAuthConsumerSecret); var tweet = new SendTweetOptions { Status = "Hacking #HackApply-" + DateTime.Now.Millisecond }; var actual = controller.PostTweet(token, tweet); Assert.IsNotNull(actual); }
public void GetCandidate_WithValidTwitterId_ReturnsCandidate() { // Arrange var controller = new TwitterController(); var twitterUserId = 30381775; //Tweet username: derflawss //Act var actual = controller.GetCandidate(twitterUserId); // Assert Assert.IsTrue(actual.FirstName == "Alfred"); Assert.IsTrue(actual.FirstName == "Samasoni"); Assert.IsTrue(actual.CandidateId > 0); }
private void CallGetTweets() { //Function to get tweets TwitterController twitter = new TwitterController(); DataTable dtRepeater = twitter.GetTwitts("salesforce", 10); if (dtRepeater != null) { Session["Tweets"] = dtRepeater; //Storing the tweet datatable into session for filtering later during search rpttweet.DataSource = dtRepeater; rpttweet.DataBind(); } else { Session["Error"] = "No tweet found for user @salesforce"; Response.Redirect("ErrorPage.aspx"); } }
//[ExpectedException(typeof (ArgumentException))] public void Should_throw_exception_if_viewModel_is_null() { //This try/catch is used instead of the [ExpectedExce... above because //the test runner complains about unhandled exceptions if one uses it. try { var controllerWithNullAruguments = new TwitterController(null, _twitterSettingsViewModel, defaultConfiguration, _timerMock.Object, new NoUIInvokation(), _tweetFetcherMock.Object, new Mock<IProgressbar>().Object); Assert.IsFalse(true); } catch(ArgumentException e) { Assert.IsTrue(true); } }
void Awake() { Instance = this; DontDestroyOnLoad(this.gameObject); // FacebookManager.sessionOpenedEvent += fbsessionOpenedEvent; // FacebookManager.loginFailedEvent += fbloginFailedEvent; TwitterManager.loginSucceededEvent += twitterloginSucceeded; TwitterManager.loginFailedEvent += twitterloginFailed; analyticsHandler = AnalyticsController.Instance; fbHandler = FacebookController.Instance; twitterHandler = TwitterController.Instance; admobHandler = AdmobController.Instance; AdmobController.Instance.RequestBanner(); AdmobController.Instance.RequestInterstitial(); }
public void When_Call_Index_Action_Should_Return_Valid_Model() { var expected = new Models.LoginModel() { Email = "*****@*****.**", Password = "******", Source = "Twitter" }; var service = new TwitterAuthentication(); var tenantIdStrategy = new RequestParameterTenantIdentificationStrategy("tenant"); var controller = new TwitterController(service, tenantIdStrategy); var actionResult = controller.Index(); var viewResult = actionResult as ViewResult; var actual = viewResult.ViewData.Model as Models.LoginModel; Assert.AreEqual(expected.Email, actual.Email); Assert.AreEqual(expected.Password, actual.Password); Assert.AreEqual(expected.Source, actual.Source); }
public void GetTweetsWithHashTags_WithValidCredentials_ReturnsAllTweets() { // Arrange var controller = new TwitterController(); var token = controller.GetAuthToken(OAuthConsumerKey, OAuthConsumerSecret); // Act var result = controller.GetTweetsWithHashTag(token, HashTag); foreach (var s in result.statuses) { s.DebugPrint(); } // Assert Assert.IsNotNull(result); }
public void PostTweet_InReplyOfApplicationTweet_Succeeds() { // Arrange var controller = new TwitterController(); var token = controller.GetAuthToken(OAuthConsumerKey, OAuthConsumerSecret); var applicationTweets = controller.GetApplicationTweets(token, HashTag); foreach (var applicationTweet in applicationTweets) { var guid = DateTime.Now.ToLongTimeString(); var tweet = new SendTweetOptions { Status = String.Format("@{0} Thanks for applying! You'll receive a confirmation email shortly.{1}", applicationTweet.in_reply_to_screen_name, guid), InReplyToStatusId = Int64.Parse(applicationTweet.id_str), }; var actual = controller.PostTweet(token, tweet); Assert.IsNotNull(actual); } }
protected void Application_Error(object sender, EventArgs e) { //skip error handling if it disabled in config if (GetCustomErrorSection().Mode == CustomErrorsMode.Off) { return; } HttpContext ctx = HttpContext.Current; //Exception ex = ctx.Server.GetLastError(); ctx.Response.Clear(); ControllerContext context; var controller = new TwitterController(); // here we can use any controller var handler = ctx.CurrentHandler as MvcHandler; if (handler == null) { //in case of FileNotFound or other handlers var routeData = new RouteData(); routeData.Values.Add("controller", "twitter"); context = new ControllerContext(new RequestContext(new HttpContextWrapper(Context), routeData), new TwitterController()); } else { context = new ControllerContext(handler.RequestContext, controller); } var viewResult = new ViewResult { ViewName = "Error" }; viewResult.ExecuteResult(context); ctx.Server.ClearError(); }
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); }
protected void CreateController() { _controller = new TwitterController( _twitterViewModel, _twitterSettingsViewModel, defaultConfiguration, _timerMock.Object, new NoUIInvokation(), _tweetFetcherMock.Object, _progressbarMock.Object); }
public async Task RandomTweet([Remainder] string twitterAccount) { var tweetMsg = TwitterController.GetUsersRandomTweet(twitterAccount); await ReplyAsync(string.Format(Resources.response_Twitter_User, twitterAccount, tweetMsg)); }
public async Task Headline() { var tweetMsg = TwitterController.GetUsersLatestTweet("guardian"); await ReplyAsync(tweetMsg); }
public async Task Gazo() { var tweetMsg = TwitterController.GetUsersRandomTweet("idol_gazo"); await ReplyAsync(tweetMsg); }