コード例 #1
0
        public void multiple_documents()
        {
            var user1 = new User {FirstName = "Jeremy", LastName = "Miller"};
            var issue1 = new Issue {Title = "TV won't turn on"}; // unfortunately true as I write this...
            var company1 = new Company{Name = "Widgets, inc."};
            var company2 = new Company{Name = "BigCo"};
            var company3 = new Company{Name = "SmallCo"};

            theSession.Store(user1);
            theSession.Store(issue1);
            theSession.Store(company1);
            theSession.Store(company2);
            theSession.Store(company3);
            theSession.SaveChanges();

            using (var session = theContainer.GetInstance<IDocumentSession>())
            {
                var user = session.Load<User>(user1.Id);
                user.FirstName = "Max";

                session.Store(user);

                session.Delete(company2);

                session.SaveChanges();
            }

            using (var session = theContainer.GetInstance<IDocumentSession>())
            {
                session.Load<User>(user1.Id).FirstName.ShouldBe("Max");
                session.Load<Company>(company1.Id).Name.ShouldBe("Widgets, inc.");
                session.Load<Company>(company2.Id).ShouldBeNull();
                session.Load<Company>(company3.Id).Name.ShouldBe("SmallCo");
            }
        }
コード例 #2
0
ファイル: UnitOfWorkTests.cs プロジェクト: dvilchez/marten
        public void update_mixed_document_types()
        {
            var user1 = new User();
            var user2 = new User();
            var issue1 = new Issue();
            var issue2 = new Issue();
            var company1 = new Company();
            var company2 = new Company();

            var uow = theContainer.GetInstance<UnitOfWork>();
            uow.Store(user1, user2);
            uow.Store(issue1, issue2);
            uow.Store(company1, company2);

            var batch = theContainer.GetInstance<UpdateBatch>();

            uow.ApplyChanges(batch);

            batch.Connection.Dispose();

            using (var session2 = theContainer.GetInstance<IDocumentStore>().OpenSession())
            {
                session2.Query<User>().ToArray().Select(x => x.Id).ShouldHaveTheSameElementsAs(user1.Id, user2.Id);
                session2.Query<Issue>().ToArray().Select(x => x.Id).ShouldHaveTheSameElementsAs(issue1.Id, issue2.Id);
                session2.Query<Company>().ToArray().Select(x => x.Id).ShouldHaveTheSameElementsAs(company1.Id, company2.Id);
            }


        }