Ejemplo 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);
        }
Ejemplo 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();
        }
Ejemplo 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)");
        }
Ejemplo 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()));
        }
Ejemplo 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());
        }
Ejemplo 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);
        }
Ejemplo 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);
        }