public void LazyFieldHasCheckIfModifiedConstraintTest()
        {
            var counter = new QueryCounter();

            using (var session = Domain.OpenSession()) {
                using (counter.Attach(session))
                    using (var transaction = session.OpenTransaction()) {
                        foreach (var chapter in session.Query.All <Chapter>())
                        {
                            chapter.Title = chapter.Title + " modified";
                        }
                        transaction.Complete();
                    }
                Assert.That(counter.Count, Is.EqualTo(2));
                counter.Reset();
            }

            using (var session = Domain.OpenSession()) {
                int updatedItems = 0;
                using (counter.Attach(session))
                    using (var transaction = session.OpenTransaction()) {
                        foreach (var chapter in session.Query.All <Chapter>())
                        {
                            chapter.Description = chapter.Description + " modified";
                            updatedItems++;
                        }
                        transaction.Complete();
                    }
                Assert.That(counter.Count, Is.EqualTo(5)); // query + fetches + update
                counter.Reset();
            }
        }
        public void LazyFieldHasCheckIfModifiedConstraintTest()
        {
            var counter = new QueryCounter();

            using (var session = Domain.OpenSession()) {
                using (counter.Attach(session))
                    using (var transaction = session.OpenTransaction()) {
                        foreach (var chapter in session.Query.All <Chapter>())
                        {
                            chapter.Title = chapter.Title + " modified";
                        }
                        transaction.Complete();
                    }

                Assert.That(counter.OverallCount, Is.EqualTo(4));
                Assert.That(counter.SelectCount, Is.EqualTo(1)); // select items only, no fetch
                Assert.That(counter.UpdateCount, Is.EqualTo(3));

                counter.Reset();
            }

            using (var session = Domain.OpenSession()) {
                var updatedItems = 0;
                using (counter.Attach(session))
                    using (var transaction = session.OpenTransaction()) {
                        foreach (var chapter in session.Query.All <Chapter>())
                        {
                            chapter.Description = chapter.Description + " modified";
                            updatedItems++;
                        }
                        transaction.Complete();
                    }

                Assert.That(counter.OverallCount, Is.EqualTo(7));
                Assert.That(counter.SelectCount, Is.EqualTo(4)); // query + fetches
                Assert.That(counter.UpdateCount, Is.EqualTo(3)); // updates

                counter.Reset();
            }
        }
        public void LazyFieldHasCheckAlwaysConstraintTest()
        {
            var counter = new QueryCounter();

            using (var session = Domain.OpenSession()) {
                using (counter.Attach(session))
                    using (var transaction = session.OpenTransaction()) {
                        var goncharov = session.Query.Single <Author>(goncharovKey);
                        goncharov.FirstName = goncharov.FirstName + "modified"; // should prefetch lazy load field
                        transaction.Complete();
                    }
                Assert.That(counter.Count, Is.EqualTo(3));
                counter.Reset();
            }
        }
        public void LazyFieldHasNoConstraintTest()
        {
            var counter = new QueryCounter();

            using (var session = Domain.OpenSession()) {
                using (counter.Attach(session))
                    using (var transaction = session.OpenTransaction()) {
                        var oblomov = session.Query.Single <Book>(oblomovKey);
                        oblomov.Title = "Oblomov by Goncharov";
                        transaction.Complete();
                    }
                Assert.That(counter.Count, Is.EqualTo(2));
                counter.Reset();
            }
        }