public async Task TestCase1(string user)
        {
            var context = this.fixture.GetCurrentDataContext();

            fixture.InitBlogTestData(context);

            var control   = new BlogUserSettingsController(context);
            var userclaim = DataSetupUtility.GetClaimForUser(user);
            var httpctx   = UnitTestUtility.GetDefaultHttpContext(provider, userclaim);

            control.ControllerContext = new ControllerContext()
            {
                HttpContext = httpctx
            };

            var existedamt = (from coll in context.BlogUserSettings where coll.Owner == user select coll).ToList().Count();

            // Step 1. Read all
            var rsts    = control.Get();
            var rstscnt = await rsts.CountAsync();

            Assert.Equal(existedamt, rstscnt);

            // Step 2. Create one new collection
            var nset = new BlogUserSetting()
            {
                Owner        = user,
                Name         = "Test Setting",
                Comment      = "Test Comment",
                DeployFolder = "Test"
            };
            var rst = await control.Post(nset);

            Assert.NotNull(rst);
            Assert.IsType <ForbidResult>(rst);

            // Step 3. Update one
            if (rstscnt > 0)
            {
                var existsett = control.Get(user);
                Assert.NotNull(existsett);
                var existsett2 = Assert.IsType <SingleResult <BlogUserSetting> >(existsett);
                Assert.NotNull(existsett2);
                var existsett2rst = existsett2.Queryable.FirstOrDefault();
                existsett2rst.Comment     = "Tobe Delteed";
                existsett2rst.Author      = "Author";
                existsett2rst.AuthorDesp  = "Author Desp";
                existsett2rst.AuthorImage = "Author Image";
                var rst3 = await control.Put(existsett2rst.Owner, existsett2rst);

                Assert.NotNull(rst3);
                var rst3a = Assert.IsType <OkObjectResult>(rst3);
                var rst3b = rst3a.Value as BlogUserSetting;
                Assert.Equal(existsett2rst.Comment, rst3b.Comment);
                Assert.Equal(existsett2rst.Author, rst3b.Author);
                Assert.Equal(existsett2rst.AuthorDesp, rst3b.AuthorDesp);
                Assert.Equal(existsett2rst.AuthorImage, rst3b.AuthorImage);
            }

            await context.DisposeAsync();
        }
        public async Task TestCase1(string user)
        {
            var context = this.fixture.GetCurrentDataContext();

            fixture.InitBlogTestData(context);

            var control   = new BlogCollectionsController(context);
            var userclaim = DataSetupUtility.GetClaimForUser(user);
            var httpctx   = UnitTestUtility.GetDefaultHttpContext(provider, userclaim);

            control.ControllerContext = new ControllerContext()
            {
                HttpContext = httpctx
            };

            var existedamt = (from coll in context.BlogCollections where coll.Owner == user select coll).ToList().Count();

            // Step 1. Read all
            var rsts    = control.Get();
            var rstscnt = await rsts.CountAsync();

            Assert.Equal(existedamt, rstscnt);

            // Step 2. Create one new collection
            var newcoll = new BlogCollection()
            {
                Owner   = user,
                Name    = "TestCase1_Add_" + user,
                Comment = "TestCase1_Add_" + user,
            };
            var rst = await control.Post(newcoll);

            Assert.NotNull(rst);
            var rst2 = Assert.IsType <CreatedODataResult <BlogCollection> >(rst);

            objectsCreated.Add(rst2.Entity.ID);
            newcoll.ID = rst2.Entity.ID;
            Assert.Equal(rst2.Entity.Name, newcoll.Name);
            Assert.Equal(rst2.Entity.Comment, newcoll.Comment);
            Assert.Equal(rst2.Entity.Owner, user);

            // Step 3. Read all
            rsts    = control.Get();
            rstscnt = await rsts.CountAsync();

            Assert.Equal(existedamt + 1, rstscnt);

            // Step 4. Change it
            newcoll.Name = "Tobe Delteed";
            var rst3 = await control.Put(newcoll.ID, newcoll);

            Assert.NotNull(rst3);
            var rst3a = Assert.IsType <UpdatedODataResult <BlogCollection> >(rst3);

            Assert.Equal(newcoll.Name, rst3a.Entity.Name);

            // Step 5. Delete it
            var rst5 = await control.Delete(newcoll.ID);

            Assert.NotNull(rst5);
            objectsCreated.Remove(newcoll.ID);
            var rst5a = Assert.IsType <StatusCodeResult>(rst5);

            Assert.Equal(204, rst5a.StatusCode);

            // Step 6. Read it again
            rsts    = control.Get();
            rstscnt = await rsts.CountAsync();

            Assert.Equal(existedamt, rstscnt);

            await context.DisposeAsync();
        }
        public async Task TestCase1(string user)
        {
            var context = this.fixture.GetCurrentDataContext();

            fixture.InitBlogTestData(context);

            var control   = new BlogPostsController(context);
            var userclaim = DataSetupUtility.GetClaimForUser(user);
            var httpctx   = UnitTestUtility.GetDefaultHttpContext(provider, userclaim);

            control.ControllerContext = new ControllerContext()
            {
                HttpContext = httpctx
            };

            var existedcoll = (from coll in context.BlogCollections where coll.Owner == user select coll).ToList();
            var existedamt  = (from coll in context.BlogPosts where coll.Owner == user select coll).ToList().Count();

            // Step 1. Read all
            var rsts    = control.Get();
            var rstscnt = await rsts.CountAsync();

            Assert.Equal(existedamt, rstscnt);

            // Step 2. Create one new post
            var newpost = new BlogPost()
            {
                Owner   = user,
                Title   = "TestCase1_Add_" + user,
                Brief   = "TestCase1_Add_" + user,
                Content = "TestCase1_Add_" + user,
            };
            var rst = await control.Post(newpost);

            Assert.NotNull(rst);
            var rst2 = Assert.IsType <CreatedODataResult <BlogPost> >(rst);

            objectsCreated.Add(rst2.Entity.ID);
            newpost.ID = rst2.Entity.ID;
            Assert.Equal(rst2.Entity.Title, newpost.Title);
            Assert.Equal(rst2.Entity.Brief, newpost.Brief);
            Assert.Equal(rst2.Entity.Content, newpost.Content);
            Assert.Equal(rst2.Entity.Owner, user);

            // Step 3. Read all
            rsts    = control.Get();
            rstscnt = await rsts.CountAsync();

            Assert.Equal(existedamt + 1, rstscnt);

            // Step 4. Change it - Title and Add new tag
            newpost.Title = "Tobe Delteed";
            newpost.BlogPostTags.Add(new BlogPostTag
            {
                Tag    = "Test",
                PostID = newpost.ID,
            });
            var rst3 = await control.Put(newpost.ID, newpost);

            Assert.NotNull(rst3);
            var rst3a = Assert.IsType <OkObjectResult>(rst3);
            var rst3b = rst3a.Value as BlogPost;

            Assert.Equal(newpost.Title, rst3b.Title);
            Assert.True(rst3b.BlogPostTags.Count == 1);
            Assert.Equal("Test", rst3b.BlogPostTags.ElementAt(0).Tag);

            // Step 4a. Change it - Remove tag and add two new tags
            newpost.BlogPostTags.Clear();
            newpost.BlogPostTags.Add(new BlogPostTag
            {
                Tag    = "Test2",
                PostID = newpost.ID,
            });
            newpost.BlogPostTags.Add(new BlogPostTag
            {
                Tag    = "Test2a",
                PostID = newpost.ID,
            });
            rst3 = await control.Put(newpost.ID, newpost);

            Assert.NotNull(rst3);
            rst3a = Assert.IsType <OkObjectResult>(rst3);
            rst3b = rst3a.Value as BlogPost;
            Assert.Equal(newpost.Title, rst3b.Title);
            Assert.True(rst3b.BlogPostTags.Count == 2);
            Assert.Equal("Test2", rst3b.BlogPostTags.ElementAt(0).Tag);
            Assert.Equal("Test2a", rst3b.BlogPostTags.ElementAt(1).Tag);

            // Step 4b. Change it - add new collection
            if (existedcoll.Count > 0)
            {
                newpost.BlogPostCollections.Add(new BlogPostCollection
                {
                    PostID       = newpost.ID,
                    CollectionID = existedcoll[0].ID
                });
                rst3 = await control.Put(newpost.ID, newpost);

                Assert.NotNull(rst3);
                rst3a = Assert.IsType <OkObjectResult>(rst3);
                rst3b = rst3a.Value as BlogPost;
                Assert.Equal(newpost.Title, rst3b.Title);
                Assert.True(rst3b.BlogPostTags.Count == 2);
                Assert.True(rst3b.BlogPostCollections.Count == 1);
                Assert.Equal(existedcoll[0].ID, rst3b.BlogPostCollections.ElementAt(0).CollectionID);

                if (existedcoll.Count > 1)
                {
                    newpost.BlogPostCollections.Clear();
                    newpost.BlogPostCollections.Add(new BlogPostCollection
                    {
                        PostID       = newpost.ID,
                        CollectionID = existedcoll[1].ID
                    });
                    rst3 = await control.Put(newpost.ID, newpost);

                    Assert.NotNull(rst3);
                    rst3a = Assert.IsType <OkObjectResult>(rst3);
                    rst3b = rst3a.Value as BlogPost;
                    Assert.Equal(newpost.Title, rst3b.Title);
                    Assert.True(rst3b.BlogPostTags.Count == 2);
                    Assert.True(rst3b.BlogPostCollections.Count == 1);
                    Assert.Equal(existedcoll[1].ID, rst3b.BlogPostCollections.ElementAt(0).CollectionID);
                }
            }

            // Step 5. Delete it
            var rst5 = await control.Delete(newpost.ID);

            Assert.NotNull(rst5);
            objectsCreated.Remove(newpost.ID);
            var rst5a = Assert.IsType <StatusCodeResult>(rst5);

            Assert.Equal(204, rst5a.StatusCode);

            // Step 6. Read it again
            rsts    = control.Get();
            rstscnt = await rsts.CountAsync();

            Assert.Equal(existedamt, rstscnt);

            await context.DisposeAsync();
        }