public async Task TestGetBlogMetadata() { BlogManager bm = new BlogManager(); var blogInfo = new BlogInfo { Name = "getblogmetadata" }; try { var response = bm.GetBlogMetadata(blogInfo, connString, contentFileRoot); Task.WaitAll(response); var responseInfo = (BlogInfo)response.Result; Assert.Null(responseInfo.Comments); // pass in null comments blogInfo.Comments = null; var comments = bm.Comments(blogInfo, connString, contentFileRoot); Task.WaitAll(comments); Assert.Null(comments.Result); blogInfo.Comments = "Hello world!"; comments = bm.Comments(blogInfo, connString, contentFileRoot); Task.WaitAll(comments); Assert.AreEqual("Hello world!", comments.Result); response = bm.GetBlogMetadata(blogInfo, connString, contentFileRoot); Task.WaitAll(response); responseInfo = (BlogInfo)response.Result; Assert.AreEqual("Hello world!", responseInfo.Comments); } finally { await bm.DeleteBlogIfExists(blogInfo, connString); } }
public static async Task <IActionResult> Comments( [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>(); string toRet = await bm.Comments(reqData, connString, contentFileRoot); return(new OkObjectResult(toRet)); } catch (Exception e) { Console.WriteLine(e); return(new ExceptionResult(e, true)); } }
public async Task TestComments() { BlogManager bm = new BlogManager(); var blogInfo = new BlogInfo { Name = "comments", Comments = "Hello world 1" }; try { var response = bm.Comments(blogInfo, connString, contentFileRoot); Task.WaitAll(response); Assert.AreEqual("Hello world 1", response.Result); blogInfo.Comments = "Hello world 2"; response = bm.Comments(blogInfo, connString, contentFileRoot); Task.WaitAll(response); Assert.AreEqual("Hello world 2Hello world 1", response.Result); } finally { await bm.DeleteBlogIfExists(blogInfo, connString); } }