public async Task TestAddLike()
        {
            BlogManager bm       = new BlogManager();
            var         blogInfo = new BlogInfo
            {
                Name  = "addlike",
                Likes = 2
            };

            try {
                var response = bm.Likes(blogInfo, connString, contentFileRoot);
                Task.WaitAll(response);
                Assert.AreEqual(2, response.Result);

                blogInfo.Likes = 1;
                response       = bm.Likes(blogInfo, connString, contentFileRoot);
                Task.WaitAll(response);
                Assert.AreEqual(3, response.Result);


                blogInfo.Likes = -1;
                response       = bm.Likes(blogInfo, connString, contentFileRoot);
                Task.WaitAll(response);
                Assert.AreEqual(2, response.Result);

                // Make like count go negative, the API should stop at 0
                blogInfo.Likes = -18;
                response       = bm.Likes(blogInfo, connString, contentFileRoot);
                Task.WaitAll(response);
                Assert.AreEqual(0, response.Result);
            }
            finally {
                await bm.DeleteBlogIfExists(blogInfo, connString);
            }
        }
Example #2
0
        public static async Task <IActionResult> UpdateLikes(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ExecutionContext context,
            ILogger log)
        {
            try
            {
                var reqBodyData = await GetRequestObject(req);

                string connString = ConfigReader.GetAppSettingOrDefault(
                    context,
                    "azurestorageconnstring",
                    null
                    ); string contentFileRoot = ConfigReader.GetAppSettingOrDefault(
                    context,
                    "contentfileroot",
                    null
                    );

                BlogManager bm = new BlogManager();

                BlogInfo reqData = reqBodyData.ToObject <BlogInfo>();
                int      toRet   = await bm.Likes(reqData,
                                                  connString,
                                                  contentFileRoot);

                return(new OkObjectResult(toRet));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(new ExceptionResult(e, true));
            }
        }