コード例 #1
0
        public void CanDeleteExistingDocumentByObject()
        {
            var person = new Person
            {
                FirstName = "Michael",
                LastName = "Carter",
                Age = 43,
                Home = new Address
                {
                    City = "Chesapeake",
                    State = "VA"
                }
            };

            using (var session = _store.OpenSession())
            {
                session.Store(person);
                session.SaveChanges();
            }

            using (var session = _store.OpenSession())
            {
                var existing = session.Load<Person>(person.Id);

                session.Delete(existing);
                session.SaveChanges();
            }

            using (var session = _store.OpenSession())
            {
                var deleted = session.Load<Person>(person.Id);
                Assert.IsNull(deleted);
            }
        }
コード例 #2
0
        public void CanLoadExistingDocument()
        {
            var person = new Person
            {
                FirstName = "Michael",
                LastName = "Carter",
                Age = 43,
                Home = new Address
                {
                    City = "Chesapeake",
                    State = "VA"
                }
            };

            using (var session = _store.OpenSession())
            {
                session.Store(person);
                session.SaveChanges();
            }

            using (var session = _store.OpenSession())
            {
                var existing = session.Load<Person>(person.Id);

                Assert.IsTrue(person.Id == existing.Id);
                Assert.IsTrue(person.FirstName == existing.FirstName);
                Assert.IsTrue(person.LastName == existing.LastName);
                Assert.IsTrue(person.Age == existing.Age);
            }
        }
コード例 #3
0
        public void LoadingSameDocumentWillReturnSameObject()
        {
            var person = new Person
            {
                FirstName = "Michael",
                LastName = "Carter",
                Age = 43,
                Home = new Address
                {
                    City = "Chesapeake",
                    State = "VA"
                }
            };

            using (var session = _store.OpenSession())
            {
                session.Store(person);
                session.SaveChanges();
            }

            using (var session = _store.OpenSession())
            {
                var existing = session.Load<Person>(person.Id);
                var existing2 = session.Load<Person>(person.Id);

                Assert.IsTrue(existing == existing2);
            }
        }
コード例 #4
0
        public void ModifyingDocumentAndNotCallingSaveChangesWillNotPersistChanges()
        {
            var person = new Person
            {
                FirstName = "Michael",
                LastName = "Carter",
                Age = 43,
                Home = new Address
                {
                    City = "Chesapeake",
                    State = "VA"
                }
            };

            using (var session = _store.OpenSession())
            {
                session.Store(person);
                session.SaveChanges();
            }

            using (var session = _store.OpenSession())
            {
                var existing = session.Load<Person>(person.Id);

                existing.FirstName = "Mike";
            }

            using (var session = _store.OpenSession())
            {
                var existing = session.Load<Person>(person.Id);

                Assert.IsTrue(existing.FirstName == "Michael");
            }
        }
コード例 #5
0
        public void CanSaveDocument()
        {
            var person = new Person
            {
                FirstName = "Michael",
                LastName = "Carter",
                Age = 43,
                Home = new Address
                {
                    City = "Chesapeake",
                    State = "VA"
                }
            };

            using (var session = _store.OpenSession())
            {
                session.Store(person);
                session.SaveChanges();
            }
        }