public void Can_promote_transactions()
        {
            var documentStore = new DocumentStore {Url = "http://localhost:8080"};
            documentStore.Initialize();

            var company = new Company {Name = "Company Name"};

            using (var tx = new TransactionScope())
            {
                var session = documentStore.OpenSession();
                session.Store(company);
                session.SaveChanges();

                Assert.Equal(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);

                using (var session3 = documentStore.OpenSession())
                {
                    session3.Store(new Company {Name = "Another company"});
                    session3.SaveChanges(); // force a dtc promotion

                    Assert.NotEqual(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);
                }

                tx.Complete();
            }
            for (int i = 0; i < 15; i++)// wait for commit
            {
                using (var session2 = documentStore.OpenSession())
                    if (session2.Load<Company>(company.Id) != null)
                        break;
                Thread.Sleep(100);
            }
            using (var session2 = documentStore.OpenSession())
                Assert.NotNull((session2.Load<Company>(company.Id)));
        }
		public WhenUsingShardedServers()
		{
			const string server = "localhost";

			const int port1 = 8079;
			const int port2 = 8081;

			path1 = GetPath("TestShardedDb1");
			path2 = GetPath("TestShardedDb2");

			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port1);
			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port2);

			company1 = new Company { Name = "Company1" };
			company2 = new Company { Name = "Company2" };

			server1 = GetNewServer(port1, path1);
			server2 = GetNewServer(port2, path2);

			shards = new List<IDocumentStore> { 
				new DocumentStore { Identifier="Shard1", Url = "http://" + server +":"+port1}, 
				new DocumentStore { Identifier="Shard2", Url = "http://" + server +":"+port2} 
			}.ToDictionary(x => x.Identifier, x => x);

			shardResolution = MockRepository.GenerateStub<IShardResolutionStrategy>();
			shardResolution.Stub(x => x.GenerateShardIdFor(company1)).Return("Shard1");
			shardResolution.Stub(x => x.GenerateShardIdFor(company2)).Return("Shard2");

			shardResolution.Stub(x => x.MetadataShardIdFor(company1)).Return("Shard1");
			shardResolution.Stub(x => x.MetadataShardIdFor(company2)).Return("Shard1");

			shardStrategy = new ShardStrategy(shards) { ShardResolutionStrategy = shardResolution };
		}
        public void Can_insert_into_two_servers_running_simultaneously_without_sharding()
        {
            var serversStoredUpon = new List<string>();

            using (var server1 = GetNewServer(port1, path1))
            using (var server2 = GetNewServer(port2, path2))
            {
                foreach (var port in new[] { port1, port2 })
                {
                    using (var documentStore = new DocumentStore { Url = "http://localhost:"+ port }.Initialize())
                    using (var session = documentStore.OpenSession())
                    {
                        documentStore.Stored += (sender, args) => serversStoredUpon.Add(args.SessionIdentifier);

                        var entity = new Company { Name = "Company" };
                        session.Store(entity);
                        session.SaveChanges();
                        Assert.NotEqual(Guid.Empty.ToString(), entity.Id);
                    }
                }
            }

            Assert.Contains(port1.ToString(), serversStoredUpon[0]);
            Assert.Contains(port2.ToString(), serversStoredUpon[1]);
        }
		public void Can_promote_transactions()
		{
			var documentStore = new DocumentStore {Url = "http://localhost:8080"};
			documentStore.Initialize();

			var company = new Company {Name = "Company Name"};

			using (var tx = new TransactionScope())
			{
				var session = documentStore.OpenSession();
				session.Store(company);
				session.SaveChanges();

				Assert.Equal(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);

				Transaction.Current.EnlistDurable(ManyDocumentsViaDTC.DummyEnlistmentNotification.Id,
				                                  new ManyDocumentsViaDTC.DummyEnlistmentNotification(), EnlistmentOptions.None);

				Assert.NotEqual(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);


				tx.Complete();
			}
			for (int i = 0; i < 15; i++)// wait for commit
			{
				using (var session2 = documentStore.OpenSession())
					if (session2.Load<Company>(company.Id) != null)
						break;
				Thread.Sleep(100);
			}
			using (var session2 = documentStore.OpenSession())
				Assert.NotNull((session2.Load<Company>(company.Id)));
		}
示例#5
0
		public IEnumerable<Task> CanPerformASimpleWhere()
		{
			var dbname = GenerateNewDatabaseName();
			using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
			{
				yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

				var entity = new Company {Name = "Async Company #1", Id = "companies/1"};
				using (var session = documentStore.OpenAsyncSession(dbname))
				{
					session.Store(entity);
					yield return session.SaveChangesAsync();
				}

				using (var session = documentStore.OpenAsyncSession(dbname))
				{
					var query = session.Query<Company>()
						.Where(x => x.Name == "Async Company #1")
						.ToListAsync();
					yield return query;

					Assert.AreEqual(1, query.Result.Count);
					Assert.AreEqual("Async Company #1", query.Result[0].Name);
				}
			}
		}
		public When_Using_Sharded_Servers()
		{
			server = "localhost";

			port1 = 8079;
			port2 = 8081;

			path1 = GetPath("TestShardedDb1");
			path2 = GetPath("TestShardedDb2");

			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port1);
			NonAdminHttp.EnsureCanListenToWhenInNonAdminContext(port2);

			company1 = new Company { Name = "Company1" };
			company2 = new Company { Name = "Company2" };

			server1 = GetNewServer(port1, path1);
			server2 = GetNewServer(port2, path2);

			shards = new Shards { 
				new DocumentStore { Identifier="Shard1", Url = "http://" + server +":"+port1}, 
				new DocumentStore { Identifier="Shard2", Url = "http://" + server +":"+port2} 
			};

			shardSelection = MockRepository.GenerateStub<IShardSelectionStrategy>();
			shardSelection.Stub(x => x.ShardIdForNewObject(company1)).Return("Shard1");
			shardSelection.Stub(x => x.ShardIdForNewObject(company2)).Return("Shard2");

			shardResolution = MockRepository.GenerateStub<IShardResolutionStrategy>();

			shardStrategy = MockRepository.GenerateStub<IShardStrategy>();
			shardStrategy.Stub(x => x.ShardSelectionStrategy).Return(shardSelection);
			shardStrategy.Stub(x => x.ShardResolutionStrategy).Return(shardResolution);
		}
示例#7
0
		public IEnumerable<Task> CanGetTotalCount()
		{
			var dbname = GenerateNewDatabaseName();
			using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
			{
				yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

				var entity = new Company {Name = "Async Company #1", Id = "companies/1"};
				using (var session = documentStore.OpenAsyncSession(dbname))
				{
					session.Store(entity);
					yield return session.SaveChangesAsync();
				}

				using (var session = documentStore.OpenAsyncSession(dbname))
				{
					RavenQueryStatistics stats;
					var query = session.Query<Company>()
						.Customize(x => x.WaitForNonStaleResults())
						.Statistics(out stats)
						.Where(x => x.Name == "Async Company #1")
						.CountAsync();
					yield return query;

					Assert.AreEqual(1, query.Result);
				}
			}
		}
		public IEnumerable<Task> CanInsertAsyncAndMultiGetAsync()
		{
			var dbname = GenerateNewDatabaseName();
			using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
			{
				yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

				var entity1 = new Company {Name = "Async Company #1"};
				var entity2 = new Company {Name = "Async Company #2"};
				using (var session_for_storing = documentStore.OpenAsyncSession(dbname))
				{
					session_for_storing.Store(entity1);
					session_for_storing.Store(entity2);
					yield return session_for_storing.SaveChangesAsync();
				}

				using (var session_for_loading = documentStore.OpenAsyncSession(dbname))
				{
					var task = session_for_loading.LoadAsync<Company>(new[] {entity1.Id, entity2.Id});
					yield return task;

					Assert.AreEqual(entity1.Name, task.Result[0].Name);
					Assert.AreEqual(entity2.Name, task.Result[1].Name);
				}
			}
		}
        public WhenUsingShardedServers()
        {
            const string server = "localhost";

            const int port1 = 8079;
            const int port2 = 8081;

            company1 = new Company { Name = "Company1" };
            company2 = new Company { Name = "Company2" };

            server1 = GetNewServer(port1);
            server2 = GetNewServer(port2);

            shards = new List<IDocumentStore> {
                new DocumentStore { Identifier="Shard1", Url = "http://" + server +":"+port1},
                new DocumentStore { Identifier="Shard2", Url = "http://" + server +":"+port2}
            }.ToDictionary(x => x.Identifier, x => x);

            shardResolution = MockRepository.GenerateStub<IShardResolutionStrategy>();
            shardResolution.Stub(x => x.GenerateShardIdFor(Arg.Is(company1), Arg<ITransactionalDocumentSession>.Is.Anything)).Return("Shard1");
            shardResolution.Stub(x => x.GenerateShardIdFor(Arg.Is(company2), Arg<ITransactionalDocumentSession>.Is.Anything)).Return("Shard2");

            shardResolution.Stub(x => x.MetadataShardIdFor(company1)).Return("Shard1");
            shardResolution.Stub(x => x.MetadataShardIdFor(company2)).Return("Shard1");

            shardStrategy = new ShardStrategy(shards) { ShardResolutionStrategy = shardResolution };
        }
		public void WillGetNotificationWhenReadingNonAuthoritativeInformation()
		{
			var company = new Company { Name = "Company Name" };
			using (var session = documentStore.OpenSession())
			{
				using (var original = documentStore.OpenSession())
				{
					original.Store(company);
					original.SaveChanges();
				}
				using (new TransactionScope())
				{
					session.Load<Company>(company.Id).Name = "Another Name";
					session.SaveChanges();

					using (new TransactionScope(TransactionScopeOption.Suppress))
					{
						using (var session2 = documentStore.OpenSession())
						{
							session2.Advanced.AllowNonAuthoritativeInformation = false;
							session2.Advanced.NonAuthoritativeInformationTimeout = TimeSpan.Zero;
							Assert.Throws<NonAuthoritativeInformationException>(() => session2.Load<Company>(company.Id));
						}
					}
				}
			}
		}
		public void WhenDocumentAlreadyExists_Can_Still_Generate_Values()
		{
			using (var store = NewDocumentStore())
			{
				var mk = new MultiTypeHiLoKeyGenerator(store, 5);
				store.Conventions.DocumentKeyGenerator = o => mk.GenerateDocumentKey(store.Conventions, o);

				
				using (var session = store.OpenSession())
				{
					var company = new Company();
					session.Store(company);
					var contact = new Contact();
					session.Store(contact);

					Assert.Equal("companies/1", company.Id);
					Assert.Equal("contacts/1", contact.Id);
				}

				mk = new MultiTypeHiLoKeyGenerator(store, 5);
				store.Conventions.DocumentKeyGenerator = o => mk.GenerateDocumentKey(store.Conventions, o);

				using (var session = store.OpenSession())
				{
					var company = new Company();
					session.Store(company);
					var contact = new Contact();
					session.Store(contact);

					Assert.Equal("companies/6", company.Id);
					Assert.Equal("contacts/6", contact.Id);
				}
			}
		}
		public void Should_insert_into_db_and_set_id()
		{
			using (var session = documentStore.OpenSession())
			{
				var entity = new Company {Name = "Company"};
				session.Store(entity);
				session.SaveChanges();
				Assert.NotEqual(Guid.Empty.ToString(), entity.Id);
			}
		}
		public void Can_promote_transactions()
		{
			var process = Process.Start(GetRavenServerPath(), "--ram --set=Raven/Port==8079");
			try
			{
				WaitForNetwork("http://localhost:8079");

				var documentStore = new DocumentStore { Url = "http://localhost:8079" };
				documentStore.Initialize();

				var company = new Company { Name = "Company Name" };
				var durableEnlistment = new ManyDocumentsViaDTC.DummyEnlistmentNotification();
				using (var tx = new TransactionScope())
				{
					var session = documentStore.OpenSession();
					session.Store(company);
					session.SaveChanges();

					Assert.Equal(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);

					Transaction.Current.EnlistDurable(ManyDocumentsViaDTC.DummyEnlistmentNotification.Id,
													  durableEnlistment, EnlistmentOptions.None);

					Assert.NotEqual(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);


					tx.Complete();
				}


				for (int i = 0; i < 15; i++)// wait for commit
				{
					using (var session2 = documentStore.OpenSession())
						if (session2.Load<Company>(company.Id) != null)
							break;
					Thread.Sleep(100);
				}
				using (var session2 = documentStore.OpenSession())
					Assert.NotNull((session2.Load<Company>(company.Id)));

				for (int i = 0; i < 15; i++) // we have to wait to be notified, too
				{
					if(durableEnlistment.WasCommitted == false)
						Thread.Sleep(100);
				}

				Assert.True(durableEnlistment.WasCommitted);

			}
			finally
			{
				process.Kill();
			}
		}
示例#14
0
        public void IdIsSetFromGeneratorOnStore()
        {
            using (var store = NewDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    Company company = new Company();
                    session.Store(company);

                    Assert.Equal("companies/1", company.Id);
                }
            }
        }
		public void Should_insert_into_db_and_set_id()
		{
			using (var server = GetNewServer(port, path))
			{
				var documentStore = new DocumentStore { Url = "http://localhost:"+ port };
				documentStore.Initialize();

				var session = documentStore.OpenSession();
				var entity = new Company {Name = "Company"};
				session.Store(entity);
				session.SaveChanges();
				Assert.NotEqual(Guid.Empty.ToString(), entity.Id);
			}
		}
		public void Can_promote_transactions()
		{
			using (var driver = new RavenDBDriver("HelloShard", new DocumentConvention()))
			{
				driver.Start();

				WaitForNetwork(driver.Url);

				using (var documentStore = new DocumentStore { Url = driver.Url  }.Initialize())
				{
					var company = new Company {Name = "Company Name"};
					var durableEnlistment = new ManyDocumentsViaDTC.DummyEnlistmentNotification();
					using (var tx = new TransactionScope())
					{
						var session = documentStore.OpenSession();
						session.Store(company);
						session.SaveChanges();

						Assert.Equal(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);

						Transaction.Current.EnlistDurable(ManyDocumentsViaDTC.DummyEnlistmentNotification.Id,
						                                  durableEnlistment, EnlistmentOptions.None);

						Assert.NotEqual(Guid.Empty, Transaction.Current.TransactionInformation.DistributedIdentifier);


						tx.Complete();
					}


					for (int i = 0; i < 15; i++) // wait for commit
					{
						using (var session2 = documentStore.OpenSession())
							if (session2.Load<Company>(company.Id) != null)
								break;
						Thread.Sleep(100);
					}
					using (var session2 = documentStore.OpenSession())
						Assert.NotNull((session2.Load<Company>(company.Id)));

					for (int i = 0; i < 15; i++) // we have to wait to be notified, too
					{
						if (durableEnlistment.WasCommitted == false)
							Thread.Sleep(100);
					}

					Assert.True(durableEnlistment.WasCommitted);
				}
			}
		}
示例#17
0
		public void CompositeIdIsSetAfterSaveChanges()
		{
			using (var store = NewDocumentStore())
			{
				using (var session = store.OpenSession())
				{
					Company company = new Company();
					company.Id = "country/2/companies/";

					session.Store(company);
					session.SaveChanges();
					Assert.Equal("country/2/companies/1", company.Id);
				}
			}
		}
        public async Task Can_insert_sync_and_get_async()
        {
            var entity = new Company {Name = "Async Company"};
            using (var session = DocumentStore.OpenSession())
            {
                session.Store(entity);
                session.SaveChanges();
            }

            using (var session = DocumentStore.OpenAsyncSession())
            {
                var task = await session.LoadAsync<Company>(entity.Id);
                Assert.Equal("Async Company", task.Name);
            }
        }
		public void Can_insert_async_and_get_sync()
		{
			var entity = new Company {Name = "Async Company"};
			using (var session = documentStore.OpenAsyncSession())
			{
				session.Store(entity);
				session.SaveChangesAsync().Wait();
			}

			using (var session = documentStore.OpenSession())
			{
				var company = session.Load<Company>(entity.Id);

				Assert.Equal("Async Company", company.Name);
			}
		}
示例#20
0
        public void DifferentTypesWillHaveDifferentIdGenerators()
        {
            using (var store = NewDocumentStore())
            {
                using (var session = store.OpenSession())
                {
                    var company = new Company();
                    session.Store(company);
                    var contact = new Contact();
                    session.Store(contact);

                    Assert.Equal("companies/1", company.Id);
                    Assert.Equal("contacts/1", contact.Id);
                }
            }
        }
        public void After_tx_rollback_value_will_not_be_in_the_database()
        {
            using (var documentStore = NewDocumentStore())
            {
                var company = new Company { Name = "Company Name" };
                var session = documentStore.OpenSession();
                using (new TransactionScope())
                {
                    session.Store(company);
                    session.SaveChanges();

                }
                using (var session2 = documentStore.OpenSession())
                    Assert.Null(session2.Load<Company>(company.Id));
            }
        }
示例#22
0
        public void TotalResultIsIncludedInQueryResult()
        {
            using (var server = GetNewServer(port, path))
            {
                using (var store = new DocumentStore { Url = "http://localhost:" + port })
                {
                    store.Initialize();

                    using (var session = store.OpenSession())
                    {
                        Company company1 = new Company()
                        {
                            Name = "Company1",
                            Address1 = "",
                            Address2 = "",
                            Address3 = "",
                            Contacts = new List<Contact>(),
                            Phone = 2
                        };
                        Company company2 = new Company()
                        {
                            Name = "Company2",
                            Address1 = "",
                            Address2 = "",
                            Address3 = "",
                            Contacts = new List<Contact>(),
                            Phone = 2
                        };

                        session.Store(company1);
                        session.Store(company2);
                        session.SaveChanges();
                    }

                    using (var session = store.OpenSession())
                    {
                        int resultCount = session.Advanced.LuceneQuery<Company>().WaitForNonStaleResults().QueryResult.TotalResults;
                        Assert.Equal(2, resultCount);
                    }
                }
            }
              
           

        }
		public void Can_insert_async_and_multi_get_async()
		{
			var entity1 = new Company {Name = "Async Company #1"};
			var entity2 = new Company {Name = "Async Company #2"};
			using (var session = documentStore.OpenAsyncSession())
			{
				session.Store(entity1);
				session.Store(entity2);
				session.SaveChangesAsync().Wait();
			}

			using (var session = documentStore.OpenAsyncSession())
			{
				var task = session.LoadAsync<Company>(new[] {entity1.Id, entity2.Id});
				Assert.Equal(entity1.Name, task.Result[0].Name);
				Assert.Equal(entity2.Name, task.Result[1].Name);
			}
		}
		public void CanInsertIntoTwoServersRunningSimultaneouslyWithoutSharding()
		{
			using (var server1 = GetNewServer(port1))
			using (var server2 = GetNewServer(port2))
			{
				foreach (var port in new[] { port1, port2 })
				{
					using (var documentStore = new DocumentStore { Url = "http://localhost:"+ port }.Initialize())
					using (var session = documentStore.OpenSession())
					{
						var entity = new Company { Name = "Company" };
						session.Store(entity);
						session.SaveChanges();
						Assert.NotEqual(Guid.Empty.ToString(), entity.Id);
					}
				}
			}
		}
示例#25
0
		public IEnumerable<Task> ShouldGetNotifications()
		{
			var dbname = GenerateNewDatabaseName();
			
			var tcs = new TaskCompletionSource<DocumentChangeNotification>();
			using (var documentStore = new DocumentStore
			{
				Url = Url + Port,
			}.Initialize())
			{
				yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

				var taskObservable = documentStore.Changes(dbname);

				yield return taskObservable.Task;

				var observableWithTask = taskObservable.ForDocument("companies/1");

				yield return observableWithTask.Task;

				observableWithTask
					.Subscribe(tcs.SetResult);

				var entity1 = new Company { Name = "Async Company #1" };
				using (var session_for_storing = documentStore.OpenAsyncSession(dbname))
				{
					session_for_storing.Store(entity1,"companies/1");
					yield return session_for_storing.SaveChangesAsync();
				}

				Task.Factory.StartNew(() =>
				{
					Thread.Sleep(5000);
					tcs.TrySetCanceled();
				});

				yield return tcs.Task;

				Assert.AreEqual("companies/1", tcs.Task.Result.Id);
			}
		}
		public void CanUseTransactionsToIsolateSaves()
		{
			var company = new Company { Name = "Company Name" };
			using (var session = documentStore.OpenSession())
			{
				using (var tx = new TransactionScope())
				{
					session.Store(company);
					session.SaveChanges();

					using (new TransactionScope(TransactionScopeOption.Suppress))
					{
						using (var session2 = documentStore.OpenSession())
							Assert.Null(session2.Load<Company>(company.Id));

						tx.Complete();
					}
				}
				Assert.NotNull(session.Load<Company>(company.Id));
			}
		}
		public IEnumerable<Task> CanInsertAsyncAndDeleteAsync()
		{
			var dbname = GenerateNewDatabaseName();
			using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
			{
				yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);

				var entity = new Company {Name = "Async Company #1", Id = "companies/1"};
				using (var session = documentStore.OpenAsyncSession(dbname))
				{
					session.Store(entity);
					yield return session.SaveChangesAsync();
				}

				using (var for_loading = documentStore.OpenAsyncSession(dbname))
				{
					var loading = for_loading.LoadAsync<Company>(entity.Id);
					yield return loading;
					Assert.IsNotNull(loading.Result);
				}

				using (var for_deleting = documentStore.OpenAsyncSession(dbname))
				{
					var loading = for_deleting.LoadAsync<Company>(entity.Id);
					yield return loading;

					for_deleting.Delete(loading.Result);
					yield return for_deleting.SaveChangesAsync();
				}

				using (var for_verifying = documentStore.OpenAsyncSession(dbname))
				{
					var verification = for_verifying.LoadAsync<Company>(entity.Id);
					yield return verification;

					Assert.IsNull(verification.Result);
				}
			}
		}
        public void Can_insert_async_and_get_sync()
		{
			using (var server = GetNewServer(port, path))
			{
				var documentStore = new DocumentStore { Url = "http://localhost:" + port };
				documentStore.Initialize();

				var entity = new Company { Name = "Async Company" };
				using (var session = documentStore.OpenAsyncSession())
				{
					session.Store(entity);
					session.SaveChangesAsync().Wait();
				}

				using (var session = documentStore.OpenSession())
				{
					var company = session.Load<Company>(entity.Id);

					Assert.Equal("Async Company", company.Name);
				}
			}
		}
示例#29
0
        public void Can_use_transactions_to_isolate_saves()
        {
            using (var documentStore = NewDocumentStore())
            {
                var company = new Company { Name = "Company Name" };
                var session = documentStore.OpenSession();
                using (RavenTransactionAccessor.StartTransaction())
                {
                    session.Store(company);
                    session.SaveChanges();

                    using (RavenTransactionAccessor.StartTransaction())
                    {
                        using (var session2 = documentStore.OpenSession())
                            Assert.Null(session2.Load<Company>(company.Id));
                    }
                    Assert.NotNull(session.Load<Company>(company.Id));
                    documentStore.DatabaseCommands.Commit(RavenTransactionAccessor.GetTransactionInformation().Id);
                }
                Assert.NotNull(session.Load<Company>(company.Id));
            }
        }
示例#30
0
        public void KeysGeneratedFromDifferentSessionsAreConsecutive()
        {
            using(var store = NewDocumentStore())
            {
                var c1 = new Company();
                var c2 = new Company();

                using(var s = store.OpenSession())
                {
                    s.Store(c1);
                    s.SaveChanges();
                }

                using (var s = store.OpenSession())
                {
                    s.Store(c2);
                    s.SaveChanges();
                }

                Assert.Equal("companies/1", c1.Id);
                Assert.Equal("companies/2", c2.Id);
            }
        }