/
Statistics.cs
75 lines (63 loc) · 2.54 KB
/
Statistics.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.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Raven.Abstractions.Indexing;
using Raven.Client.Document;
using Raven.Client.Extensions;
using Raven.Tests.Document;
namespace Raven.Tests.Silverlight
{
public class Statistics : RavenTestBase
{
[Asynchronous]
public IEnumerable<Task> CanRetrieveStatisticsForTheDefaultDatabase()
{
using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
{
var getStats = documentStore.AsyncDatabaseCommands
.GetStatisticsAsync();
yield return getStats;
Assert.IsNotNull(getStats.Result);
}
}
[Asynchronous]
public IEnumerable<Task> CanRetrieveStatisticsForADatabase()
{
var dbname = GenerateNewDatabaseName();
using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
{
yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);
yield return documentStore.AsyncDatabaseCommands.ForDatabase(dbname).PutIndexAsync("test", new IndexDefinition
{
Map = "from doc in docs select new { doc.Name}"
}, true);
var getStats = documentStore.AsyncDatabaseCommands.ForDatabase(dbname).GetStatisticsAsync();
yield return getStats;
var stats = getStats.Result;
Assert.AreEqual(0, stats.CountOfDocuments);
Assert.IsTrue(stats.CountOfIndexes > 0);
}
}
[Asynchronous]
public IEnumerable<Task> StatisticsShouldNotBeCached()
{
var dbname = GenerateNewDatabaseName();
using (var documentStore = new DocumentStore {Url = Url + Port}.Initialize())
{
yield return documentStore.AsyncDatabaseCommands.EnsureDatabaseExistsAsync(dbname);
var getStats = documentStore.AsyncDatabaseCommands.ForDatabase(dbname).GetStatisticsAsync();
yield return getStats;
Assert.AreEqual(0, getStats.Result.CountOfDocuments);
using (var session = documentStore.OpenAsyncSession(dbname))
{
session.Store(new Company {Name = "Change the Stats, Inc."});
yield return session.SaveChangesAsync();
}
var verifyStats = documentStore.AsyncDatabaseCommands.ForDatabase(dbname).GetStatisticsAsync();
yield return verifyStats;
Assert.AreEqual(1, verifyStats.Result.CountOfDocuments);
}
}
}
}