Exemplo n.º 1
0
        public void Uow_CascadeDeleteBlogPosts_Null()
        {
            var blog = BlogObjectMother
                       .aDefaultBlog()
                       .WithTile("CascadeDelete")
                       .ToRepository();

            Uow.GetRepository <Blog>()
            .Insert(blog);

            Uow.SaveChanges();

            var insertResult = Uow.GetRepository <Blog>().GetFirstOrDefault(predicate: x =>
                                                                            x.Title == "CascadeDelete",
                                                                            include: i => i.Include(x => x.Posts));

            Assert.That(insertResult.Title, Is.EqualTo("CascadeDelete"));
            Assert.That(insertResult.Posts, Is.Not.Null);

            var postCount = Uow.GetRepository <Post>().Count();

            Assert.That(postCount, Is.GreaterThan(0));

            Uow.GetRepository <Blog>().Delete(blog);
            Uow.SaveChanges();

            var deleteResult = Uow.GetRepository <Blog>().Find(blog.Id);

            Assert.That(deleteResult, Is.Null);
        }
Exemplo n.º 2
0
        public async Task AsyncInsertRepository_MultipleBlogWithPosts_SuccessfullSave()
        {
            var blogs = new List <Blog>();

            for (int i = 0; i < 100; i++)
            {
                blogs.Add(BlogObjectMother
                          .aDefaultBlog()
                          .WithTile($"Test Blog MultiInsert {i}")
                          .ToRepository());
            }

            foreach (var blog in blogs)
            {
                db.Add(blog);
                await db.SaveChangesAsync();
            }

            var result = BlogRepository.GetFirstOrDefault(predicate: x =>
                                                          x.Title.Contains("MultiInsert"),
                                                          include: i => i.Include(x => x.Posts));

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Posts, Is.Not.Null);
        }
Exemplo n.º 3
0
        public void RepositoryCascadeDelete_BlogPosts_Null()
        {
            var blog = BlogObjectMother
                       .aDefaultBlogWithPost()
                       .ToRepository();

            BlogRepository.Insert(blog);
            db.SaveChanges();

            var insertResult = BlogRepository.GetFirstOrDefault(predicate: x =>
                                                                x.Title == BlogObjectMother.aDefaultBlogWithPost().Title,
                                                                include: i => i.Include(x => x.Posts));

            Assert.That(insertResult.Title, Is.EqualTo(BlogObjectMother.aDefaultBlogWithPost().Title));
            Assert.That(insertResult.Posts, Is.Not.Null);

            var postCount = PostRepository.Count();

            Assert.That(postCount, Is.GreaterThan(0));

            BlogRepository.Delete(blog);
            db.SaveChanges();

            var deleteResult = BlogRepository.Find(blog.Id);

            var postResult = PostRepository.Find(blog.Posts.FirstOrDefault().Id);

            Assert.That(deleteResult, Is.Null);
            //Only the parent was marked for deletion not the child
            //As the delete operation is set to soft Delete by default
            Assert.That(postResult, Is.Null);
        }
Exemplo n.º 4
0
        public void Uow_DeleteBlog_Null()
        {
            //var initalCount = Uow.GetRepository<Blog>()
            //    .GetAll()
            //    .ToList()
            //    .Count;

            var blogInsert = BlogObjectMother
                             .aDefaultBlog()
                             .ToRepository();

            Uow.GetRepository <Blog>()
            .Insert(blogInsert);

            Uow.SaveChanges();

            var blogGet = Uow.GetRepository <Blog>().Find(blogInsert.Id);

            Assert.That(blogGet, Is.Not.Null);

            Uow.GetRepository <Blog>().Delete(blogGet);
            Uow.SaveChanges();

            //var initalCount2 = Uow.GetRepository<Blog>().GetAll().ToList().Count;

            var blogDelete = Uow.GetRepository <Blog>().Find(blogGet.Id);

            Assert.That(blogDelete, Is.Null);
        }
Exemplo n.º 5
0
        public void RepositoryDelete_Blog_Null()
        {
            var blog = BlogObjectMother
                       .aDefaultBlogWithPost()
                       .ToRepository();

            BlogRepository.Insert(blog);
            db.SaveChanges();

            var insertResult = BlogRepository.GetFirstOrDefault(predicate: x =>
                                                                x.Title == BlogObjectMother
                                                                .aDefaultBlogWithPost()
                                                                .Title);

            Assert.That(insertResult.Title, Is.EqualTo(BlogObjectMother
                                                       .aDefaultBlogWithPost()
                                                       .Title));

            BlogRepository.Delete(blog);
            db.SaveChanges();

            var deleteResult = BlogRepository.Find(blog.Id);

            Assert.That(deleteResult, Is.Null);
        }
Exemplo n.º 6
0
        public void InsertRepository_Blog_SuccessfullSave()
        {
            BlogRepository.Insert(BlogObjectMother.aDefaultBlog().ToRepository());
            db.SaveChanges();

            var result = BlogRepository.GetFirstOrDefault(predicate: x =>
                                                          x.Title == BlogObjectMother.aDefaultBlog().Title);

            Assert.That(result.Title, Is.EqualTo(BlogObjectMother.aDefaultBlog().Title));
        }
Exemplo n.º 7
0
        public async Task BlogController_Insert_Id()
        {
            var createDto = BlogObjectMother
                            .aDefaultBlog()
                            .ToCreateDto();

            var response = await _client.PostAsJsonAsync(BlogControllerEndpoints.Create, createDto);

            var result = await response.Content.Deserialize <long>();

            Assert.That(result, Is.GreaterThan(0));
        }
Exemplo n.º 8
0
        public void InsertRepository_BlogWithPosts_SuccessfullSave()
        {
            BlogRepository.Insert(BlogObjectMother.aDefaultBlogWithPost().ToRepository());
            db.SaveChanges();

            var result = BlogRepository.GetFirstOrDefault(predicate: x =>
                                                          x.Title == BlogObjectMother.aDefaultBlog().Title,
                                                          include: i => i.Include(x => x.Posts));

            Assert.That(result.Title, Is.EqualTo(BlogObjectMother.aDefaultBlogWithPost().Title));
            Assert.That(result.Posts, Is.Not.Null);
        }
Exemplo n.º 9
0
        public async Task UowAsyncInsert_SingleBlogWithPosts_SuccessfullSave()
        {
            Uow.GetRepository <Blog>().Insert(BlogObjectMother.aDefaultBlog().ToRepository());

            await Uow.SaveChangesAsync();

            var result = Uow.GetRepository <Blog>().GetFirstOrDefault(predicate: x =>
                                                                      x.Title == BlogObjectMother.aDefaultBlog().Title,
                                                                      include: i => i.Include(x => x.Posts));

            Assert.That(result.Title, Is.EqualTo(BlogObjectMother.aDefaultBlog().Title));
            Assert.That(result.Posts, Is.Not.Null);
        }
Exemplo n.º 10
0
        public void Uow_InsertBlog_SuccessfullSave()
        {
            Uow.GetRepository <Blog>().Insert(BlogObjectMother
                                              .aDefaultBlog()
                                              .ToRepository());

            Uow.SaveChanges();

            var result = Uow.GetRepository <Blog>().GetFirstOrDefault(predicate: x =>
                                                                      x.Title == BlogObjectMother.aDefaultBlog().Title);

            Assert.That(result.Title, Is.EqualTo(BlogObjectMother.aDefaultBlog().Title));
        }
Exemplo n.º 11
0
        public async Task BlogController_InsertInvalidTitle_ValidationException()
        {
            var createDto = BlogObjectMother
                            .aDefaultBlog()
                            .WithTile(null)
                            .ToDto();

            try
            {
                await _client.PostAsJsonAsync(BlogControllerEndpoints.Create, createDto);
            }
            catch (FluentValidation.ValidationException validationException)
            {
                StringAssert.Contains("Title", validationException.Message);
            }
        }
Exemplo n.º 12
0
        public async Task AsyncInsertRepository_SingleBlogWithPosts_SuccessfullSave()
        {
            BlogRepository.Insert(BlogObjectMother
                                  .aDefaultBlogWithPost()
                                  .WithTile("Async Blog Test")
                                  .ToRepository());

            await db.SaveChangesAsync();

            var result = BlogRepository.GetFirstOrDefault(predicate: x =>
                                                          x.Title == "Async Blog Test",
                                                          include: i => i.Include(x => x.Posts));

            Assert.That(result.Title, Is.EqualTo("Async Blog Test"));
            Assert.That(result.Posts, Is.Not.Null);
        }
Exemplo n.º 13
0
        public async Task UowAsyncInsert_MultipleBlogWithPosts_SuccessfullSave()
        {
            var blogs = BlogObjectMother.aListOfBlogsAndPosts("MultiInsert Blog");

            foreach (var blog in blogs)
            {
                Uow.GetRepository <Blog>().Insert(blog);
                await Uow.SaveChangesAsync();
            }

            var result = Uow.GetRepository <Blog>().GetFirstOrDefault(predicate: x =>
                                                                      x.Title.Contains("MultiInsert Blog"),
                                                                      include: i => i.Include(x => x.Posts));

            Assert.That(result, Is.Not.Null);
            Assert.That(result.Posts, Is.Not.Null);
        }
Exemplo n.º 14
0
        public void Uow_List_ListOfBlogsAndPostsOrderdByTitleDesc()
        {
            var blog = BlogObjectMother
                       .aDefaultBlogWithPost()
                       .WithTile("ASDF")
                       .ToRepository();

            Uow.GetRepository <Blog>().Insert(blog);
            Uow.SaveChanges();

            var result = Uow.GetRepository <Blog>().GetPagedList(
                predicate: x => x.Title == "ASDF",
                include: source => source.Include(t => t.Posts),
                orderBy: b => b.OrderByDescending(x => x.Hits));

            Assert.That(result.Items.Count, Is.GreaterThan(0));
            Assert.That(result.Items.FirstOrDefault().Hits, Is.GreaterThan(0));
        }
Exemplo n.º 15
0
        public void Uow_UpdateBlog_UpdatedBlog()
        {
            var blog = BlogObjectMother
                       .aDefaultBlog()
                       .ToRepository();

            Uow.GetRepository <Blog>().Insert(blog);
            Uow.SaveChanges();

            var insertResult = Uow.GetRepository <Blog>().Find(blog.Id);

            Assert.That(insertResult, Is.Not.Null);

            blog.Hits = 99;
            Uow.GetRepository <Blog>().Update(blog);
            var updateResult = Uow.GetRepository <Blog>().Find(blog.Id);

            Assert.That(updateResult.Hits, Is.EqualTo(99));
        }
        public void RepositoryFirstOrDefault_Blog_FirstPost()
        {
            db.Add(BlogObjectMother
                   .aDefaultBlogWithPost()
                   .WithTile("ASDF")
                   .WithHits(999)
                   .ToRepository());

            db.SaveChanges();

            var result = BlogRepository.GetFirstOrDefault(
                predicate: x => x.Title == "ASDF",
                orderBy: o => o.OrderByDescending(d => d.Hits),
                selector: s => s.Posts.FirstOrDefault(),
                include: i => i.Include(a => a.Posts));

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.TypeOf <Post>());
        }
Exemplo n.º 17
0
        public void RepositoryUpdate_Blog_UpdatedBlog()
        {
            var blog = BlogObjectMother
                       .aDefaultBlog()
                       .WithTile("Update Blog")
                       .ToRepository();

            BlogRepository.Insert(blog);
            db.SaveChanges();

            var insertResult = BlogRepository.Find(blog.Id);

            Assert.That(insertResult, Is.Not.Null);

            blog.Hits = 99;
            BlogRepository.Update(blog);
            var updateResult = BlogRepository.Find(blog.Id);

            Assert.That(updateResult.Hits, Is.EqualTo(99));
        }
Exemplo n.º 18
0
        public void Uow_FirstOrDefaultBlog_FirstPost()
        {
            var blog = BlogObjectMother
                       .aDefaultBlogWithPost()
                       .WithTile("ASDF")
                       .ToRepository();

            Uow.GetRepository <Blog>().Insert(blog);
            Uow.SaveChanges();

            var result = Uow.GetRepository <Blog>().GetFirstOrDefault(
                predicate: x => x.Title == "ASDF");

            //orderBy: o => o.OrderByDescending(d => d.Hits),
            //selector: s => s.Posts.FirstOrDefault(),
            //include: i => i.Include(a => a.Posts));

            Assert.That(result, Is.Not.Null);
            Assert.That(result, Is.TypeOf <Post>());
        }
Exemplo n.º 19
0
 private void AddObjectMothers()
 {
     Uow.GetRepository <Blog>().Insert(BlogObjectMother.aListOfBlogsAndPosts());
 }
        private void BuildDb()
        {
            _context.Blogs.AddRange(BlogObjectMother.aListOfBlogsAndPosts());

            _context.SaveChanges();
        }
Exemplo n.º 21
0
 private void AddObjectMothers()
 {
     db.AddRange(BlogObjectMother.aListOfBlogsAndPosts());
     db.Add(BlogObjectMother.aDefaultBlog().WithTile("ASDF").ToRepository());
 }