forked from ravendb/ravendb
/
RavenDB845.cs
75 lines (67 loc) · 1.64 KB
/
RavenDB845.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
using System;
using Raven.Abstractions;
using Raven.Client;
using Raven.Tests.Helpers;
using Xunit;
namespace Raven.Tests.Issues
{
public class LastModifiedTests : RavenTestBase
{
public override void Dispose()
{
SystemTime.UtcDateTime = null;
base.Dispose();
}
public class Foo
{
public string Id { get; set; }
public string Name { get; set; }
}
[Fact]
public void LastModifiedDate_IsUpdated_Local()
{
using (var documentStore = NewDocumentStore(requestedStorage: "esent"))
{
DoTest(documentStore);
}
}
[Fact]
public void LastModifiedDate_IsUpdated_Remote()
{
using (var documentStore = NewRemoteDocumentStore())
{
DoTest(documentStore);
}
}
private void DoTest(IDocumentStore documentStore)
{
using (var session = documentStore.OpenSession())
{
session.Store(new Foo { Id = "foos/1", Name = "A" });
session.SaveChanges();
}
DateTime firstDate;
using (var session = documentStore.OpenSession())
{
var foo = session.Load<Foo>("foos/1");
var metadata = session.Advanced.GetMetadataFor(foo);
firstDate = metadata.Value<DateTime>("Last-Modified");
}
SystemTime.UtcDateTime = () => DateTime.UtcNow.AddDays(1);
using (var session = documentStore.OpenSession())
{
var foo = session.Load<Foo>("foos/1");
foo.Name = "B";
session.SaveChanges();
}
DateTime secondDate;
using (var session = documentStore.OpenSession())
{
var foo = session.Load<Foo>("foos/1");
var metadata = session.Advanced.GetMetadataFor(foo);
secondDate = metadata.Value<DateTime>("Last-Modified");
}
Assert.NotEqual(secondDate, firstDate);
}
}
}