Пример #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);
        }
Пример #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);
        }
Пример #3
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);
        }
Пример #4
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));
        }
Пример #5
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));
        }
Пример #6
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);
        }
Пример #7
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);
        }
Пример #8
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));
        }
Пример #9
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);
            }
        }
Пример #10
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));
        }
Пример #11
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));
        }
Пример #12
0
 private void AddObjectMothers()
 {
     db.AddRange(BlogObjectMother.aListOfBlogsAndPosts());
     db.Add(BlogObjectMother.aDefaultBlog().WithTile("ASDF").ToRepository());
 }