Пример #1
0
        SaveResult InsertTestDataBaseLineIntoDb(PersistManager <BloggerContextPg> uut)
        {
            var blog = new Blog
            {
                Id  = -1,
                Url = "www.example.com"
            };

            var blogEntityAspect = new EntityAspect(blog, EntityState.Added);

            var post = new Post
            {
                BlogId    = -1,
                Content   = "I am content",
                Id        = -2,
                Title     = "this is the title",
                CreatedAt = Instant.FromUtc(2002, 10, 8, 6, 4)
            };

            var postEntityAspect = new EntityAspect(post, EntityState.Added);

            var saveBundle0 = new ClientSaveBundle();

            saveBundle0.AddEntity(blogEntityAspect);
            saveBundle0.AddEntity(postEntityAspect);

            var parsedSaveBundle = JObject.Parse(saveBundle0.ToJson());

            var saveResult = uut.SaveChanges(parsedSaveBundle.ToString());

            return(saveResult);
        }
Пример #2
0
        public void PersistManager_Delete_DependentEntity()
        {
            var uut = new PersistManager <BloggerContextPg>();

            var ctx = new BloggerContextPg();

            var blogs = ctx.Blogs.ToList();
            var posts = ctx.Posts.ToList();

            blogs.Count.Should().BeGreaterThan(0);
            posts.Count.Should().BeGreaterThan(0);

            var blogsToDelete = blogs.Select(b => new EntityAspect(b, EntityState.Deleted)).ToList();
            var postsToDelete = posts.Select(p => new EntityAspect(p, EntityState.Deleted)).ToList();

            var saveBundle0 = new ClientSaveBundle();

            blogsToDelete.ForEach(b => saveBundle0.AddEntity(b));
            postsToDelete.ForEach(p => saveBundle0.AddEntity(p));

            var parsedSaveBundle = JObject.Parse(saveBundle0.ToJson());

            var saveResultOfDelete = uut.SaveChanges(parsedSaveBundle.ToString());

            var postDeleteBlogs = uut.Context.Blogs.ToList();

            postDeleteBlogs.Count.Should().Be(0);
            saveResultOfDelete.DeletedKeys.Count.Should().Be(blogs.Count + posts.Count);
        }