public void Should_use_context()
        {
            using (IDocumentSession session = DocumentStore.OpenSession())
            {
                var doc = new Doc {Id = "Doc", Name = "Name"};
                session.Store(doc);
                session.SaveChanges();
            }

            using (var storeContext = new StoreContext())
            using (var deleteContext = new DeleteContext())
            using (var queryContext = new QueryContext())
            using (var conversionContext = new ConversionContext())
            using (IDocumentSession session = DocumentStore.OpenSession())
            {
                var doc1 = new Doc {Id = "Doc1"};
                session.Store(doc1);
                Doc doc2 =
                    session.Query<Doc>()
                        .Where(d => d.Name == "Name")
                        .Customize(c => c.WaitForNonStaleResults())
                        .Single();
                session.Delete(doc2);
                session.SaveChanges();
                Assert.True(storeContext.AfterStoreCalled);
                Assert.True(storeContext.BeforeStoreCalled);
                Assert.True(deleteContext.BeforeDeleteCalled);
                Assert.True(queryContext.BeforeQueryExecutedCalled);
                Assert.True(conversionContext.DocumentToEntityCalled);
                Assert.True(conversionContext.EntityToDocumentCalled);
            }
        }
 public void When_no_context_Then_should_not_throw()
 {
     using (IDocumentSession session = DocumentStore.OpenSession())
     {
         var doc = new Doc {Id = "Doc"};
         session.Store(doc);
         Assert.DoesNotThrow(session.SaveChanges);
     }
 }
 public void Should_use_context()
 {
     using (var context = new StoreContext())
     using (IDocumentSession session = DocumentStore.OpenSession())
     {
         var doc = new Doc {Id = "Doc"};
         session.Store(doc);
         session.SaveChanges();
         Assert.True(context.BeforeStoreCalled);
         Assert.True(context.AfterStoreCalled);
     }
 }
        public void Should_use_context()
        {
            using (IDocumentSession session = DocumentStore.OpenSession())
            {
                var doc = new Doc {Id = "Doc"};
                session.Store(doc);
                session.SaveChanges();
            }

            using (var context = new DeleteContext())
            using (IDocumentSession session = DocumentStore.OpenSession())
            {
                var doc = session.Load<Doc>("Doc");
                session.Delete(doc);
                session.SaveChanges();
                Assert.True(context.BeforeDeleteCalled);
            }
        }
        public void Should_use_context()
        {
            using (IDocumentSession session = DocumentStore.OpenSession())
            {
                var doc = new Doc {Id = "Doc", Name = "Name"};
                session.Store(doc);
                session.SaveChanges();
            }

            using (var context = new QueryContext())
            using (IDocumentSession session = DocumentStore.OpenSession())
            {
                session.Query<Doc>()
                    .Where(d => d.Name == "Name")
                    .Customize(c => c.WaitForNonStaleResultsAsOfLastWrite())
                    .ToList();
                Assert.True(context.BeforeQueryExecutedCalled);
            }
        }
        public void Should_use_context()
        {
            using (var context = new ConversionContext())
            {
                using (var session = DocumentStore.OpenSession())
                {
                    var doc = new Doc { Id = "Doc" };
                    session.Store(doc);
                    session.SaveChanges();
                    Assert.True(context.EntityToDocumentCalled);
                }
            }

            using (var context = new ConversionContext())
            {
                using (var session = DocumentStore.OpenSession())
                {
                    session.Load<Doc>("Doc");
                    Assert.True(context.DocumentToEntityCalled);
                }
            }
        }
        public async Task Should_use_context_async()
        {
            using (var context = new ConversionContext())
            {
                using (var session = DocumentStore.OpenAsyncSession())
                {
                    var doc = new Doc {Id = "Doc"};
                    await session.StoreAsync(doc);
                    await session.SaveChangesAsync();
                    Assert.True(context.EntityToDocumentCalled);
                }
            }

            using (var context = new ConversionContext())
            {
                using (var session = DocumentStore.OpenAsyncSession())
                {
                    await session.LoadAsync<Doc>("Doc");
                    Assert.True(context.DocumentToEntityCalled);
                }
            }
        }
        public void Should_support_nested_sessions()
        {
            using (var context1 = new StoreContext())
            using (IDocumentSession session1 = DocumentStore.OpenSession())
            {
                var doc1 = new Doc {Id = "Doc1"};
                session1.Store(doc1);

                using (var context2 = new StoreContext())
                using (IDocumentSession session2 = DocumentStore.OpenSession())
                {
                    var doc2 = new Doc {Id = "Doc2"};
                    session2.Store(doc2);
                    session2.SaveChanges();
                    Assert.True(context2.BeforeStoreCalled);
                    Assert.True(context2.AfterStoreCalled);
                }

                session1.SaveChanges();
                Assert.True(context1.BeforeStoreCalled);
                Assert.True(context1.AfterStoreCalled);
            }
        }