Ejemplo n.º 1
0
        public static async Task <IActionResult> MinsToRead(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            ExecutionContext context,
            ILogger log)
        {
            try
            {
                JArray reqBodyData = await GetRequestArray(req);

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

                BlogManager bm = new BlogManager();

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

                return(new OkObjectResult(toRet));
            }
            catch (Exception e)
            {
                return(new ExceptionResult(e, true));
            }
        }
Ejemplo n.º 2
0
        public async Task TestWithInvalidPath()
        {
            BlogManager     bm        = new BlogManager();
            List <BlogInfo> blogInfos = new List <BlogInfo>();

            try {
                blogInfos.Add(new BlogInfo
                {
                    Name = "invalid",
                    Path = "thiswontwork"
                });
                var except = Assert.Throws <AggregateException>(() =>
                {
                    var response = bm.GetMinsToRead(blogInfos, connString, contentFileRoot);
                    Task.WaitAll(response);
                });
                StringAssert.Contains("An invalid request URI was provided.", except.Message);
            }
            finally {
                foreach (var blog in blogInfos)
                {
                    await bm.DeleteBlogIfExists(blog, connString);
                }
            }
        }
Ejemplo n.º 3
0
        public async Task TestMultipleFileNames()
        {
            BlogManager     bm        = new BlogManager();
            List <BlogInfo> blogInfos = new List <BlogInfo>();

            try {
                blogInfos.Add(new BlogInfo
                {
                    Name = "fivehundredwords"
                });
                blogInfos.Add(new BlogInfo
                {
                    Name = "empty"
                });
                var response = bm.GetMinsToRead(blogInfos, connString, contentFileRoot);
                Task.WaitAll(response);
                Assert.AreEqual(2, response.Result.Count);
                Assert.AreEqual("1", response.Result[0].MinsToRead);
                Assert.AreEqual("fivehundredwords", response.Result[0].Name);
            }
            finally {
                foreach (var blog in blogInfos)
                {
                    await bm.DeleteBlogIfExists(blog, connString);
                }
            }
        }
Ejemplo n.º 4
0
        public void TestNullName()
        {
            BlogManager     bm        = new BlogManager();
            List <BlogInfo> blogInfos = new List <BlogInfo>();

            blogInfos.Add(new BlogInfo
            {
            });
            var except = Assert.Throws <AggregateException>(() =>
            {
                var response = bm.GetMinsToRead(blogInfos, connString, contentFileRoot);
                Task.WaitAll(response);
            });

            StringAssert.Contains("Pass in a unique blogname in the list of names", except.Message);
        }
Ejemplo n.º 5
0
        public async Task TestSingleEmptyFile_NoPath()
        {
            BlogManager     bm        = new BlogManager();
            List <BlogInfo> blogInfos = new List <BlogInfo>();

            try {
                blogInfos.Add(new BlogInfo
                {
                    Name = "empty"
                });
                var response = bm.GetMinsToRead(blogInfos, connString, contentFileRoot);
                Task.WaitAll(response);
                Assert.AreEqual(1, response.Result.Count);
                Assert.AreEqual("0", response.Result[0].MinsToRead);
                Assert.AreEqual("empty", response.Result[0].Name);
            }
            finally {
                foreach (var blog in blogInfos)
                {
                    await bm.DeleteBlogIfExists(blog, connString);
                }
            }
        }