Esempio n. 1
0
		public void WorkWithTransactionAndNoAllowNonAutoritiveInformation()
		{
			using (var store = new EmbeddableDocumentStore
			{
				RunInMemory = true
			}.Initialize())
			{
				using (new TransactionScope())
				{
					using (IDocumentSession session = store.OpenSession())
					{
						var user = new User {Id = "users/[email protected]"};
						session.Store(user);
						session.SaveChanges();
					}

					using(new TransactionScope(TransactionScopeOption.Suppress))
					using (IDocumentSession session = store.OpenSession())
					{
						var user = session.Load<User>("users/[email protected]");
						Assert.Null(user);
					}
				}

				
			}
		}
Esempio n. 2
0
		public void CanUseDeferred()
		{
			string userId;
			using (var session = documentStore.OpenSession())
			{
				var entity = new User();
				session.Store(entity);
				userId = entity.Id;
				session.SaveChanges();
			}

			using(var session = documentStore.OpenSession())
			{
				Assert.NotNull(session.Load<User>(userId));
			}

			using (var session = documentStore.OpenSession())
			{
				session.Advanced.Defer(new DeleteCommandData
				{
					Key = userId
				});

				session.SaveChanges();
			}

			using (var session = documentStore.OpenSession())
			{
				Assert.Null(session.Load<User>(userId));
			}
		}
		public void LastModifiedUsesCorrectDateTimeFormatInIndex()
		{
			using (var store = NewDocumentStore())
			{
				new RavenDocumentsByEntityName().Execute(store);

				var user = new User { Name = "John Doe" };
				using (var session = store.OpenSession())
				{
					session.Store(user);
					session.SaveChanges();
				}

				using (var session = store.OpenSession())
				{
					user = session.Load<User>("users/1");
					var ravenJObject = session.Advanced.GetMetadataFor(user);
					var dateTime = ravenJObject.Value<DateTime>("Last-Modified");
					var results = session.Advanced.LuceneQuery<object>(new RavenDocumentsByEntityName().IndexName)
						.WhereEquals("LastModified", DateTools.DateToString(dateTime, DateTools.Resolution.MILLISECOND))
						.WaitForNonStaleResults()
						.ToArray();
					Assert.Equal(1, results.Count());
				}
			}
		}
Esempio n. 4
0
		public void CanMarkEntityAsReadOnly()
		{
			using(var store = NewDocumentStore())
			{
				using(var session = store.OpenSession())
				{
					var entity = new User {Name = "Ayende"};
					session.Store(entity);
					session.Advanced.GetMetadataFor(entity)[Constants.RavenReadOnly] = true;
					session.SaveChanges();
				}

				using (var session = store.OpenSession())
				{
					var user = session.Load<User>("users/1");
					user.Name = "Oren";
					session.SaveChanges();
				}

				using (var session = store.OpenSession())
				{
					var user = session.Load<User>("users/1");
					Assert.Equal("Ayende", user.Name);
				}
			}
		}
Esempio n. 5
0
		public void CanQueryDtcForUncommittedItem()
		{
			using (GetNewServer())
			using (var store = new DocumentStore { Url = "http://localhost:8080" }.Initialize())
			{
				for (int i = 0; i < 150; i++)
				{
					string id;
					using (var tx = new TransactionScope())
					{
						System.Transactions.Transaction.Current.EnlistDurable(ManyDocumentsViaDTC.DummyEnlistmentNotification.Id,
																			  new ManyDocumentsViaDTC.DummyEnlistmentNotification(),
																			  EnlistmentOptions.None);

						using (var session = store.OpenSession())
						{
							var entity = new User();
							session.Store(entity);
							session.SaveChanges();
							id = entity.Id;
						}


						tx.Complete();
					}
					using (var session = store.OpenSession())
					{
						session.Advanced.AllowNonAuthoritiveInformation = false;
						var user = session.Load<User>(id);
						Assert.NotNull(user);
					}
				}
			}
		}
Esempio n. 6
0
        public void CanQueryDefaultDatabaseQuickly()
        {
            using (GetNewServer(8080))
            using (var store = new DocumentStore
            {
                Url = "http://localhost:8080"
            }.Initialize())
            {
                store.DatabaseCommands.EnsureDatabaseExists("Northwind");

                using (var s = store.OpenSession("Northwind"))
                {
                    var entity = new User
                    {
                        Name = "Hello",
                    };
                    s.Store(entity);
                    s.SaveChanges();
                }

                var sp = Stopwatch.StartNew();
                using (var s = store.OpenSession())
                {
                    Assert.Empty(s.Query<User>().Where(x => x.Name == "Hello"));
                }
                Assert.True(TimeSpan.FromSeconds(5) > sp.Elapsed);
            }
        }
Esempio n. 7
0
        public void CanCreateDatabaseUsingExtensionMethod()
        {
            using (GetNewServer(8080))
            using (var store = new DocumentStore
            {
                Url = "http://localhost:8080"
            }.Initialize())
            {
                store.DatabaseCommands.EnsureDatabaseExists("Northwind");

                string userId;

                using (var s = store.OpenSession("Northwind"))
                {
                    var entity = new User
                    {
                        Name = "First Mutlti Tenant Bank",
                    };
                    s.Store(entity);
                    userId = entity.Id;
                    s.SaveChanges();
                }

                using (var s = store.OpenSession())
                {
                    Assert.Null(s.Load<User>(userId));
                }

                using (var s = store.OpenSession("Northwind"))
                {
                    Assert.NotNull(s.Load<User>(userId));
                }
            }
        }
Esempio n. 8
0
		public void CanBeUpdated()
		{
			using (var store = NewDocumentStore())
			{
				using (var s = store.OpenSession())
				{
					for (int i = 0; i < 5; i++)
					{
						var clone = new User { Name = "Ayende #" + i };
						s.Store(clone);
					}
					s.SaveChanges();
				}

				using (var s = store.OpenSession())
				{
					for (int i = 0; i < 5; i++)
					{
						var clone = s.Load<User>("users/" + (i + 1));
						clone.Name = "Rahien #" + i;
					}
					s.SaveChanges();
				}

				using (var s = store.OpenSession())
				{
					for (int i = 0; i < 5; i++)
					{
						Assert.Equal("Rahien #" + i, s.Load<User>("users/" + (i + 1)).Name);
					}
				}
			}
		}
Esempio n. 9
0
		public void CanBeDeleted()
		{
			using (var store = NewDocumentStore())
			{
				using (var s = store.OpenSession())
				{
					for (int i = 0; i < 5; i++)
					{
						var clone = new User { Name = "Ayende #" + i };
						s.Store(clone);
					}
					s.SaveChanges();
				}

				using (var s = store.OpenSession())
				{
					for (int i = 0; i < 5; i++)
					{
						var clone = s.Load<User>("users/" + (i + 1));
						s.Delete(clone);
					}
					s.SaveChanges();
				}

				using (var s = store.OpenSession())
				{
					for (int i = 0; i < 5; i++)
					{
						Assert.Null(s.Load<User>("users/" + (i + 1)));
					}
				}
			}
		}
Esempio n. 10
0
		public void CanUseMultiGetToBatchGetDocumentRequests()
		{
			using (GetNewServer())
			using (var docStore = new DocumentStore {Url = "http://localhost:8079"}.Initialize())
			{
				for (int i = 0; i < 10; i++)
				{
					string id;
					using (var tx = new TransactionScope())
					using (var session = docStore.OpenSession())
					{

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

						var entity = new User { Name = "Ayende" };
						session.Store(entity);
						session.SaveChanges();
						id = entity.Id;
						tx.Complete();
					}

					using (var session = docStore.OpenSession())
					{
						session.Advanced.AllowNonAuthoritativeInformation = false;
						var user = session.Advanced.Lazily.Load<User>(id);
						Assert.NotNull(user.Value);
					}
				}

			}
		}
Esempio n. 11
0
		public async Task CanUseDeferred()
		{
			string userId;
			using (var session = documentStore.OpenAsyncSession())
			{
				var entity = new User();
				await session.StoreAsync(entity);
				await session.SaveChangesAsync();
				userId = entity.Id;
			}

			using(var session = documentStore.OpenAsyncSession())
			{
				Assert.NotNull(await session.LoadAsync<User>(userId));
			}

			using (var session = documentStore.OpenAsyncSession())
			{
				session.Advanced.Defer(new DeleteCommandData
				{
					Key = userId
				});

				await session.SaveChangesAsync();
			}

			using (var session = documentStore.OpenAsyncSession())
			{
				Assert.Null(await session.LoadAsync<User>(userId));
			}
		}
Esempio n. 12
0
		private static void PrintMissedDocuments(User[] users)
		{
			var missed = new List<int>();
			for (int i = 0; i < 15000; i++)
			{
				if (users.Any(user => user.Id == i + 1) == false)
				{
					missed.Add(i + 1);
				}
			}
			Console.WriteLine("Missed documents: ");
			Console.WriteLine(string.Join(", ", missed));
		}
 public async Task IsOn()
 {
     using (var store = NewRemoteDocumentStore(databaseName: "TEST-ASYNC"))
     {
         using (var session = store.OpenAsyncSession())
         {
             var user = new User
             {
                 Name = "john"
             };
             await session.StoreAsync(user);
             await session.SaveChangesAsync();
         }
     }
 }
Esempio n. 14
0
		public void WorkWithoutTransaction()
		{
			using (var store = NewDocumentStore())
			{
				using (var session = store.OpenSession())
				{
					var user = new User { Id = "users/[email protected]" };
					session.Store(user);
					session.SaveChanges();
				}

				using (var session = store.OpenSession())
				{
					var user = session.Load<User>("users/[email protected]");
					Assert.NotNull(user);
				}
			}
		}
        public void IsOffSync()
        {
            using (var store = NewRemoteDocumentStore(databaseName: "TEST-ASYNC"))
            {
                // http://stackoverflow.com/questions/13859467/ravendb-client-onlinux-connecting-to-windows-server-using-mono-http
                store.JsonRequestFactory.DisableRequestCompression = true;

                using (var session = store.OpenSession())
                {
                    var user = new User
                    {
                        Name = "john"
                    };
                    session.Store(user);
                    session.SaveChanges();
                }
            }
        }
Esempio n. 16
0
		public void Failed()
		{
			using (var store = NewDocumentStore())
			{
				using (var session = store.OpenSession())
				{
					var entity = new User { Id = "users/1" }; session.Store(entity);
					session.SaveChanges();
				}

				using (var session = store.OpenSession())
				{
					session.Advanced.UseOptimisticConcurrency = true;
					var entity = new User { Id = "users/1" }; 
					session.Store(entity, Guid.NewGuid());
					Assert.Throws<ConcurrencyException>(() => session.SaveChanges());
				}
			}
		}
Esempio n. 17
0
		public void ReadOnlyPreventsDeletes()
		{
			using (var store = NewDocumentStore())
			{
				using (var session = store.OpenSession())
				{
					var entity = new User { Name = "Ayende" };
					session.Store(entity);
					session.Advanced.GetMetadataFor(entity)[Constants.RavenReadOnly] = true;
					session.SaveChanges();
				}

				using (var session = store.OpenSession())
				{
					var user = session.Load<User>("users/1");
					Assert.Throws<InvalidOperationException>(() => session.Delete(user));
				}
			}
		}
Esempio n. 18
0
		public void LastModifiedShouldNotBreakMultiLoad()
		{
			var user1 = new User { Name = "John Doe" };
			var user2 = new User { Name = "Jane Doe" };
			using (var store = NewDocumentStore())
			{
				using (var session = store.OpenSession())
				{
					session.Store(user1);
					session.Store(user2);
					session.SaveChanges();
				}

				using (var session = store.OpenSession())
				{
					var users = session.Load<User>(new[] {user1.Id, user2.Id});
					Assert.Equal(2, users.Count());
				}
			}
		}
        public void GetMetadataForTransient()
        {
            using(var store = NewDocumentStore())
            {
                using(var s = store.OpenSession())
                {
                    var entity = new User{Name = "Ayende"};
                    s.Store(entity);
                    s.Advanced.GetMetadataFor(entity)["admin"] = true;

                    s.SaveChanges();
                }

                using (var s = store.OpenSession())
                {
                    var entity = new User{Id = "users/1"};
                    Assert.True(s.Advanced.GetMetadataFor(entity).Value<bool>("admin"));
                }
            }
        }
Esempio n. 20
0
		public void WorkWithoutTransaction()
		{
			using (var store = new EmbeddableDocumentStore
			{
				RunInMemory = true
			}.Initialize())
			{
				using (IDocumentSession session = store.OpenSession())
				{
					var user = new User { Id = "users/[email protected]" };
					session.Store(user);
					session.SaveChanges();
				}

				using (IDocumentSession session = store.OpenSession())
				{
					var user = session.Load<User>("users/[email protected]");
					Assert.NotNull(user);
				}
			}
		}
Esempio n. 21
0
		public void CanQueryOnNullableProperty()
		{
			using(var store = NewDocumentStore())
			{
				using(var session = store.OpenSession())
				{
					var u1 = new User();
					session.Store(u1);
					var metadata = session.Advanced.GetMetadataFor(u1);
					metadata["Errored"] = true;
					metadata["JobId"] = "12cd80f2-34b0-4dd9-8464-d1cefad07256";

					var u2 = new User();
					session.Store(u2);
					var metadata2 = session.Advanced.GetMetadataFor(u2);
					// doesn't have metadata property
					//metadata2["Errored"] = true;
					metadata2["JobId"] = "12cd80f2-34b0-4dd9-8464-d1cefad07256";

					var u3 = new User();
					session.Store(u3);
					var metadata3 = session.Advanced.GetMetadataFor(u3);
					metadata2["Errored"] = false;
					metadata3["JobId"] = "12cd80f2-34b0-4dd9-8464-d1cefad07256";
					session.SaveChanges();
				}

				using (var session = store.OpenSession())
				{
					var users = session.Advanced.LuceneQuery<User>()
							.WaitForNonStaleResultsAsOfNow()
							.WhereEquals("@metadata.JobId", "12cd80f2-34b0-4dd9-8464-d1cefad07256")
							.AndAlso()
							.WhereEquals("@metadata.Errored", false)
							.ToArray();

					Assert.Equal(1, users.Length);
				}
			}
		}
Esempio n. 22
0
		public void CanWorkWithDateTimeOffset()
		{
			using (var store = NewDocumentStore())
			{
				store.DatabaseCommands.PutIndex("test", new IndexDefinition
				{
					Map = @"from doc in docs select new { Time = doc[""@metadata""].time }"
				});

				using (var session = store.OpenSession())
				{
					var entity = new User();
					session.Store(entity);
					session.Advanced.GetMetadataFor(entity)["time"] = new DateTimeOffset(2012, 11, 08, 11, 20, 0, TimeSpan.FromHours(2));
					session.SaveChanges();
				}

				WaitForIndexing(store);
				WaitForUserToContinueTheTest(store);
				Assert.Empty(store.DocumentDatabase.Statistics.Errors);
			}
		}
Esempio n. 23
0
		public void QueryableCountIsAccurate()
		{
			using(var store = NewDocumentStore())
			{
				store.DatabaseCommands.PutIndex("Users",
				                                new IndexDefinition
				                                {
				                                	Map = "from user in docs.Users select new { user.Name }"
				                                });

				using(var s = store.OpenSession())
				{
					for (int i = 0; i < 5; i++)
					{
						var clone = new User{Name = "Ayende #"+i};
						s.Store(clone);
					}
					s.SaveChanges();
				}

				WaitForUserToContinueTheTest(store);

				// wait for index
				using (var s = store.OpenSession())
				{
					var count = s.Query<User>("Users")
						.Customize(x=>x.WaitForNonStaleResults())
						.Count();
					Assert.Equal(5, count);
				}

				using (var s = store.OpenSession())
				{
					var queryable = s.Query<User>("Users");
					Assert.Equal(queryable.ToArray().Length, queryable.Count());
				}
			}
		}
Esempio n. 24
0
		public void WorkWithTransaction()
		{
            using (var store = NewDocumentStore(requestedStorage: "esent"))
			{
                EnsureDtcIsSupported(store);

				using (var scope = new TransactionScope())
				using (var session = store.OpenSession())
				{
					var user = new User { Id = "users/[email protected]" };
					session.Store(user);
					session.SaveChanges();
					scope.Complete();
				}

				using (var session = store.OpenSession())
				{
					session.Advanced.AllowNonAuthoritativeInformation = false;
					var user = session.Load<User>("users/[email protected]");
					Assert.NotNull(user);
				}
			}
		}
Esempio n. 25
0
		public void Successful()
		{
			Guid guid;

			using(var store = NewDocumentStore())
			{
				using(var session = store.OpenSession())
				{
					var entity = new User{Id = "users/1"};
					session.Store(entity);
					session.SaveChanges();

					guid = session.Advanced.GetEtagFor(entity).Value;
				}

				using (var session = store.OpenSession())
				{
					session.Advanced.UseOptimisticConcurrency = true; 
					var entity = new User { Id = "users/1" };
					session.Store(entity, guid);
					session.SaveChanges();
				}
			}
		}
Esempio n. 26
0
		public void WorkWithTransaction()
		{
			using (var store = new EmbeddableDocumentStore
			{
				RunInMemory = true
			}.Initialize())
			{
				using (var scope = new TransactionScope())
				using (IDocumentSession session = store.OpenSession())
				{
					var user = new User { Id = "users/[email protected]" };
					session.Store(user);
					session.SaveChanges();
					scope.Complete();
				}

				using (IDocumentSession session = store.OpenSession())
				{
					session.Advanced.AllowNonAuthoritativeInformation = false;
					var user = session.Load<User>("users/[email protected]");
					Assert.NotNull(user);
				}
			}
		}
Esempio n. 27
0
		public void CanGetId()
		{
			using (var store = NewDocumentStore())
			{
				using (var s = store.OpenSession())
				{
					for (int i = 0; i < 5; i++)
					{
						var clone = new User { Name = "Ayende #" + i };
						s.Store(clone);
					}
					s.SaveChanges();
				}

				using (var s = store.OpenSession())
				{
					for (int i = 0; i < 5; i++)
					{
						var clone = s.Load<User>("users/" + (i + 1));
						Assert.Equal("users/" + (i + 1), s.Advanced.GetDocumentId(clone));
					}
				}
			}
		}
Esempio n. 28
0
        public void CanQueryTenantDatabase()
        {
            using (GetNewServer(8080))
            using (var store = new DocumentStore
            {
                Url = "http://localhost:8080"
            }.Initialize())
            {
                store.DatabaseCommands.EnsureDatabaseExists("Northwind");

                using (var s = store.OpenSession("Northwind"))
                {
                    var entity = new User
                    {
                        Name = "Hello",
                    };
                    s.Store(entity);
                    s.SaveChanges();
                }

                using (var s = store.OpenSession("Northwind"))
                {
                    Assert.NotEmpty(s.Query<User>().Where(x => x.Name == "Hello"));
                }
            }
        }
Esempio n. 29
0
        public void CanUseMultipleDatabases()
        {
            using(GetNewServer(8080))
            using(var store = new DocumentStore
            {
                Url = "http://localhost:8080"
            }.Initialize())
            {
                using(var s = store.OpenSession())
                {
                    s.Store(new DatabaseDocument
                    {
                        Id = "Raven/Databases/Northwind",
                        Settings =
                            {
                                {"Raven/RunInMemory", "true"},
                                {"Raven/DataDir", "Northwind"}
                            }
                    });

                    s.SaveChanges();
                }

                string userId;

                using(var s = store.OpenSession("Northwind"))
                {
                    var entity = new User
                    {
                        Name = "First Mutlti Tenant Bank",
                    };
                    s.Store(entity);
                    userId = entity.Id;
                    s.SaveChanges();
                }

                using (var s = store.OpenSession())
                {
                    Assert.Null(s.Load<User>(userId));
                }

                using (var s = store.OpenSession("Northwind"))
                {
                    Assert.NotNull(s.Load<User>(userId));
                }
            }
        }
Esempio n. 30
0
		public void Can_query_metadata()
		{
			using (var store = NewDocumentStore())
			{
				var user1 = new User {Name = "Joe Schmoe"};
				const string propertyName1 = "Test-Property-1";
				const string propertyValue1 = "Test-Value-1";
				using (var session = store.OpenSession())
				{
					session.Store(user1);
					var metadata1 = session.Advanced.GetMetadataFor(user1);
					metadata1[propertyName1] = propertyValue1;
					session.Store(new User {Name = "Ralph Schmoe"});
					session.SaveChanges();
				}

				using (var session = store.OpenSession())
				{
					var result = session.Advanced.LuceneQuery<User>()
						.WhereEquals("@metadata." + propertyName1, propertyValue1)
						.ToList();

					Assert.NotNull(result);
					Assert.Equal(1, result.Count);
					var metadata = session.Advanced.GetMetadataFor(result[0]);
					Assert.Equal(propertyValue1, metadata[propertyName1]);
				}
			}
		}