Ejemplo n.º 1
0
        public void TwitterConformance()
        {
            // Arrange
            var testCases = new Dictionary <string, int>
            {
                { "This is a test.", 15 },
                { "http://test.com", 23 },
                { "https://test.com", 23 },
                { "test.com", 23 },
                { "Test https://test.com test https://test.com test.com test", 86 },

                // FIXME: This results in 4 :(
                //{"\U00010000\U0010ffff", 2},
                { "저찀쯿쿿", 4 },
                { "H\U0001f431☺", 3 }
            };

            // Act
            var results = testCases.ToDictionary(kvp => kvp.Key, kvp => TwitterHelper.CountCharacters(kvp.Key, MockConfig()));

            // Assert
            foreach (var str in testCases.Keys)
            {
                Assert.AreEqual(testCases[str], results[str], str);
            }
        }
Ejemplo n.º 2
0
        public void SimpleAsciiTextHasSimpleLength()
        {
            // Arrange
            var testCases = new Dictionary <int, string>();
            var rand      = new Random();

            for (int i = 1; i < 140; ++i)
            {
                var sb = new StringBuilder();
                for (int n = 0; n < i; ++n)
                {
                    bool upper = rand.Next(0, 1) == 1;
                    sb.Append((char)((upper
                                                ? 'A'
                                                : 'a') + rand.Next(0, 27)));
                }

                testCases.Add(i, sb.ToString());
            }

            // Act
            var results = testCases.ToDictionary(kvp => kvp.Key, kvp => TwitterHelper.CountCharacters(kvp.Value, MockConfig()));

            // Assert
            foreach (int l in testCases.Keys)
            {
                Assert.AreEqual(l, results[l]);
            }
        }
Ejemplo n.º 3
0
        private void UpdateTextLength()
        {
            var len = TwitterHelper.CountCharacters(Text, TwitterConfig);

            if (QuotedTweet != null)
            {
                // Keep the space in mind that separates the tweet text and the status URL
                len += TwitterConfig.UrlLengthHttps + 1;
            }
            TextLength = len;
        }
Ejemplo n.º 4
0
        public void EmptyStringHasZeroLength()
        {
            // Arrange
            var str = string.Empty;

            // Act
            int count = TwitterHelper.CountCharacters(str, MockConfig());

            // Assert
            Assert.AreEqual(0, count);
        }
Ejemplo n.º 5
0
        public void ValidTweetLessThan20Chars()
        {
            // Arrange
            var str = "I am a Tweet";

            // Act
            int count = TwitterHelper.CountCharacters(str, MockConfig());

            // Assert
            Assert.AreEqual(12, count);
        }
Ejemplo n.º 6
0
        public void TwitterExampleIsCountedCorrectly()
        {
            // Arrange
            var str = "café";

            // Act
            int count = TwitterHelper.CountCharacters(str, MockConfig());

            // Assert
            Assert.AreEqual(4, count);
        }
Ejemplo n.º 7
0
        public void InvalidTweet141CharsNewLine()
        {
            // Arrange
            var str =
                "A lie gets halfway around the world before the truth has a chance to get its pants on. \n- Winston Churchill (1874-1965) http://bit.ly/dJpywL";

            // Act
            int count = TwitterHelper.CountCharacters(str, MockConfig());

            // Assert
            Assert.IsTrue(count > 140);
        }
Ejemplo n.º 8
0
        public void ValidTweet140CharsWithAccent()
        {
            // Arrange
            var str =
                "A lié géts halfway arøünd thé wørld béføré thé truth has a chance tø get its pants øn. Winston Churchill (1874-1965) http://bit.ly/dJpywL";

            // Act
            int count = TwitterHelper.CountCharacters(str, MockConfig());

            // Assert
            Assert.AreEqual(140, count);
        }
Ejemplo n.º 9
0
        public void ValidTweet140CharsDoubleWord()
        {
            // Arrange
            var str =
                "\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431\U0001f431";

            // Act
            int count = TwitterHelper.CountCharacters(str, MockConfig());

            // Assert
            Assert.AreEqual(140, count);
        }
Ejemplo n.º 10
0
        public void ValidTweet140Chars()
        {
            // Arrange
            var str =
                "A lie gets halfway around the world before the truth has a chance to get its pants on. Winston Churchill (1874-1965) http://bit.ly/dJpywL";

            // Act
            int count = TwitterHelper.CountCharacters(str, MockConfig());

            // Assert
            Assert.AreEqual(140, count);
        }
Ejemplo n.º 11
0
        public void ValidTweet140CharsDoubleByte()
        {
            // Arrange
            const string str =
                "のののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののののの";

            // Act
            int count = TwitterHelper.CountCharacters(str, MockConfig());

            // Assert
            Assert.AreEqual(140, count);
        }
Ejemplo n.º 12
0
        private bool CanExecuteSendTweetCommand()
        {
            if (IsSending)
            {
                return(false);
            }

            if (string.IsNullOrWhiteSpace(Text))
            {
                return(false);
            }

            if (!Accounts.Any(a => a.Use))
            {
                return(false);
            }

            if (ConfirmationRequired && !ConfirmationSet)
            {
                return(false);
            }

            return(TwitterHelper.CountCharacters(Text, TwitterConfig) <= Constants.Twitter.MaxTweetLength);
        }