forked from ravendb/ravendb
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDateTimeOffsetIssues.cs
146 lines (124 loc) · 5.67 KB
/
DateTimeOffsetIssues.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using Raven.Json.Linq;
using Raven.Tests.Common;
using Xunit;
using Xunit.Extensions;
namespace Raven.Tests.MailingList
{
public class DateTimeOffsetIssues : RavenTest
{
public class Book
{
public string Id { get; set; }
public string Author { get; set; }
}
[Theory]
[InlineData("2011-11-05T13:09:17.5402774")]
[InlineData("2011-11-05T13:09:17.540277")]
public void Adding_DateTimeOffset_To_metadata_should_fetch_it_as_DateTimeOffset(string expectedDateTimeString)
{
using (var _documentStore = NewRemoteDocumentStore(fiddler: true, requestedStorage: "esent", runInMemory: false))
{
// Arrange
string bookId;
var expectedDateTime = DateTimeOffset.Parse(expectedDateTimeString);
using (var session = _documentStore.OpenSession())
{
var entity = new Book { Author = "dane" };
session.Store(entity);
session.SaveChanges();
bookId = entity.Id;
}
// Act
// Add metadata to the entity
using (var session = _documentStore.OpenSession())
{
var book = session.Load<Book>(bookId);
var metadata = session.Advanced.GetMetadataFor(book);
metadata.Add("DateTime-ToCheck", RavenJToken.FromObject(expectedDateTime));
session.SaveChanges();
}
// Try get metadata
using (var session = _documentStore.OpenSession())
{
var entity = session.Load<Book>(bookId);
var metadata = session.Advanced.GetMetadataFor(entity);
var result = metadata.Value<DateTimeOffset>("DateTime-ToCheck"); // No exception is thrown here
Assert.IsType<DateTimeOffset>(result);
Assert.Equal(expectedDateTime, result);
}
// Change the entity
using (var session = _documentStore.OpenSession())
{
var book = session.Load<Book>(bookId);
book.Author = "Jane Doe";
session.SaveChanges();
}
// Assert
// Try to get the metadata back as DateTime
using (var session = _documentStore.OpenSession())
{
var entity = session.Load<Book>(bookId);
var metadata = session.Advanced.GetMetadataFor(entity);
var result = new DateTimeOffset();
Assert.DoesNotThrow(() => result = metadata.Value<DateTimeOffset>("DateTime-ToCheck")); // An exception should not be thrown here, after changing the entity
Assert.Equal(expectedDateTime, result);
}
}
}
[Theory]
[InlineData("2011-11-05T13:09:17.5402774")]
[InlineData("2011-11-05T13:09:17.540277")]
public void Adding_DateTime_to_metadata_should_fetch_it_as_DateTime(string expectedDateTimeString)
{
using(var _documentStore = NewRemoteDocumentStore(fiddler:true,requestedStorage:"esent",runInMemory:false))
{
// Arrange
string bookId;
var expectedDateTime = DateTime.Parse(expectedDateTimeString);
using (var session = _documentStore.OpenSession())
{
var entity = new Book { Author = "dane" };
session.Store(entity);
session.SaveChanges();
bookId = entity.Id;
}
// Act
// Add metadata to the entity
using (var session = _documentStore.OpenSession())
{
var book = session.Load<Book>(bookId);
var metadata = session.Advanced.GetMetadataFor(book);
metadata.Add("DateTime-ToCheck", RavenJToken.FromObject(expectedDateTime));
session.SaveChanges();
}
// Try get metadata
using (var session = _documentStore.OpenSession())
{
var entity = session.Load<Book>(bookId);
var metadata = session.Advanced.GetMetadataFor(entity);
var result = metadata.Value<DateTime>("DateTime-ToCheck"); // No exception is thrown here
Assert.IsType<DateTime>(result);
Assert.Equal(expectedDateTime,result);
}
// Change the entity
using (var session = _documentStore.OpenSession())
{
var book = session.Load<Book>(bookId);
book.Author = "Jane Doe";
session.SaveChanges();
}
// Assert
// Try to get the metadata back as DateTime
using (var session = _documentStore.OpenSession())
{
var entity = session.Load<Book>(bookId);
var metadata = session.Advanced.GetMetadataFor(entity);
var result = new DateTime();
Assert.DoesNotThrow(() => result = metadata.Value<DateTime>("DateTime-ToCheck")); // An exception should not be thrown here, after changing the entity
Assert.Equal(expectedDateTime, result);
}
}
}
}
}