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));
        }
Esempio n. 3
0
        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."));
        }