public void SendError(ScoreInfo invalidScore, UnrecognisedTokenException exception) { try { var sendNotifications = bool.Parse(ConfigurationManager.AppSettings["SendNotifications"]); if (!sendNotifications) return; var user = new TokenUser(TokenSingleton.Token); var tweet = string.Format("@{0} Unrecognised token: \"{1}\". Language spec: http://t.co/mESKiN9qSS", invalidScore.Username, exception.Message.Length > tokenLength ? exception.Message.Substring(0, tokenLength) : exception.Message); user.PublishTweet(tweet); } catch (Exception) { // ToDo: implement UI notifications } }
public void SubmitterIsNotifiedOfInvalidScore() { var invalidScore = new ScoreInfo { Id = 123, TextScore = "BadScore", Username = "******" }; var expectedException = new UnrecognisedTokenException("Invalid Token"); interpreter.Setup(i => i.Interpret(invalidScore.TextScore)).Throws(expectedException); queue.ScoreReceived(invalidScore); notifications.Verify(n => n.SendError(invalidScore, expectedException), Times.Once()); Assert.That(queue.Tweets, Is.Empty); }