Пример #1
0
        public void Will_automatically_set_metadata()
        {
            var company = new Company {Name = "Company Name"};
            using (var session = documentStore.OpenSession())
            {
                session.Store(company);
                session.SaveChanges();
            }

            using (var session = documentStore.OpenSession())
            {
                var company2 = session.Load<Company>(company.Id);
                var metadata = session.GetMetadataFor(company2);
                Assert.Equal("Current", metadata.Value<string>("Raven-Document-Revision-Status"));
                Assert.Equal(1, metadata.Value<int>("Raven-Document-Revision"));
            }
        }
Пример #2
0
        public void Will_delete_old_revisions()
        {
            var company = new Company {Name = "Company #1"};
            using (var session = documentStore.OpenSession())
            {
                session.Store(company);
                session.SaveChanges();
                for (int i = 0; i < 10; i++)
                {
                    company.Name = "Company #" + i + 2;
                    session.SaveChanges();
                }
            }


            using (var session = documentStore.OpenSession())
            {
                for (int i = 1; i < 6; i++)
                {
                    Assert.Null(session.Load<Company>(company.Id + "/revisions/" + i));
                }

                for (int i = 6; i < 11; i++)
                {
                    Assert.NotNull(session.Load<Company>(company.Id + "/revisions/" + i));
                }
            }
        }
Пример #3
0
        public void Will_automatically_craete_duplicate_on_next_insert()
        {
            var company = new Company {Name = "Company Name"};
            using (var session = documentStore.OpenSession())
            {
                session.Store(company);
                session.SaveChanges();
            }
            using (var session = documentStore.OpenSession())
            {
                var company3 = session.Load<Company>(company.Id);
                company3.Name = "Hibernating Rhinos";
                session.SaveChanges();
            }
            using (var session = documentStore.OpenSession())
            {
                var company2 = session.Load<Company>(company.Id + "/revisions/1");
                var metadata = session.GetMetadataFor(company2);
                Assert.Equal("Company Name", company2.Name);
                Assert.Equal("Historical", metadata.Value<string>("Raven-Document-Revision-Status"));
                Assert.Equal(1, metadata.Value<int>("Raven-Document-Revision"));

                company2 = session.Load<Company>(company.Id + "/revisions/2");
                metadata = session.GetMetadataFor(company2);
                Assert.Equal("Hibernating Rhinos", company2.Name);
                Assert.Equal("Historical", metadata.Value<string>("Raven-Document-Revision-Status"));
                Assert.Equal(2, metadata.Value<int>("Raven-Document-Revision"));
            }
        }