When_save_revisioned_document_second_time_without_changing_version_Then_should_update_versioned_copy()
        {
            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = new RevisionedDocument {
                    Id = "key", Revision = 1, Data = "Alpha"
                };
                await session.StoreAsync(doc);

                await session.SaveChangesAsync();
            }

            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = await session.LoadAsync <RevisionedDocument>("key");

                doc.Data = "Beta";
                await session.SaveChangesAsync();
            }

            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = await session.LoadAsync <RevisionedDocument>("key");

                Assert.Equal("Beta", doc.Data);
            }

            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = await session.LoadRevision <RevisionedDocument>("key", 1);

                Assert.Equal("Beta", doc.Data);
            }
        }
		public void When_save_revisioned_document_second_time_without_changing_version_Then_should_update_versioned_copy()
		{
			using (var session = _documentStore.OpenSession())
			{
				var doc = new RevisionedDocument { Id = "key", Revision = 1, Data = "Alpha" };
				session.Store(doc);
				session.SaveChanges();
			}

			using (var session = _documentStore.OpenSession())
			{
				var doc = session.Load<RevisionedDocument>("key");
				doc.Data = "Beta";
				session.SaveChanges();
			}

			using (var session = _documentStore.OpenSession())
			{
				var doc = session.Load<RevisionedDocument>("key");
				Assert.Equal("Beta", doc.Data);
			}

			using (var session = _documentStore.OpenSession())
			{
				var doc = session.LoadRevision<RevisionedDocument>("key", 1);
				Assert.Equal("Beta", doc.Data);
			}
		}
		public void When_save_revisioned_document_Then_should_be_able_to_load_revision()
		{
			using (var session = _documentStore.OpenSession())
			{
				var doc = new RevisionedDocument { Id = "key", Revision = 1 };
				session.Store(doc);
				session.SaveChanges();
			}

			using (var session = _documentStore.OpenSession())
			{
				var doc = session.LoadRevision<RevisionedDocument>("key", 1);
				Assert.NotNull(doc);
			}
		}
        public async Task When_delete_revision_and_load_Then_should_get_null()
        {
            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = new RevisionedDocument { Id = "key", Revision = 1, Data = "Alpha" };
                await session.StoreAsync(doc);
                await session.SaveChangesAsync();
            }

            await _documentStore.AsyncDatabaseCommands.DeleteRevision("key", 1, null);

            using (var session = _documentStore.OpenAsyncSession())
            {
                Assert.Null(await session.LoadRevision<RevisionedDocument>("key", 1));
            }
        }
        public void When_save_revisioned_document_Then_should_be_able_to_load_revision()
        {
            using (var session = _documentStore.OpenSession())
            {
                var doc = new RevisionedDocument {
                    Id = "key", Revision = 1
                };
                session.Store(doc);
                session.SaveChanges();
            }

            using (var session = _documentStore.OpenSession())
            {
                var doc = session.LoadRevision <RevisionedDocument>("key", 1);
                Assert.NotNull(doc);
            }
        }
        public void When_delete_revision_and_load_Then_should_get_null()
        {
            using (var session = _documentStore.OpenSession())
            {
                var doc = new RevisionedDocument {
                    Id = "key", Revision = 1, Data = "Alpha"
                };
                session.Store(doc);
                session.SaveChanges();
            }

            _documentStore.DatabaseCommands.DeleteRevision("key", 1, null);

            using (var session = _documentStore.OpenSession())
            {
                Assert.Null(session.LoadRevision <RevisionedDocument>("key", 1));
            }
        }
        public void When_saving_a_modified_revision_document_Then_should_throw()
        {
            using (var session = _documentStore.OpenSession())
            {
                var doc = new RevisionedDocument {
                    Id = "key", Revision = 1, Data = "Alpha"
                };
                session.Store(doc);
                session.SaveChanges();
            }

            using (var session = _documentStore.OpenSession())
            {
                var doc = session.LoadRevision <RevisionedDocument>("key", 1);
                doc.Data = "Beta";
                Assert.Throws <OperationVetoedException>(() => session.SaveChanges());
            }
        }
        public void When_query_Then_revisioned_document_is_not_returned()
        {
            using (var session = _documentStore.OpenSession())
            {
                var doc = new RevisionedDocument {
                    Id = "key", Revision = 1, Data = "Alpha"
                };
                session.Store(doc);
                session.SaveChanges();
            }

            using (var session = _documentStore.OpenSession())
            {
                RevisionedDocument[] myVersionedDocuments = session.Query <RevisionedDocument>().Customize(q => q.WaitForNonStaleResults()).ToArray();
                Assert.Equal(1, myVersionedDocuments.Length);
                Assert.Equal("key", myVersionedDocuments[0].Id);
            }
        }
        public async Task When_save_revisioned_document_Then_should_be_able_to_load_revision()
        {
            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = new RevisionedDocument {
                    Id = "key", Revision = 1
                };
                await session.StoreAsync(doc);

                await session.SaveChangesAsync();
            }

            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = await session.LoadRevision <RevisionedDocument>("key", 1);

                Assert.NotNull(doc);
            }
        }
        public async Task When_delete_revision_and_load_Then_should_get_null()
        {
            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = new RevisionedDocument {
                    Id = "key", Revision = 1, Data = "Alpha"
                };
                await session.StoreAsync(doc);

                await session.SaveChangesAsync();
            }

            await _documentStore.AsyncDatabaseCommands.DeleteRevision("key", 1, null);

            using (var session = _documentStore.OpenAsyncSession())
            {
                Assert.Null(await session.LoadRevision <RevisionedDocument>("key", 1));
            }
        }
        public async Task When_saving_a_modified_revision_document_Then_should_throw()
        {
            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = new RevisionedDocument {
                    Id = "key", Revision = 1, Data = "Alpha"
                };
                await session.StoreAsync(doc);

                await session.SaveChangesAsync();
            }

            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = await session.LoadRevision <RevisionedDocument>("key", 1);

                doc.Data = "Beta";
                await Assert.ThrowsAnyAsync <Exception>(() => session.SaveChangesAsync());
            }
        }
        public async Task When_query_Then_revisioned_document_is_not_returned()
        {
            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = new RevisionedDocument { Id = "key", Revision = 1, Data = "Alpha" };
                await session.StoreAsync(doc);
                await session.SaveChangesAsync();
            }

            using (var session = _documentStore.OpenAsyncSession())
            {
                var myVersionedDocuments = await session
                    .Query<RevisionedDocument>()
                    .Customize(q => q.WaitForNonStaleResults())
                    .ToListAsync();

                Assert.Equal(1, myVersionedDocuments.Count);
                Assert.Equal("key", myVersionedDocuments[0].Id);
            }
        }
        public async Task When_query_Then_revisioned_document_is_not_returned()
        {
            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = new RevisionedDocument {
                    Id = "key", Revision = 1, Data = "Alpha"
                };
                await session.StoreAsync(doc);

                await session.SaveChangesAsync();
            }

            using (var session = _documentStore.OpenAsyncSession())
            {
                var myVersionedDocuments =
                    await session.Query <RevisionedDocument>().Customize(q => q.WaitForNonStaleResults()).ToListAsync();

                Assert.Equal(1, myVersionedDocuments.Count);
                Assert.Equal("key", myVersionedDocuments[0].Id);
            }
        }
        public async Task When_save_revisioned_document_Then_should_be_able_to_load_revision()
        {
            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = new RevisionedDocument { Id = "key", Revision = 1 };
                await session.StoreAsync(doc);
                await session.SaveChangesAsync();
            }

            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = await session.LoadRevision<RevisionedDocument>("key", 1);
                Assert.NotNull(doc);
            }
        }
		public void When_saving_a_modified_revision_document_Then_should_throw()
		{
			using (var session = _documentStore.OpenSession())
			{
				var doc = new RevisionedDocument { Id = "key", Revision = 1, Data = "Alpha" };
				session.Store(doc);
				session.SaveChanges();
			}

			using (var session = _documentStore.OpenSession())
			{
				var doc = session.LoadRevision<RevisionedDocument>("key", 1);
				doc.Data = "Beta";
				Assert.Throws<OperationVetoedException>(() => session.SaveChanges());
			}
		}
		public void When_query_Then_revisioned_document_is_not_returned()
		{
			using (var session = _documentStore.OpenSession())
			{
				var doc = new RevisionedDocument { Id = "key", Revision = 1, Data = "Alpha" };
				session.Store(doc);
				session.SaveChanges();
			}

			using (var session = _documentStore.OpenSession())
			{
				RevisionedDocument[] myVersionedDocuments = session.Query<RevisionedDocument>().Customize(q => q.WaitForNonStaleResults()).ToArray();
				Assert.Equal(1, myVersionedDocuments.Length);
				Assert.Equal("key", myVersionedDocuments[0].Id);
			}
		}
		public void When_delete_revision_and_load_Then_should_get_null()
		{
			using (var session = _documentStore.OpenSession())
			{
				var doc = new RevisionedDocument { Id = "key", Revision = 1, Data = "Alpha" };
				session.Store(doc);
				session.SaveChanges();
			}

			_documentStore.DatabaseCommands.DeleteRevision("key", 1, null);

			using (var session = _documentStore.OpenSession())
			{
				Assert.Null(session.LoadRevision<RevisionedDocument>("key", 1));
			}
		}
        public async Task When_saving_a_modified_revision_document_Then_should_throw()
        {
            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = new RevisionedDocument { Id = "key", Revision = 1, Data = "Alpha" };
                await session.StoreAsync(doc);
                await session.SaveChangesAsync();
            }

            using (var session = _documentStore.OpenAsyncSession())
            {
                var doc = await session.LoadRevision<RevisionedDocument>("key", 1);
                doc.Data = "Beta";
                await Assert.ThrowsAnyAsync<Exception>(() => session.SaveChangesAsync());
            }
        }