Example #1
0
        public void ProduceTweetText_LoopsThroughAllMessages()
        {
            var last = "";

            for (var x = 0; x < 12; x++)
            {
                var tf = TweetTextBuilder.ProduceTweetText("a", Guid.Empty);

                Console.WriteLine(tf);
                Assert.AreNotEqual(tf, last);
                last = tf;
            }
        }
        public HttpResponseMessage Post(UsedGuidInputModel ug)
        {
            // 1. screening of inputs / unit tested
            var initialCheck = DomainLogic.DetermineRequestValidity(ug);

            if (initialCheck.StatusCode != HttpStatusCode.OK)
            {
                // NOTE: initial check produces exactly what we need to return to API caller for failure cases
                return(initialCheck);
            }

            // 2. the main event THE guid colision check ;) / unit & integration testing
            if (_dataStore.GuidExistsAlready(ug.Guid))
            {
                return(DomainLogic.OhNoExistingGuid());
            }

            // 3. ok we're good to go it's a guid we haven't seen before
            try
            {
                if (_dataStore.SaveGuid(ug.Guid))
                {
                    // this is unit tested
                    var tweetText = TweetTextBuilder.ProduceTweetText(ug.UsedBy, ug.Guid);

                    // this is for integration testing
                    var publistTweetResult = _tweeter.PublishTweet(tweetText);

                    if (publistTweetResult.StatusCode != HttpStatusCode.OK)
                    {
                        return(publistTweetResult);
                    }
                }

                return(new HttpResponseMessage(HttpStatusCode.OK));
            }
            catch (Exception ex)
            {
                return(new HttpResponseMessage
                {
                    StatusCode = HttpStatusCode.InternalServerError,
                    ReasonPhrase = ex.Message
                });
            }
        }
Example #3
0
        public void ProduceTweetText_ReplacesBlankUsedBy(string expectedContents, string usedBy)
        {
            var result = TweetTextBuilder.ProduceTweetText(usedBy, Guid.Empty);

            Assert.That(result.Contains(expectedContents), $"ProduceTweetText didn't deal with '{Regex.Escape(usedBy ?? "")}'");
        }