/test/SlowTests/Issues/RavenDB_9104.cs

https://github.com/fitzchak/ravendb · C# · 313 lines · 258 code · 55 blank · 0 comment · 6 complexity · d3663e9b8a8cc8208bd06848a4be0e1c MD5 · raw file

  1. using Raven.Client.Documents;
  2. using Raven.Client.Documents.Indexes;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Threading;
  6. using System.Threading.Tasks;
  7. using FastTests;
  8. using Xunit;
  9. namespace SlowTests.Issues
  10. {
  11. public class RavenDB_9104 : RavenTestBase
  12. {
  13. public class BlogPost
  14. {
  15. public string Id { get; set; }
  16. public string Title { get; set; }
  17. public string Username { get; set; }
  18. public string Post { get; set; }
  19. public List<string> BlogComments { get; set; }
  20. }
  21. public class BlogComment
  22. {
  23. public string Id { get; set; }
  24. public string Username { get; set; }
  25. public string Comment { get; set; }
  26. public string BlogCommentRatingId { get; set; }
  27. }
  28. public class BlogCommentRating
  29. {
  30. public string Id { get; set; }
  31. public decimal Rating { get; set; }
  32. }
  33. public class BlogPostAll
  34. : AbstractMultiMapIndexCreationTask<BlogPostAll.Mapping>
  35. {
  36. public class Mapping
  37. {
  38. public string Id { get; set; }
  39. public string Title { get; set; }
  40. public string Username { get; set; }
  41. public IEnumerable<string> Comments { get; set; }
  42. }
  43. public BlogPostAll()
  44. {
  45. AddMap<BlogPost>(results =>
  46. from result in results
  47. let blogComments = LoadDocument<BlogComment>(result.BlogComments)
  48. select new Mapping
  49. {
  50. Id = result.Id,
  51. Username = result.Username,
  52. Title = result.Title,
  53. Comments = blogComments.Select(a => a.Comment)
  54. });
  55. }
  56. }
  57. public class BlogPostWithAverageRatingAll
  58. : AbstractMultiMapIndexCreationTask<BlogPostAll.Mapping>
  59. {
  60. public class Mapping
  61. {
  62. public string Id { get; set; }
  63. public string Title { get; set; }
  64. public string Username { get; set; }
  65. public IEnumerable<string> Comments { get; set; }
  66. public decimal AverageRating { get; set; }
  67. }
  68. public BlogPostWithAverageRatingAll()
  69. {
  70. AddMap<BlogPost>(results =>
  71. from result in results
  72. let blogComments = LoadDocument<BlogComment>(result.BlogComments)
  73. let blogCommentRatings = LoadDocument<BlogCommentRating>(blogComments.Select(a => a.BlogCommentRatingId))
  74. ?? new[] { new BlogCommentRating { Rating = 0}}
  75. select new Mapping
  76. {
  77. Id = result.Id,
  78. Username = result.Username,
  79. Title = result.Title,
  80. Comments = blogComments.Select(a => a.Comment),
  81. AverageRating = blogCommentRatings.Average(a => a.Rating)
  82. });
  83. }
  84. }
  85. [Fact]
  86. public async Task NullListAsync()
  87. {
  88. using (var store = GetDocumentStore())
  89. {
  90. await store.ExecuteIndexAsync(new BlogPostAll());
  91. using (var session = store.OpenAsyncSession())
  92. {
  93. for (var i = 0; i < 5; i++)
  94. {
  95. await session.StoreAsync(new BlogPost
  96. {
  97. Title = "Lorem Ipsum " + i,
  98. Username = "Anonymous",
  99. Post = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. " +
  100. "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. " +
  101. "It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. " +
  102. "It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
  103. }, "BlogPosts/" + i);
  104. }
  105. await session.SaveChangesAsync();
  106. var query = await session.Query<BlogPostAll.Mapping, BlogPostAll>()
  107. .Customize(x=>x.WaitForNonStaleResults())
  108. .As<BlogPost>()
  109. .ToListAsync();
  110. Assert.Equal(5, query.Count);
  111. }
  112. }
  113. }
  114. [Fact]
  115. public async Task EmptyListAsync()
  116. {
  117. using (var store = GetDocumentStore())
  118. {
  119. await store.ExecuteIndexAsync(new BlogPostAll());
  120. using (var session = store.OpenAsyncSession())
  121. {
  122. for (var i = 0; i < 5; i++)
  123. {
  124. await session.StoreAsync(new BlogPost
  125. {
  126. Title = "Lorem Ipsum " + i,
  127. Username = "Anonymous",
  128. BlogComments = new List<string>(),
  129. Post = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. " +
  130. "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. " +
  131. "It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. " +
  132. "It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
  133. }, "BlogPosts/" + i);
  134. }
  135. await session.SaveChangesAsync();
  136. var query = await session.Query<BlogPostAll.Mapping, BlogPostAll>()
  137. .Customize(x => x.WaitForNonStaleResults())
  138. .As<BlogPost>()
  139. .ToListAsync();
  140. Assert.Equal(5, query.Count);
  141. }
  142. }
  143. }
  144. [Fact]
  145. public async Task ListContainingNullAsync()
  146. {
  147. using (var store = GetDocumentStore())
  148. {
  149. await store.ExecuteIndexAsync(new BlogPostAll());
  150. using (var session = store.OpenAsyncSession())
  151. {
  152. for (var i = 0; i < 5; i++)
  153. {
  154. await session.StoreAsync(new BlogPost
  155. {
  156. Title = "Lorem Ipsum " + i,
  157. Username = "Anonymous",
  158. BlogComments = new List<string>()
  159. {
  160. null
  161. },
  162. Post = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. " +
  163. "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. " +
  164. "It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. " +
  165. "It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
  166. }, "BlogPosts/" + i);
  167. }
  168. await session.SaveChangesAsync();
  169. var query = await session.Query<BlogPostAll.Mapping, BlogPostAll>()
  170. .Customize(x => x.WaitForNonStaleResults())
  171. .As<BlogPost>()
  172. .ToListAsync();
  173. Assert.Equal(5, query.Count);
  174. }
  175. }
  176. }
  177. [Fact]
  178. public async Task ListWithRatingAsync()
  179. {
  180. using (var store = GetDocumentStore())
  181. {
  182. await store.ExecuteIndexAsync(new BlogPostWithAverageRatingAll());
  183. using (var session = store.OpenAsyncSession())
  184. {
  185. var rating = new BlogCommentRating()
  186. {
  187. Rating = 4
  188. };
  189. await session.StoreAsync(rating, "BlogCommentRating/" + 1);
  190. for (var i = 0; i < 5; i++)
  191. {
  192. await session.StoreAsync(new BlogComment
  193. {
  194. Username = "Anonymous",
  195. BlogCommentRatingId = "BlogCommentRating/" + 1,
  196. Comment = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. " +
  197. "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. " +
  198. "It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. " +
  199. "It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
  200. }, "BlogComments/" + i);
  201. }
  202. for (var i = 0; i < 5; i++)
  203. {
  204. await session.StoreAsync(new BlogPost
  205. {
  206. Title = "Lorem Ipsum " + i,
  207. Username = "Anonymous",
  208. BlogComments = new List<string>()
  209. {
  210. "BlogComments/" + i,
  211. },
  212. Post = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. " +
  213. "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. " +
  214. "It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. " +
  215. "It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
  216. }, "BlogPosts/" + i);
  217. }
  218. await session.SaveChangesAsync();
  219. var query = await session.Query<BlogPostWithAverageRatingAll.Mapping, BlogPostWithAverageRatingAll>()
  220. .Customize(x => x.WaitForNonStaleResults())
  221. .As<BlogPost>()
  222. .ToListAsync();
  223. Assert.Equal(5, query.Count);
  224. }
  225. }
  226. }
  227. [Fact]
  228. public async Task ListWithRatingNullAsync()
  229. {
  230. using (var store = GetDocumentStore())
  231. {
  232. await store.ExecuteIndexAsync(new BlogPostWithAverageRatingAll());
  233. using (var session = store.OpenAsyncSession())
  234. {
  235. for (var i = 0; i < 5; i++)
  236. {
  237. await session.StoreAsync(new BlogPost
  238. {
  239. Title = "Lorem Ipsum " + i,
  240. Username = "Anonymous",
  241. BlogComments = null,
  242. Post = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. " +
  243. "Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. " +
  244. "It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. " +
  245. "It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
  246. }, "BlogPosts/" + i);
  247. }
  248. await session.SaveChangesAsync();
  249. var query = await session.Query<BlogPostWithAverageRatingAll.Mapping, BlogPostWithAverageRatingAll>()
  250. .Customize(x=>x.WaitForNonStaleResults())
  251. .As<BlogPost>()
  252. .ToListAsync();
  253. Assert.Equal(5, query.Count);
  254. }
  255. }
  256. }
  257. }
  258. }