示例#1
0
        public void CanAddAnotherBusinessObject()
        {
            #region Arrange

            Post post;

            post = new Post();
            post.Text = Fixture.Create<string>();
            post.Date = Fixture.Create<string>();
            post.Url = Guid.NewGuid().ToString();

            #endregion Arrange

            #region Act

            using (var uow = UoWFactory.Create())
            {
                var rep = uow.Create();
                var persitedPost = rep.Add<Post>(post);

                uow.Commit();
            }

            #endregion Act

            #region Assert

            // TODO.

            #endregion Assert
        }
        public void CanNotCrash()
        {
            //var blog = new Blog()
            //{
            //    Author = Fixture.Create<string>(),
            //    Name = Fixture.Create<string>(),
            //    Posts = new System.Collections.Generic.List<Post>()
            //    {
            //        new Post() { Date = "20150909", Text = Fixture.Create<string>() },
            //        //new Post() { Date = "20150909", Text = Fixture.Create<string>() }
            //    }
            //};

            var post = new Post()
            {
                Text = Fixture.Create<string>(),
                Url = Fixture.Create<string>(),
            };

            using (var db = new EF7BloggContext())
            {
                db.ChangeTracker.TrackGraph(post, c => c.Entry.State = EntityState.Added);

                db.SaveChanges();
            };
        }
示例#3
0
        public void CanCreate3()
        {
            Post post;
            using (var uow = UoWFactory.Create())
            {
                var rep = uow.Create();
                var blogww = Fixture.Create<Blog>();
                post = Fixture.Create<Post>();

                var k = rep.Add<Post>(post);

                uow.Commit();
            }

            var blog = new Blog();
            blog.Name = Fixture.Create<string>();
            post.Text = Fixture.Create<string>();
            post.Blog = blog;
            blog.Posts.Add(post);

            post = new Post();
            post.Text = Fixture.Create<string>();
            post.Url = Guid.NewGuid().ToString();
            post.Blog = blog;
            blog.Posts.Add(post);

            using (var uow = UoWFactory.Create())
            {
                var repository = uow.Create();

                var updatedBlog = repository.UpdateGraph(blog);
                uow.Commit();
            }
        }
示例#4
0
        public void CanRetrieveBlogNonGeneric()
        {
            #region Arrange

            Blog createdBlog;
            Post post;
            using (var uow = UoWFactory.Create())
            {
                var rep = uow.Create();
                var blog = new Blog
                {
                    Name = Fixture.Create<string>()
                };

                post = new Post();
                post.Text = Fixture.Create<string>();
                post.Date = Fixture.Create<string>();
                post.Url = Guid.NewGuid().ToString();
                post.Blog = blog;

                blog.Posts.Add(post);

                createdBlog = rep.AddWithRelations(blog);

                uow.Commit();
            }

            #endregion Arrange

            #region Act

            Blog retrievedBlog = null;
            using (var uow = UoWFactory.Create())
            {
                var rep = uow.Create();
                retrievedBlog = rep.RetrieveBlogNonGeneric(createdBlog.Id);
            }

            #endregion Act

            #region Assert

            Assert.IsNotNull(retrievedBlog);

            #endregion Assert
        }
示例#5
0
        public void CanUpdateBusinessObject()
        {
            #region Arrange

            Post retrievedPost = null;
            using (var uow = UoWFactory.Create())
            {
                Post post;
                var rep = uow.Create();
                post = new Post();
                post.Text = Fixture.Create<string>();
                post.Date = Fixture.Create<string>();
                post.Url = Guid.NewGuid().ToString();

                var persistedPost = rep.Add<Post>(post);

                uow.Commit();

                var projector = rep.PropertySelectBuilder(post)
                    .Select(p => p.Text, p => p.Date)
                    .Build();

                retrievedPost = rep.RetrieveById(persistedPost.Id, projector);
            }

            #endregion Arrange

            #region Act

            using (var uow = UoWFactory.Create())
            {
                var rep = uow.Create();
                retrievedPost.Text = Fixture.Create<string>();
                retrievedPost.Date = Fixture.Create<string>();

                rep.Update(retrievedPost, p => p.Text);

                uow.Commit();
            }

            #endregion Act
        }
示例#6
0
        public void CanCreate6()
        {
            var blog = new Blog();
            blog.Name = Fixture.Create<string>();
            using (var uow = UoWFactory.Create())
            {
                var repository = uow.Create();

                var persistedBlog = repository.Add(blog);

                uow.Commit();
            }

            var post = new Post();
            post.Text = Fixture.Create<string>();
            post.Url = Guid.NewGuid().ToString();

            using (var uow = UoWFactory.Create())
            {
                var repository = uow.Create();

                var persistedPost = repository.Add(post);

                uow.Commit();
            }

            var post1 = new Post();
            post1.Text = Fixture.Create<string>();
            post1.Url = Guid.NewGuid().ToString();
            blog.Posts.AddRange(new List<Post>() { post, post1 });

            using (var uow = UoWFactory.Create())
            {
                var repository = uow.Create();

                var updatedBlog = repository.UpdateGraph(blog);

                uow.Commit();
            }
        }
示例#7
0
        public void CanAddTheSameBusinessObjectUsingDisconnectedScenarioExpectedException()
        {
            #region Arrange

            Post post;

            post = new Post();
            post.Text = Fixture.Create<string>();
            post.Date = Fixture.Create<string>();
            post.Url = Guid.NewGuid().ToString();

            using (var uow = UoWFactory.Create())
            {
                var rep = uow.Create();
                var persitedPreRegistration = rep.Add<Post>(post);

                uow.Commit();
            }

            #endregion Arrange

            #region Act

            using (var uow = UoWFactory.Create())
            {
                var rep = uow.Create();
                var persitedPost = rep.Add<Post>(post);

                uow.Commit();
            }

            #endregion Act

            #region Assert

            // TODO.

            #endregion Assert
        }
示例#8
0
        public void CanAddTheSameBusinessObjectExpectedException()
        {
            /*
            This test should fail since the alternate key Url value is the same between the two insterts.
            */

            #region Arrange

            Post post;

            post = new Post();
            post.Text = Fixture.Create<string>();
            post.Date = Fixture.Create<string>();
            post.Url = Guid.NewGuid().ToString();

            using (var uow = UoWFactory.Create())
            {
                var rep = uow.Create();
                var persitedPost = rep.Add<Post>(post);

                uow.Commit();

                #endregion Arrange

                #region Act

                persitedPost = rep.Add<Post>(post);

                uow.Commit();

                #endregion Act
            }

            #region Assert

            // TODO.

            #endregion Assert
        }
        public void CanAddWithRelations()
        {
            #region Arrange

            var blog = new Blog();
            blog.Name = Fixture.Create<string>();

            var post = new Post();
            post.Text = Fixture.Create<string>();
            post.Url = Guid.NewGuid().ToString();
            blog.Posts.Add(post);

            #endregion Arrange

            #region Act

            using (var uow = UoWFactory.Create())
            {
                var repository = uow.Create();

                var updatedBlog = repository.AddWithRelations(blog);
                uow.Commit();
            }

            #endregion Act

            #region Assert

            // TODO!

            #endregion Assert
        }
        public void CanAddWithRelations_Inconclusive()
        {
            Assert.Inconclusive("This implementation of retrieve is not going to be used");
            Post post;
            Blog createdBlog;
            using (var uow = UoWFactory.Create())
            {
                var rep = uow.Create();
                var blog = new Blog
                {
                    Name = Fixture.Create<string>()
                };

                post = new Post();
                post.Text = Fixture.Create<string>();
                post.Date = Fixture.Create<string>();
                post.Url = Guid.NewGuid().ToString();
                post.Blog = blog;

                blog.Posts.Add(post);

                post = new Post();
                post.Text = Fixture.Create<string>();
                post.Date = Fixture.Create<string>();
                post.Url = Guid.NewGuid().ToString();
                post.Blog = blog;

                blog.Posts.Add(post);

                createdBlog = rep.AddWithRelations(blog);

                uow.Commit();
            }

            using (var uow = UoWFactory.Create())
            {
                var rep = uow.Create();

                var retrievedBlogWithPosts = rep.RetrieveObsolete<Blog, dynamic>(
                    createdBlog.Id, p => new { ff = p.Name, ffff = p.Description, fff = p.Posts.Select(pp => pp.Text) });
            }
        }
        public void CanAddWithRelations2()
        {
            #region Arrange

            Blog createdBlog;
            Post post;

            var blog = new Blog
            {
                Name = Fixture.Create<string>(),
                Description = Fixture.Create<string>()
            };

            post = new Post()
            {
                Text = Fixture.Create<string>(),
                Date = Fixture.Create<string>(),
                Url = Guid.NewGuid().ToString(),
                Blog = blog,
            };

            var follower = new Follower()
            {
                Name = Fixture.Create<string>(),
                Blog = blog
            };

            blog.Posts.Add(post);
            blog.Followers.Add(follower);

            post = new Post();
            post.Text = Fixture.Create<string>();
            post.Date = Fixture.Create<string>();
            post.Url = Guid.NewGuid().ToString();
            post.Blog = blog;

            blog.Posts.Add(post);

            #endregion Arrange

            #region Act

            using (var uow = UoWFactory.Create())
            {
                var rep = uow.Create();

                createdBlog = rep.AddWithRelations(blog);

                uow.Commit();
            }

            #endregion Act

            #region Assert

            using (var uow = UoWFactory.Create())
            {
                var rep = uow.Create();

                var pp = rep.PropertySelectBuilder(blog)
                    .Select(m => m.Id, m => m.Name, m => m.Description)
                    .Include<Post>(p => p.Posts, p => p.Text, p => post.Date)
                    .Include<Follower>(m => m.Followers, p => p.Id, p => p.Name)
                    .Build();

                var retrievedBlog = rep.RetrieveById(createdBlog.Id, pp);
            }

            #endregion Assert
        }