public AggregateContext aggregate()
    {
        AggregateContext _localctx = new AggregateContext(Context, State);

        EnterRule(_localctx, 8, RULE_aggregate);
        try {
            EnterOuterAlt(_localctx, 1);
            {
                State = 41; Match(T__4);
                State = 42; _localctx.column = Match(ID);
                State = 43; Match(T__5);
                State = 44; _localctx.agg = Match(OP);
                State = 45; Match(T__6);
                State = 46; _localctx.alias = Match(ID);
                State = 47; Match(T__3);

                this.AddAggregateExpression(_localctx.agg.Text, _localctx.column.Text, _localctx.alias.Text);
            }
        }
        catch (RecognitionException re) {
            _localctx.exception = re;
            ErrorHandler.ReportError(this, re);
            ErrorHandler.Recover(this, re);
        }
        finally {
            ExitRule();
        }
        return(_localctx);
    }
        public void Can_add_aggregate()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[] { new Comment(), new Comment() };
                var comments1 = new[] { new Comment(), new Comment() };
                var posts     = new[] { new Post {
                                            Comments = comments0.ToList()
                                        }, new Post {
                                            Comments = comments1.ToList()
                                        } };
                var blog = new Blog {
                    Posts = posts.ToList()
                };

                context.Add(blog);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
            }
        }
        public void Attaching_aggregate_with_no_key_set_adds_it_instead()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[] { new Comment(), new Comment() };
                var comments1 = new[] { new Comment(), new Comment() };
                var posts     = new[] { new Post {
                                            Comments = comments0.ToList()
                                        }, new Post {
                                            Comments = comments1.ToList()
                                        } };
                var blog = new Blog {
                    Posts = posts.ToList()
                };

                context.Attach(blog);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
            }
        }
示例#4
0
        public void Dependents_with_no_key_set_are_added()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[]
                {
                    new Comment
                    {
                        Id     = 33,
                        PostId = 55
                    },
                    new Comment
                    {
                        Id     = 34,
                        PostId = 55
                    }
                };
                var comments1 = new[]
                {
                    new Comment
                    {
                        PostId = 56
                    },
                    new Comment
                    {
                        PostId = 56
                    }
                };
                var posts = new[]
                {
                    new Post
                    {
                        Id       = 55,
                        BlogId   = 66,
                        Comments = comments0.ToList()
                    },
                    new Post
                    {
                        BlogId   = 66,
                        Comments = comments1.ToList()
                    }
                };
                var blog = new Blog
                {
                    Id    = 66,
                    Posts = posts.ToList()
                };

                context.Attach(blog);

                Assert.Equal(EntityState.Unchanged, context.Entry(blog).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
            }
        }
示例#5
0
        public void Can_add_two_aggregates_linked_down_the_tree()
        {
            using (var context = new AggregateContext())
            {
                var reminders = new[] { new Reminder {
                                            Id = 11
                                        }, new Reminder {
                                            Id = 12
                                        } };
                var author = new Author {
                    Id = 22, Reminders = reminders.ToList()
                };

                var comments0 = new[] { new Comment {
                                            Id = 33, Author = author
                                        }, new Comment {
                                            Id = 34, Author = author
                                        } };
                var comments1 = new[] { new Comment {
                                            Id = 44, Author = author
                                        }, new Comment {
                                            Id = 45, Author = author
                                        } };
                var posts = new[]
                {
                    new Post
                    {
                        Id       = 55,
                        Author   = author,
                        Comments = comments0.ToList()
                    },
                    new Post
                    {
                        Id       = 56,
                        Author   = author,
                        Comments = comments1.ToList()
                    }
                };
                var blog = new Blog
                {
                    Id     = 66,
                    Author = author,
                    Posts  = posts.ToList()
                };

                context.AddRange(blog, author);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(author).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[1]).State);
            }
        }
        public void Can_add_aggregate_with_other_linked_aggregate_also_attached()
        {
            using (var context = new AggregateContext())
            {
                var reminders = new[] { new Reminder {
                                            Id = 11
                                        }, new Reminder {
                                            Id = 12
                                        } };
                var author = new Author {
                    Id = 22, Reminders = reminders.ToList()
                };

                var comments0 = new[] { new Comment {
                                            Id = 33, Author = author
                                        }, new Comment {
                                            Id = 34, Author = author
                                        } };
                var comments1 = new[] { new Comment {
                                            Id = 44, Author = author
                                        }, new Comment {
                                            Id = 45, Author = author
                                        } };
                var posts = new[]
                {
                    new Post {
                        Id = 55, Author = author, Comments = comments0.ToList()
                    },
                    new Post {
                        Id = 56, Author = author, Comments = comments1.ToList()
                    }
                };
                var blog = new Blog {
                    Id = 66, Author = author, Posts = posts.ToList()
                };

                author.Comments   = comments0.Concat(comments1).ToList();
                comments0[0].Post = posts[0];
                posts[0].Blog     = blog;

                context.Add(author);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(author).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[1]).State);
            }
        }
        public void Can_add_one_to_one_aggreate()
        {
            using (var context = new AggregateContext())
            {
                var statistics = new BlogCategoryStatistics();
                var category = new BlogCategory { Statistics = statistics };

                context.Add(category);

                Assert.Equal(EntityState.Added, context.Entry(category).State);
                Assert.Equal(EntityState.Added, context.Entry(category.Statistics).State);
            }
        }
示例#8
0
        public void Attaching_one_to_one_aggregate_with_no_key_set_adds_it_instead()
        {
            using var context = new AggregateContext();
            var statistics = new BlogCategoryStatistics();
            var category   = new BlogCategory {
                Statistics = statistics
            };

            context.Attach(category);

            Assert.Equal(EntityState.Added, context.Entry(category).State);
            Assert.Equal(EntityState.Added, context.Entry(category.Statistics).State);
        }
        public void Can_attach_one_to_one_aggreate()
        {
            using (var context = new AggregateContext())
            {
                var statistics = new BlogCategoryStatistics { Id = 11, BlogCategoryId = 22 };
                var category = new BlogCategory { Id = 22, Statistics = statistics };

                context.Attach(category);

                Assert.Equal(EntityState.Unchanged, context.Entry(category).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(category.Statistics).State);
            }
        }
示例#10
0
        public void Can_add_one_to_one_aggregate()
        {
            using var context = new AggregateContext();
            var statistics = new BlogCategoryStatistics();
            var category   = new BlogCategory {
                Statistics = statistics
            };

            context.Add(category);

            Assert.Equal(EntityState.Added, context.Entry(category).State);
            Assert.Equal(EntityState.Added, context.Entry(category.Statistics).State);
        }
示例#11
0
        public void Can_attach_aggregate_with_linked_aggregate_not_attached()
        {
            using (var context = new AggregateContext())
            {
                var reminders = new[] { new Reminder {
                                            Id = 11
                                        }, new Reminder {
                                            Id = 12
                                        } };
                var author = new Author {
                    Id = 22, Reminders = reminders.ToList()
                };

                var comments0 = new[] { new Comment {
                                            Id = 33, Author = author
                                        }, new Comment {
                                            Id = 34, Author = author
                                        } };
                var comments1 = new[] { new Comment {
                                            Id = 44, Author = author
                                        }, new Comment {
                                            Id = 45, Author = author
                                        } };
                var posts = new[]
                {
                    new Post {
                        Id = 55, Author = author, Comments = comments0.ToList()
                    },
                    new Post {
                        Id = 56, Author = author, Comments = comments1.ToList()
                    }
                };
                var blog = new Blog {
                    Id = 66, Author = author, Posts = posts.ToList()
                };

                context.Attach(blog);

                Assert.Equal(EntityState.Unchanged, context.Entry(blog).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[1]).State);
                Assert.Equal(EntityState.Detached, context.Entry(author).State);
                Assert.Equal(EntityState.Detached, context.Entry(reminders[0]).State);
                Assert.Equal(EntityState.Detached, context.Entry(reminders[1]).State);
            }
        }
示例#12
0
        public void Can_attach_one_to_one_aggregate()
        {
            using var context = new AggregateContext();
            var statistics = new BlogCategoryStatistics {
                Id = 11, BlogCategoryId = 22
            };
            var category = new BlogCategory {
                Id = 22, Statistics = statistics
            };

            context.Attach(category);

            Assert.Equal(EntityState.Unchanged, context.Entry(category).State);
            Assert.Equal(EntityState.Unchanged, context.Entry(category.Statistics).State);
        }
示例#13
0
        public void One_to_one_dependents_with_no_key_set_are_added()
        {
            using var context = new AggregateContext();
            var statistics = new BlogCategoryStatistics {
                BlogCategoryId = 22
            };
            var category = new BlogCategory {
                Id = 22, Statistics = statistics
            };

            context.Attach(category);

            Assert.Equal(EntityState.Unchanged, context.Entry(category).State);
            Assert.Equal(EntityState.Added, context.Entry(category.Statistics).State);
        }
示例#14
0
        public void Can_attach_aggregate()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[] { new Comment {
                                            Id = 33, PostId = 55
                                        }, new Comment {
                                            Id = 34, PostId = 55
                                        } };
                var comments1 = new[] { new Comment {
                                            Id = 44, PostId = 56
                                        }, new Comment {
                                            Id = 45, PostId = 56
                                        } };
                var posts = new[]
                {
                    new Post
                    {
                        Id       = 55,
                        BlogId   = 66,
                        Comments = comments0.ToList()
                    },
                    new Post
                    {
                        Id       = 56,
                        BlogId   = 66,
                        Comments = comments1.ToList()
                    }
                };
                var blog = new Blog {
                    Id = 66, Posts = posts.ToList()
                };

                context.Attach(blog);

                Assert.Equal(EntityState.Unchanged, context.Entry(blog).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[1]).State);
            }
        }
示例#15
0
        public void Can_add_aggreate()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[] { new Comment(), new Comment() };
                var comments1 = new[] { new Comment(), new Comment() };
                var posts = new[] { new Post { Comments = comments0.ToList() }, new Post { Comments = comments1.ToList() } };
                var blog = new Blog { Posts = posts.ToList() };

                context.Add(blog);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
            }
        }
示例#16
0
        public void Can_attach_aggreate()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[] { new Comment { Id = 33, PostId = 55 }, new Comment { Id = 34, PostId = 55 } };
                var comments1 = new[] { new Comment { Id = 44, PostId = 56 }, new Comment { Id = 45, PostId = 56 } };
                var posts = new[]
                    {
                        new Post { Id = 55, BlogId = 66, Comments = comments0.ToList() },
                        new Post { Id = 56, BlogId = 66, Comments = comments1.ToList() }
                    };
                var blog = new Blog { Id = 66, Posts = posts.ToList() };

                context.Attach(blog);

                Assert.Equal(EntityState.Unchanged, context.Entry(blog).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[1]).State);
            }
        }
示例#17
0
        public void One_to_one_dependents_with_no_key_set_are_added()
        {
            using (var context = new AggregateContext())
            {
                var statistics = new BlogCategoryStatistics { BlogCategoryId = 22 };
                var category = new BlogCategory { Id = 22, Statistics = statistics };

                context.Attach(category);

                Assert.Equal(EntityState.Unchanged, context.Entry(category).State);
                Assert.Equal(EntityState.Added, context.Entry(category.Statistics).State);
            }
        }
示例#18
0
        public void Can_attach_aggregate_with_linked_aggregate_not_attached()
        {
            using (var context = new AggregateContext())
            {
                var reminders = new[] { new Reminder { Id = 11 }, new Reminder { Id = 12 } };
                var author = new Author { Id = 22, Reminders = reminders.ToList() };

                var comments0 = new[] { new Comment { Id = 33, Author = author }, new Comment { Id = 34, Author = author } };
                var comments1 = new[] { new Comment { Id = 44, Author = author }, new Comment { Id = 45, Author = author } };
                var posts = new[]
                    {
                        new Post { Id = 55, Author = author, Comments = comments0.ToList() },
                        new Post { Id = 56, Author = author, Comments = comments1.ToList() }
                    };
                var blog = new Blog { Id = 66, Author = author, Posts = posts.ToList() };

                context.Attach(blog);

                Assert.Equal(EntityState.Unchanged, context.Entry(blog).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments1[1]).State);
                Assert.Equal(EntityState.Detached, context.Entry(author).State);
                Assert.Equal(EntityState.Detached, context.Entry(reminders[0]).State);
                Assert.Equal(EntityState.Detached, context.Entry(reminders[1]).State);
            }
        }
 public AggregateController(AggregateContext context) => _context = context;
示例#20
0
        public void Can_add_aggregate_with_other_linked_aggregate_also_attached()
        {
            using (var context = new AggregateContext())
            {
                var reminders = new[] { new Reminder { Id = 11 }, new Reminder { Id = 12 } };
                var author = new Author { Id = 22, Reminders = reminders.ToList() };

                var comments0 = new[] { new Comment { Id = 33, Author = author }, new Comment { Id = 34, Author = author } };
                var comments1 = new[] { new Comment { Id = 44, Author = author }, new Comment { Id = 45, Author = author } };
                var posts = new[]
                {
                    new Post { Id = 55, Author = author, Comments = comments0.ToList() },
                    new Post { Id = 56, Author = author, Comments = comments1.ToList() }
                };
                var blog = new Blog { Id = 66, Author = author, Posts = posts.ToList() };

                author.Comments = comments0.Concat(comments1).ToList();
                comments0[0].Post = posts[0];
                posts[0].Blog = blog;

                context.Add(author);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(author).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[1]).State);
            }
        }
示例#21
0
        public void Attaching_one_to_one_aggregate_with_no_key_set_adds_it_instead()
        {
            using (var context = new AggregateContext())
            {
                var statistics = new BlogCategoryStatistics();
                var category = new BlogCategory { Statistics = statistics };

                context.Attach(category);

                Assert.Equal(EntityState.Added, context.Entry(category).State);
                Assert.Equal(EntityState.Added, context.Entry(category.Statistics).State);
            }
        }
示例#22
0
        static async Task Main()
        {
            var eventsConverter = new EventsConverter();

            //var e = new Core.OrderManagement.Orders.Events.OrderCreated(OrderIdentity.New());
            //System.Console.WriteLine(JsonSerializer.Serialize(e, new JsonSerializerOptions { WriteIndented = true }));


            //var a = EventMapping.Convert(e);
            //var json = JsonSerializer.Serialize(a, new JsonSerializerOptions { WriteIndented = true, Converters = { new IdentityJsonConverter() } });

            //System.Console.WriteLine(json);

            //var data2 = JsonSerializer.Deserialize<OrderCreated>(json);
            //var e2 = EventMapping.Convert2(data2);

            //System.Console.WriteLine(JsonSerializer.Serialize(e, e.GetType(), new JsonSerializerOptions { WriteIndented = true }));

            //return;

            var aggregateContext = new AggregateContext();

            IEventStore eventStore        = new EventStoreDb(eventsConverter, new Uri("http://localhost:2113"));
            var         productRepository = new ProductRepository(eventStore, aggregateContext);

            var product1 = Product.Create(aggregateContext, ProductName.Create("Brood"));

            await productRepository.SaveAsync(product1);

            product1.ChangeName(ProductName.Create("Boterham"));
            await productRepository.SaveAsync(product1);



            var productRepository2 = new ProductRepository(eventStore, aggregateContext);

            var product1A = await productRepository2.GetAsync(product1.Identifier);

            //System.Console.WriteLine(JsonSerializer.Serialize(product, new JsonSerializerOptions { WriteIndented = true }));
            //System.Console.WriteLine(JsonSerializer.Serialize(product2, new JsonSerializerOptions { WriteIndented = true }));


            var orderRepository = new OrderRepository(eventStore, aggregateContext);


            var order = Order.Create(
                aggregateContext,
                OrderIdentifier.New(),
                CustomerIdentifier.New());

            var faultyLine = order.CreateOrderLine(ProductIdentifier.New(), 1);

            faultyLine.Remove();

            var prod2 = ProductIdentifier.New();
            var prod3 = ProductIdentifier.New();
            var prod4 = ProductIdentifier.New();


            order.CreateOrderLine(product1, 1);
            order.CreateOrderLine(prod2, 2);
            order.CreateOrderLine(prod3, 1);
            order.CreateOrderLine(prod4, 1);

            var prod3OrderLine = order.Lines.Get(prod3);

            prod3OrderLine.Remove();

            var prod1OrderLine = order.Lines.Get(product1.Identifier);

            prod1OrderLine.AdjustQuantity(3);


            await orderRepository.SaveAsync(order);

            var order2 = await orderRepository.GetAsync(order.OrderIdentifier);


            var product1B = await productRepository2.GetAsync(product1.Identifier);

            product1B.ChangeName(ProductName.Create("Stok brood"));
            await productRepository2.SaveAsync(product1B);
        }
示例#23
0
        public void Dependents_with_no_key_set_are_added()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[] { new Comment { Id = 33, PostId = 55 }, new Comment { Id = 34, PostId = 55 } };
                var comments1 = new[] { new Comment { PostId = 56 }, new Comment { PostId = 56 } };
                var posts = new[]
                    {
                        new Post { Id = 55, BlogId = 66, Comments = comments0.ToList() },
                        new Post { BlogId = 66, Comments = comments1.ToList() }
                    };
                var blog = new Blog { Id = 66, Posts = posts.ToList() };

                context.Attach(blog);

                Assert.Equal(EntityState.Unchanged, context.Entry(blog).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Unchanged, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
            }
        }
示例#24
0
        public void Attaching_aggregate_with_no_key_set_adds_it_instead()
        {
            using (var context = new AggregateContext())
            {
                var comments0 = new[] { new Comment(), new Comment() };
                var comments1 = new[] { new Comment(), new Comment() };
                var posts = new[] { new Post { Comments = comments0.ToList() }, new Post { Comments = comments1.ToList() } };
                var blog = new Blog { Posts = posts.ToList() };

                context.Attach(blog);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
            }
        }
示例#25
0
        public void Can_add_two_aggregates_linked_down_the_tree()
        {
            using (var context = new AggregateContext())
            {
                var reminders = new[] { new Reminder { Id = 11 }, new Reminder { Id = 12 } };
                var author = new Author { Id = 22, Reminders = reminders.ToList() };

                var comments0 = new[] { new Comment { Id = 33, Author = author }, new Comment { Id = 34, Author = author } };
                var comments1 = new[] { new Comment { Id = 44, Author = author }, new Comment { Id = 45, Author = author } };
                var posts = new[]
                    {
                        new Post { Id = 55, Author = author, Comments = comments0.ToList() },
                        new Post { Id = 56, Author = author, Comments = comments1.ToList() }
                    };
                var blog = new Blog { Id = 66, Author = author, Posts = posts.ToList() };

                context.AddRange(blog, author);

                Assert.Equal(EntityState.Added, context.Entry(blog).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(posts[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments0[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(comments1[1]).State);
                Assert.Equal(EntityState.Added, context.Entry(author).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[0]).State);
                Assert.Equal(EntityState.Added, context.Entry(reminders[1]).State);
            }
        }