-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathSerializeTests.cs
116 lines (107 loc) · 2.93 KB
/
SerializeTests.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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Threading;
using NUnit.Framework;
using Nest.Tests.MockData.Domain;
using Elasticsearch.Net;
using FluentAssertions;
namespace Nest.Tests.Unit.Internals.Serialize
{
[TestFixture]
public class SerializeTests : BaseJsonTests
{
public class SimpleClass
{
public int Id { get; set; }
public string Name { get; set; }
}
public class ClassWithCollections
{
public int Id { get; set; }
private ICollection<SimpleClass> _productVariants;
public virtual ICollection<SimpleClass> ProductVariants
{
get { return _productVariants ?? (_productVariants = new List<SimpleClass>()); }
set { _productVariants = value; }
}
}
// <summary>
/// https://github.com/Mpdreamz/NEST/issues/204
///
/// Reported problems with ICollections
/// </summary>
[Test]
public void ClassWithCollectionSerializes()
{
var col = new ClassWithCollections
{
Id = 2,
ProductVariants = new List<SimpleClass>
{
new SimpleClass {Id = 1, Name = "class 1"},
new SimpleClass {Id = 1, Name = "class 1"},
}
};
var json = this._client.Serializer.Serialize(col).Utf8String();
this.JsonEquals(json, MethodInfo.GetCurrentMethod());
}
[Test]
public void DateTimeIgnoresCurrentCulture()
{
var t = new Thread(() =>
{
var cultureInfo = new CultureInfo("IT-it");
cultureInfo.DateTimeFormat.DateSeparator = ".";
cultureInfo.DateTimeFormat.TimeSeparator = ".";
Thread.CurrentThread.CurrentCulture = cultureInfo;
Thread.CurrentThread.CurrentUICulture = cultureInfo;
var serialized = _client.Serializer.Serialize(new DateTime(2015, 01, 30, 08, 52, 32, 443)).Utf8String();
serialized.Should().EndWith(":32.443\"");
});
t.Start();
t.Join(TimeSpan.FromSeconds(5));
}
[Test]
public void SerializingSearchIsFastEnough()
{
//seraialize once to build cache
var randomDeserialize = this._client.Serializer.Serialize(new SearchDescriptor<ElasticsearchProject>()
.From(0)
.Size(10)
.Fields(f => f.Id, f => f.Country)
.SortAscending(f => f.LOC)
.SortDescending(f => f.Country)
.Query(q => q
.MatchAll()
)
);
var sw = Stopwatch.StartNew();
var data = this._client.Serializer.Serialize(new SearchDescriptor<ElasticsearchProject>()
.From(0)
.Size(10)
.Fields(f => f.Id, f => f.Country)
.SortAscending(f => f.LOC)
.SortDescending(f => f.Country)
.Query(q => q
.MatchAll()
)
);
Assert.NotNull(data);
data = this._client.Serializer.Serialize(new SearchDescriptor<ElasticsearchProject>()
.From(0)
.Size(10)
.Fields(f => f.Id, f => f.Country)
.SortAscending(f => f.LOC)
.SortDescending(f => f.Country)
.Query(q => q
.MatchAll()
)
);
Assert.LessOrEqual(sw.ElapsedMilliseconds, 10);
Assert.NotNull(data);
}
}
}