当前位置: 首页>>代码示例>>C#>>正文


C# DocumentStore.InitializeTemporalVersioning方法代码示例

本文整理汇总了C#中Raven.Client.Document.DocumentStore.InitializeTemporalVersioning方法的典型用法代码示例。如果您正苦于以下问题:C# DocumentStore.InitializeTemporalVersioning方法的具体用法?C# DocumentStore.InitializeTemporalVersioning怎么用?C# DocumentStore.InitializeTemporalVersioning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Raven.Client.Document.DocumentStore的用法示例。


在下文中一共展示了DocumentStore.InitializeTemporalVersioning方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TemporalVersioning_OneEdit_OverHttp

        public void TemporalVersioning_OneEdit_OverHttp()
        {
            using (var embeddedDocumentStore = this.GetTemporalDocumentStore())
            {
                embeddedDocumentStore.Configuration.AnonymousUserAccessMode = AnonymousUserAccessMode.All;
                using (var server = new HttpServer(embeddedDocumentStore.Configuration, embeddedDocumentStore.DocumentDatabase))
                {
                    server.StartListening();

                    var documentStore = new DocumentStore { Url = "http://localhost:8080" };
                    documentStore.Initialize();
                    documentStore.InitializeTemporalVersioning();

                    const string id = "employees/1";
                    var effectiveDate1 = new DateTimeOffset(new DateTime(2012, 1, 1));
                    using (var session = documentStore.OpenSession())
                    {
                        var employee = new Employee { Id = id, Name = "John", PayRate = 10 };
                        session.Effective(effectiveDate1).Store(employee);

                        session.SaveChanges();
                    }

                    // Make some changes
                    var effectiveDate2 = new DateTimeOffset(new DateTime(2012, 2, 1));
                    using (var session = documentStore.OpenSession())
                    {
                        var employee = session.Effective(effectiveDate2).Load<Employee>(id);
                        employee.PayRate = 20;

                        session.SaveChanges();
                    }

                    // Check the results
                    using (var session = documentStore.OpenSession())
                    {
                        var current = session.Load<Employee>(id);
                        Assert.Equal(id, current.Id);
                        Assert.Equal(20, current.PayRate);

                        var currentTemporal = session.Advanced.GetTemporalMetadataFor(current);
                        Assert.Equal(TemporalStatus.Current, currentTemporal.Status);
                        Assert.Equal(2, currentTemporal.RevisionNumber);

                        var revisions = session.Advanced.GetTemporalRevisionsFor<Employee>(id, 0, 10);
                        Assert.Equal(2, revisions.Length);

                        Assert.Equal(id, revisions[0].Id);
                        Assert.Equal(id, revisions[1].Id);
                        Assert.Equal(10, revisions[0].PayRate);
                        Assert.Equal(20, revisions[1].PayRate);

                        var version1Temporal = session.Advanced.GetTemporalMetadataFor(revisions[0]);
                        Assert.Equal(TemporalStatus.Revision, version1Temporal.Status);
                        Assert.False(version1Temporal.Deleted);
                        Assert.Equal(effectiveDate1, version1Temporal.EffectiveStart);
                        Assert.Equal(effectiveDate2, version1Temporal.EffectiveUntil);
                        Assert.Equal(1, version1Temporal.RevisionNumber);

                        var version2Temporal = session.Advanced.GetTemporalMetadataFor(revisions[1]);
                        Assert.Equal(TemporalStatus.Revision, version2Temporal.Status);
                        Assert.False(version2Temporal.Deleted);
                        Assert.Equal(effectiveDate2, version2Temporal.EffectiveStart);
                        Assert.Equal(DateTimeOffset.MaxValue, version2Temporal.EffectiveUntil);
                        Assert.Equal(2, version2Temporal.RevisionNumber);
                    }
                }
            }
        }
开发者ID:jggutierrez,项目名称:RavenDB-TemporalVersioning,代码行数:69,代码来源:HttpTests.cs


注:本文中的Raven.Client.Document.DocumentStore.InitializeTemporalVersioning方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。