Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adding test

  • Loading branch information...
commit 74048a5aa07ae61dda18c0e0804dd84b1dca2531 1 parent f9eff60
@ayende ayende authored
View
10 Raven.Tests/MailingList/RobStats/Entity.cs
@@ -0,0 +1,10 @@
+using System;
+
+namespace Raven.Tests.MailingList.RobStats {
+ public class Entity {
+ public string Id { get; set; }
+ public string DisplayName { get; set; }
+ public string Visibility { get; set; }
+ public DateTimeOffset UpdatedAt { get; set; }
+ }
+}
View
6 Raven.Tests/MailingList/RobStats/Opinion.cs
@@ -0,0 +1,6 @@
+namespace Raven.Tests.MailingList.RobStats {
+ public class Opinion {
+ public string EntityId { get; set; }
+ public bool IsFavorite { get; set; }
+ }
+}
View
76 Raven.Tests/MailingList/RobStats/StatisticsBug.cs
@@ -0,0 +1,76 @@
+// //-----------------------------------------------------------------------
+// // <copyright company="Hibernating Rhinos LTD">
+// // Copyright (c) Hibernating Rhinos LTD. All rights reserved.
+// // </copyright>
+// //-----------------------------------------------------------------------
+using System;
+using System.Diagnostics;
+using System.Linq;
+using System.Reflection;
+using Raven.Client.Document;
+using Raven.Client.Indexes;
+using Raven.Client.Linq;
+using Xunit;
+
+namespace Raven.Tests.MailingList.RobStats
+{
+ public class StatisticsBug : RavenTest
+ {
+ [Fact]
+ public void Should_get_stats_whe_using_lazy()
+ {
+ using (GetNewServer())
+ using (var store = new DocumentStore
+ {
+ Url = "http://localhost:8080"
+ }.Initialize())
+ {
+ new TheIndex().Execute(store);
+ using (var session = store.OpenSession())
+ {
+ for (var i = 0; i < 15; i++)
+ {
+ var entity = new Entity
+ {
+ DisplayName = "Entity " + i,
+ UpdatedAt = DateTimeOffset.Now,
+ Visibility = "Visible"
+ };
+
+ session.Store(entity);
+
+ var opinion = new Opinion
+ {
+ EntityId = entity.Id,
+ IsFavorite = i%2 == 0
+ };
+
+ session.Store(opinion);
+ }
+
+ session.SaveChanges();
+ }
+
+ using (var session = store.OpenSession())
+ {
+ RavenQueryStatistics stats;
+ var query = session.Query<Summary, TheIndex>()
+ .Customize(x => x.WaitForNonStaleResults())
+ .Statistics(out stats)
+ .Where(x => x.Visibility == "Visible")
+ .OrderByDescending(x => x.UpdatedAt);
+
+ var pagedQuery = query
+ .Skip(0)
+ .Take(10)
+ .Lazily();
+
+
+ var items = pagedQuery.Value.ToArray();
+ Assert.Equal(15, stats.TotalResults);
+ Assert.Equal(10, items.Length);
+ }
+ }
+ }
+ }
+}
View
11 Raven.Tests/MailingList/RobStats/Summary.cs
@@ -0,0 +1,11 @@
+using System;
+
+namespace Raven.Tests.MailingList.RobStats {
+ public class Summary {
+ public string EntityId { get; set; }
+ public string DisplayName { get; set; }
+ public string Visibility { get; set; }
+ public DateTimeOffset UpdatedAt { get; set; }
+ public int NumberOfFavorites { get; set; }
+ }
+}
View
40 Raven.Tests/MailingList/RobStats/TheIndex.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Linq;
+using Raven.Client.Indexes;
+
+namespace Raven.Tests.MailingList.RobStats {
+ class TheIndex : AbstractMultiMapIndexCreationTask<Summary> {
+ public TheIndex() {
+ AddMap<Opinion>(
+ opinions => from opinion in opinions
+ select new {
+ opinion.EntityId,
+ DisplayName = (string)null,
+ Visibility = (string)null,
+ UpdatedAt = DateTimeOffset.MinValue,
+ NumberOfFavorites = opinion.IsFavorite ? 1 : 0,
+ });
+
+ AddMap<Entity>(
+ entities => from entity in entities
+ select new {
+ EntityId = entity.Id,
+ entity.DisplayName,
+ entity.Visibility,
+ entity.UpdatedAt,
+ NumberOfFavorites = 0,
+ });
+
+ Reduce = results => from result in results
+ group result by result.EntityId
+ into g
+ select new {
+ EntityId = g.Key,
+ DisplayName = g.Select(x => x.DisplayName).Where(x => x != null).FirstOrDefault(),
+ Visibility = g.Select(x => x.Visibility).Where(x => x != null).FirstOrDefault(),
+ UpdatedAt = g.Max(x => (DateTimeOffset)x.UpdatedAt),
+ NumberOfFavorites = g.Sum(x => x.NumberOfFavorites),
+ };
+ }
+ }
+}
View
5 Raven.Tests/Raven.Tests.csproj
@@ -562,6 +562,11 @@
<Compile Include="MailingList\LazyStats.cs" />
<Compile Include="MailingList\NicolasGarfinkiel.cs" />
<Compile Include="MailingList\Rob.cs" />
+ <Compile Include="MailingList\RobStats\Entity.cs" />
+ <Compile Include="MailingList\RobStats\Opinion.cs" />
+ <Compile Include="MailingList\RobStats\StatisticsBug.cs" />
+ <Compile Include="MailingList\RobStats\Summary.cs" />
+ <Compile Include="MailingList\RobStats\TheIndex.cs" />
<Compile Include="MailingList\spokeypokey.cs" />
<Compile Include="MailingList\spokeypokey2.cs" />
<Compile Include="MailingList\Stacey.cs" />
Please sign in to comment.
Something went wrong with that request. Please try again.