コード例 #1
0
        public void CreateBlogWith_ExistingPosts()
        {
            ICreateOrUpdateService <BloggingContext, Blog> createOrUpdateService = new CreateOrUpdateService <BloggingContext, Blog>(this._context);
            var result = createOrUpdateService.CreateOrUpdate(new BlogWithPostsCreateDto
            {
                Name  = "Test Create2",
                Url   = "https://www.usc.edu",
                Posts = new List <PostDto>()
                {
                    new PostDto {
                        PostId = 1, Title = "TestTitle1", Content = "TestContent1"
                    },
                }
            }, ActionFlags.Create);

            Assert.True(result.IsValid);
            Assert.NotEqual(0, result.Result.BlogId);
            var entity = this._context.Blogs.Where(x => x.BlogId == result.Result.BlogId).First();

            Assert.Equal("Test Create2", result.Result.Name);
            Assert.Equal(1, result.Result.Posts[0].PostId);
            Assert.Equal(DateTime.MaxValue, entity.Posts.ToList()[0].UpdatedDate);
            Assert.Equal(1, entity.Posts.ToList()[0].NumberOfEditted);
            Assert.Equal(1, entity.Posts.Count);
        }
コード例 #2
0
        public void UpdateBlogWithPosts_WithExistingPosts()
        {
            ICreateOrUpdateService <BloggingContext, Blog> CreateOrUpdateService = new CreateOrUpdateService <BloggingContext, Blog>(this._context);
            var result = CreateOrUpdateService.CreateOrUpdate(new BlogWithPostsCreateDto
            {
                BlogId = 1,
                Name   = "Test Update2",
                Url    = "https://www.usc.edu",
                Posts  = new List <PostDto>()
                {
                    new PostDto {
                        PostId = 1, Title = "TestTitle1", Content = "TestContent1"
                    },
                    new PostDto {
                        PostId = 2, Title = "TestTitle2", Content = "TestContent2"
                    },
                    new PostDto {
                        Title = "TestTitle3", Content = "TestContent3"
                    },
                }
            }, ActionFlags.Update);

            Assert.True(result.IsValid);
            Assert.Equal(1, result.Result.BlogId);
            var entity = this._context.Blogs.Where(x => x.BlogId == 1).First();

            Assert.Equal("Test Update2", result.Result.Name);
            Assert.NotEqual(0, result.Result.Posts.ToList()[0].PostId);
            Assert.NotEqual(0, result.Result.Posts.ToList()[1].PostId);
            Assert.NotEqual(0, result.Result.Posts.ToList()[2].PostId);
            Assert.Equal(DateTime.MaxValue, entity.Posts.ToList()[0].UpdatedDate);
            Assert.Equal(DateTime.MaxValue, entity.Posts.ToList()[1].UpdatedDate);
            Assert.Equal(DateTime.MinValue, entity.Posts.ToList()[2].UpdatedDate);
            Assert.Equal(3, entity.Posts.Count());
        }
コード例 #3
0
        public void UpdateBlogWithPosts_UpdateWithNewBlogTags()
        {
            ICreateOrUpdateService <BloggingContext, Blog> CreateOrUpdateService = new CreateOrUpdateService <BloggingContext, Blog>(this._context);
            var result = CreateOrUpdateService.CreateOrUpdate(new BlogWithPostsCreateDto
            {
                BlogId = 1,
                Name   = "Test Update2",
                Url    = "https://www.usc.edu",
                Posts  = new List <PostDto> {
                    new PostDto {
                        PostId = 3, Title = "T1", Content = "C1"
                    },
                    new PostDto {
                        PostId = 4, Title = "T2", Content = "C1"
                    }
                },
                Tags = new List <BlogTagDto>()
                {
                    new BlogTagDto {
                        Id = 1, BlogId = 1, Name = "Test2"
                    },
                    new BlogTagDto {
                        BlogId = 1, Name = "Test3"
                    }
                }
            }, ActionFlags.Update);

            Assert.True(result.IsValid);
            Assert.Equal(1, result.Result.BlogId);
            var entity = this._context.Blogs.Where(x => x.BlogId == 1).First();

            Assert.Equal("Test Update2", result.Result.Name);
            Assert.Equal(2, entity.Tags.Count());
        }
コード例 #4
0
        public void Can_UpdateBlog_With_BlogUpdateDto()
        {
            ICreateOrUpdateService <BloggingContext, Blog> createOrUpdateService = new CreateOrUpdateService <BloggingContext, Blog>(this._context);
            var result = createOrUpdateService.CreateOrUpdate(new BlogUpdateDto
            {
                BlogId = 1, // exist id
                Name   = "Cannot update"
            });

            Assert.True(result.IsValid);
        }
コード例 #5
0
        public void Cannot_CreateBlog_With_BlogUpdateDto()
        {
            ICreateOrUpdateService <BloggingContext, Blog> createOrUpdateService = new CreateOrUpdateService <BloggingContext, Blog>(this._context);
            var result = createOrUpdateService.CreateOrUpdate(new BlogUpdateDto
            {
                BlogId = 9,
                Name   = "Cannot update"
            }, ActionFlags.Create);

            Assert.False(result.IsValid);
        }
コード例 #6
0
        public void TestUpdate_Blog_With_NotExistedId_Should_Fail()
        {
            ICreateOrUpdateService <BloggingContext, Blog> CreateOrUpdateService = new CreateOrUpdateService <BloggingContext, Blog>(this._context);
            var result = CreateOrUpdateService.CreateOrUpdate(new BlogDto
            {
                BlogId = 100,
                Name   = "Test Update",
                Url    = "https://www.usc.edu"
            }, ActionFlags.Update);

            Assert.False(result.IsValid);
        }
コード例 #7
0
        public void UpdateBlogTag_Only_Name_field()
        {
            ICreateOrUpdateService <BloggingContext, BlogTag> CreateOrUpdateService = new CreateOrUpdateService <BloggingContext, BlogTag>(this._context);
            var result = CreateOrUpdateService.CreateOrUpdate(new BlogTagDto {
                Id   = 1,
                Name = "TestUpdate"
            }, ActionFlags.Update);

            Assert.True(result.IsValid);
            Assert.Equal("TestUpdate", result.Result.Name);
            Assert.Equal(1, result.Result.BlogId);
        }
コード例 #8
0
        public void UpdateBlogTag_Only_Name_Using_IgnoreMappingValue()
        {
            ICreateOrUpdateService <BloggingContext, BlogTag> CreateOrUpdateService = new CreateOrUpdateService <BloggingContext, BlogTag>(this._context);
            var result = CreateOrUpdateService.CreateOrUpdate(new BlogTagDto
            {
                Id   = 1,
                Name = "Skip"
            }, ActionFlags.Update);

            Assert.True(result.IsValid);
            Assert.NotEqual("Skip", result.Result.Name);
            Assert.Equal(1, result.Result.BlogId);
        }
コード例 #9
0
        public void CreatePost()
        {
            ICreateOrUpdateService <BloggingContext, Post> createOrUpdateService = new CreateOrUpdateService <BloggingContext, Post>(this._context);
            var result = createOrUpdateService.CreateOrUpdate(new PostDto
            {
                Title          = "TestTitle2",
                Content        = "TestContent2",
                EdittedContent = "TestEdittedContent3"
            }, ActionFlags.Create);

            Assert.True(result.IsValid);
            Assert.Equal("TestContent2", result.Result.Content);
            Assert.Null(result.Result.EdittedContent);
        }
コード例 #10
0
        public void UpdateBlogWithPosts_UndefinedTags_Should_Not_Remove_Tags()
        {
            ICreateOrUpdateService <BloggingContext, Blog> CreateOrUpdateService = new CreateOrUpdateService <BloggingContext, Blog>(this._context);
            var result = CreateOrUpdateService.CreateOrUpdate(new BlogWithPostsCreateDto
            {
                BlogId = 1,
                Name   = "Test Update2",
                Url    = "https://www.usc.edu",
            }, ActionFlags.Update);

            Assert.True(result.IsValid);
            Assert.Equal(1, result.Result.BlogId);
            var entity = this._context.Blogs.Where(x => x.BlogId == 1).First();

            Assert.Equal("Test Update2", result.Result.Name);
            Assert.Equal(1, entity.Tags.Count());
        }
コード例 #11
0
        public void CreateBlogWith_ExisitingId_Should_Failed()
        {
            ICreateOrUpdateService <BloggingContext, Blog> createOrUpdateService = new CreateOrUpdateService <BloggingContext, Blog>(this._context);
            var result = createOrUpdateService.CreateOrUpdate(new BlogWithPostsCreateDto
            {
                BlogId = 1,
                Name   = "Test Create2",
                Url    = "https://www.usc.edu",
                Posts  = new List <PostDto>()
                {
                    new PostDto {
                        PostId = 1, Title = "TestTitle1", Content = "TestContent1"
                    },
                }
            }, ActionFlags.Create);

            Assert.False(result.IsValid);
        }
コード例 #12
0
        public void TestCreate_Blog()
        {
            ICreateOrUpdateService <BloggingContext, Blog> createOrUpdateService = new CreateOrUpdateService <BloggingContext, Blog>(this._context);
            var result = createOrUpdateService.CreateOrUpdate(new BlogDto
            {
                Name     = "Test Create",
                Url      = "https://www.usc.edu",
                AuthorId = 1
            }, ActionFlags.Create);

            Assert.True(result.IsValid);
            Assert.NotEqual(0, result.Result.BlogId);
            var entity = this._context.Blogs.Where(x => x.BlogId == result.Result.BlogId).First();

            Assert.Equal("Test Create", result.Result.Name);
            Assert.Equal("https://www.usc.edu", result.Result.Url);
            Assert.Equal(DateTime.MaxValue, entity.CreatedDate);
            Assert.Equal(0, entity.Posts.Count);
            Assert.Equal(1, entity.Author.Id);
        }
コード例 #13
0
        public void UpdateBlogWithPosts_WithExistingPostIds_Should()
        {
            ICreateOrUpdateService <BloggingContext, Blog> CreateOrUpdateService = new CreateOrUpdateService <BloggingContext, Blog>(this._context);
            var result = CreateOrUpdateService.CreateOrUpdate(new BlogWithPostIdsCreateDto
            {
                BlogId  = 1,
                Name    = "Test Update2",
                Url     = "https://www.usc.edu",
                PostIds = new List <int>()
                {
                    3, 4
                }
            }, ActionFlags.Update);

            Assert.True(result.IsValid);
            Assert.Equal(1, result.Result.BlogId);
            var entity = this._context.Blogs.Where(x => x.BlogId == 1).First();

            Assert.Equal("Test Update2", result.Result.Name);
            Assert.Equal(2, entity.Posts.Count());
        }
コード例 #14
0
        public void TestUpdate_Blog_NameAndUrl_Only()
        {
            ICreateOrUpdateService <BloggingContext, Blog> CreateOrUpdateService = new CreateOrUpdateService <BloggingContext, Blog>(this._context);
            var result = CreateOrUpdateService.CreateOrUpdate(new BlogDto
            {
                BlogId = 1,
                Name   = "Test Update",
                Url    = "https://www.usc.edu",
            }, ActionFlags.Update);
            var entity = this._context.Blogs.Where(x => x.BlogId == 1).First();

            Assert.True(result.IsValid);
            Assert.Equal(1, result.Result.BlogId);

            Assert.Equal("Test Update", result.Result.Name);
            Assert.Equal("https://www.usc.edu", result.Result.Url);
            Assert.Equal(DateTime.MaxValue, entity.UpdatedDate);
            Assert.Equal(2, entity.Posts.Count);
            Assert.Equal(1, entity.Tags.Count);
            Assert.Equal(1, entity.Author.Id);
        }
コード例 #15
0
        public void UpdateBlogWithPosts_RemoveAllTags()
        {
            ICreateOrUpdateService <BloggingContext, Blog> CreateOrUpdateService = new CreateOrUpdateService <BloggingContext, Blog>(this._context);
            var result = CreateOrUpdateService.CreateOrUpdate(new BlogWithPostsCreateDto
            {
                BlogId = 1,
                Name   = "Test Update2",
                Url    = "https://www.usc.edu",
                Tags   = new List <BlogTagDto>()
                {
                }
            }, ActionFlags.Update);

            Assert.Equal(new List <object>()
            {
            }, result.Errors);
            Assert.True(result.IsValid);
            Assert.Equal(1, result.Result.BlogId);
            var entity = this._context.Blogs.Where(x => x.BlogId == 1).First();

            Assert.Equal("Test Update2", result.Result.Name);
            Assert.Equal(0, entity.Tags.Count());
        }