Esempio n. 1
0
        public void CanAutomaticallyAssignAnId()
        {
            var user = new User() { Name = "Harry" };
            var dbSession = _database.OpenSession();
            dbSession.Store(user);

            var loadedUser = dbSession.Get<User>(user.PieId());
            Assert.AreEqual("Harry", loadedUser.Name);
        }
Esempio n. 2
0
        public void AnObjectSavedTwiceIsFoundOnce()
        {
            var user = new User() { Name = "Harry" };
            dbSession.Store(user);
            dbSession.Store(user);
            dbSession.Commit();

            var user2 = indexer.Query<User>(dbSession, u => u.Name == "Harry").Single();
        }
Esempio n. 3
0
        public void CanSearch()
        {
            var user = new User() { Name = "Harry" };
            dbSession.Store(user);
            dbSession.Commit();

            var user2 = this.indexer.Query<User>(dbSession, u => u.Name == "Harry").Single();

            Assert.AreEqual("Harry", user2.Name);
            Assert.AreEqual(user.PieId(), user2.PieId(), "If these are different, user2 has not been loaded from the database (it has just been rebuilt by the lucene search)");
        }
Esempio n. 4
0
        public void CanDelete()
        {
            var user = new User() { Name = "Harry" };

            var dbSession = _database.OpenSession(); dbSession.Store(user);
            Assert.Null(_database.OpenSession().Get<User>(user.PieId()));
            dbSession.Commit();
            Assert.NotNull(_database.OpenSession().Get<User>(user.PieId()));

            dbSession.Remove(user);
            dbSession.Commit();

            Assert.Null(_database.OpenSession().Get<User>(user.PieId()));
        }
Esempio n. 5
0
        public void CantFindDeletedData()
        {
            var user = new User() { Name = "Harry" };
            dbSession.Store(user);
            dbSession.Commit();

            Assert.True(indexer.Query<User>(dbSession, u => u.Name == "Harry").Any());

            dbSession.Remove(user);
            dbSession.Commit();

            var enumerable = indexer.Query<User>(dbSession, u => u.Name == "Harry").ToArray();
            Assert.False(enumerable.Any());
        }
Esempio n. 6
0
        public void CanSearchOnUpdatedData()
        {
            var user = new User() { Name = "Harry" };
            dbSession.Store(user);
            dbSession.Commit();

            var user2 = indexer.Query<User>(dbSession, u => u.Name == "Harry").Single();
            user2.Name = "Tom";
            dbSession.Store(user2);
            dbSession.Commit();

            var enumerable = indexer.Query<User>(dbSession, u => u.Name == "Harry").ToArray();
            Assert.Null(enumerable.SingleOrDefault());

            var foundUsingNewName = indexer.Query<User>(dbSession, u => u.Name == "Tom").Single();
            Assert.AreEqual("Tom", foundUsingNewName.Name);
        }
Esempio n. 7
0
        public void PreservesReferences()
        {
            var user = new User() { Name = "Harry" };
            var task = new Task() { Creator = user, Assignee = user };
            var dbSession = _database.OpenSession();
            dbSession.Store(task, "asdfg");

            var loadedTask = dbSession.Get<Task>("asdfg");

            Assert.True(loadedTask.Assignee == loadedTask.Creator);
        }