public void KeepSynchronizedSimple()
        {
            using (var container = new RhetosTestContainer())
            {
                var log = new List <string>();
                container.AddLogMonitor(log);

                var repository = container.Resolve <Common.DomRepository>();

                var doc1 = new Test9.Document {
                    Name = "doc1"
                };
                var doc2 = new Test9.Document {
                    Name = "doc2"
                };
                repository.Test9.Document.Insert(new[] { doc1, doc2 });

                Assert.AreEqual(0, SimpleNumParts(repository, "doc1"), "initial");

                var st1 = new Test9.Part {
                    HeadID = doc1.ID, Name = "st1"
                };
                repository.Test9.Part.Insert(new[] { st1 });

                Assert.AreEqual(1, SimpleNumParts(repository, "doc1"), "after insert detail");

                var st2 = new Test9.Part {
                    HeadID = doc1.ID, Name = "st2"
                };
                repository.Test9.Part.Insert(new[] { st2 });

                Assert.AreEqual(2, SimpleNumParts(repository, "doc1"), "after insert detail 2");

                st1.HeadID = doc2.ID;
                log.Clear();
                repository.Test9.Part.Update(new[] { st1 });

                Assert.AreEqual("DocumentAggregates i0 u2 d0, DocumentSimpleAggregate i0 u2 d0",
                                ReportRecompute(log)); // Optimized IEnumerable<Guid> filters in ChangesOnChangedItems merges IDs retrieved before and after save, to avoid two calls to the Recompute() function.
                Assert.AreEqual(1, SimpleNumParts(repository, "doc1"), "after update detail");

                st1.Name += "x";
                log.Clear();
                repository.Test9.Part.Update(new[] { st1 });

                Assert.AreEqual("DocumentAggregates i0 u0 d0, DocumentSimpleAggregate i0 u0 d0",
                                ReportRecompute(log)); // Optimized IEnumerable<Guid> filters in ChangesOnChangedItems merges IDs retrieved before and after save, to avoid two calls to the Recompute() function.
                Assert.AreEqual(1, SimpleNumParts(repository, "doc1"), "after update detail");

                repository.Test9.Part.Delete(new[] { st2 });

                Assert.AreEqual(0, SimpleNumParts(repository, "doc1"), "after delete detail 2");
            }
        }
        public void ComputeForNewBaseItemsWithSaveFilter()
        {
            using (var scope = TestScope.Create())
            {
                var repository = scope.Resolve <Common.DomRepository>();

                var documentUser = new Test9.Document {
                    Name = "UserDoc"
                };
                var documentAuto = new Test9.Document {
                    Name = "AutoDoc"
                };
                repository.Test9.Document.Insert(new[] { documentUser, documentAuto });

                // The save filter is implemented in DSL script on ComputeForNewBaseItems for documents starting with "Auto".
                var computed = repository.Test9.DocumentCreationInfoSaveFilter.Load(new[] { documentUser.ID, documentAuto.ID });
                Assert.AreEqual("AutoDoc", TestUtility.DumpSorted(computed, item => item.Name));
            }
        }
        public void KeepSynchronizedSimple()
        {
            using (var container = new RhetosTestContainer())
            {
                var log = new List<string>();
                container.AddLogMonitor(log);

                var repository = container.Resolve<Common.DomRepository>();

                var doc1 = new Test9.Document { Name = "doc1" };
                var doc2 = new Test9.Document { Name = "doc2" };
                repository.Test9.Document.Insert(new[] { doc1, doc2 });
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

                Assert.AreEqual(0, SimpleNumParts(repository, "doc1"), "initial");
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

                var st1 = new Test9.Part { HeadID = doc1.ID, Name = "st1" };
                repository.Test9.Part.Insert(new[] { st1 });
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

                Assert.AreEqual(1, SimpleNumParts(repository, "doc1"), "after insert detail");
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

                var st2 = new Test9.Part { HeadID = doc1.ID, Name = "st2" };
                repository.Test9.Part.Insert(new[] { st2 });
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

                Assert.AreEqual(2, SimpleNumParts(repository, "doc1"), "after insert detail 2");
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

                st1.HeadID = doc2.ID;
                log.Clear();
                repository.Test9.Part.Update(new[] { st1 });
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

                Assert.AreEqual("DocumentAggregates i0 u2 d0, DocumentSimpleAggregate i0 u2 d0",
                    ReportRecompute(log)); // Optimized IEnumerable<Guid> filters in ChangesOnChangedItems merges IDs retrieved before and after save, to avoid two calls to the Recompute() function.
                Assert.AreEqual(1, SimpleNumParts(repository, "doc1"), "after update detail");
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

                st1.Name += "x";
                log.Clear();
                repository.Test9.Part.Update(new[] { st1 });
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

                Assert.AreEqual("DocumentAggregates i0 u0 d0, DocumentSimpleAggregate i0 u0 d0",
                    ReportRecompute(log)); // Optimized IEnumerable<Guid> filters in ChangesOnChangedItems merges IDs retrieved before and after save, to avoid two calls to the Recompute() function.
                Assert.AreEqual(1, SimpleNumParts(repository, "doc1"), "after update detail");
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

                repository.Test9.Part.Delete(new[] { st2 });
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();

                Assert.AreEqual(0, SimpleNumParts(repository, "doc1"), "after delete detail 2");
                container.Resolve<Common.ExecutionContext>().EntityFrameworkContext.ClearCache();
            }
        }
        public void KeepSynchronizedSimple()
        {
            using (var executionContext = new CommonTestExecutionContext())
            {
                var repository = new Common.DomRepository(executionContext);

                var doc1 = new Test9.Document { Name = "doc1" };
                var doc2 = new Test9.Document { Name = "doc2" };
                repository.Test9.Document.Insert(new[] { doc1, doc2 });
                executionContext.NHibernateSession.Clear();

                Assert.AreEqual(0, SimpleNumParts(repository, "doc1"), "initial");
                executionContext.NHibernateSession.Clear();

                var st1 = new Test9.Part { Head = doc1, Name = "st1" };
                repository.Test9.Part.Insert(new[] { st1 });
                executionContext.NHibernateSession.Clear();

                Assert.AreEqual(1, SimpleNumParts(repository, "doc1"), "after insert detail");
                executionContext.NHibernateSession.Clear();

                var st2 = new Test9.Part { Head = doc1, Name = "st2" };
                repository.Test9.Part.Insert(new[] { st2 });
                executionContext.NHibernateSession.Clear();

                Assert.AreEqual(2, SimpleNumParts(repository, "doc1"), "after insert detail 2");
                executionContext.NHibernateSession.Clear();

                st1.Head = doc2;
                repository.Test9.Part.Update(new[] { st1 });
                executionContext.NHibernateSession.Clear();

                Assert.AreEqual(1, SimpleNumParts(repository, "doc1"), "after update detail");
                executionContext.NHibernateSession.Clear();

                repository.Test9.Part.Delete(new[] { st2 });
                executionContext.NHibernateSession.Clear();

                Assert.AreEqual(0, SimpleNumParts(repository, "doc1"), "after delete detail 2");
                executionContext.NHibernateSession.Clear();
            }
        }