Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 791 lines (712 sloc) 16.666 kb
a62b637 Demis Bellot first commit of new git src repo
mythz authored
1 using System;
2 using System.Collections.Generic;
c55b157 Sergey Bogdanov - replaced Console.WriteLine with Debug.WriteLine to minimize output to ...
desunit authored
3 using System.Diagnostics;
a62b637 Demis Bellot first commit of new git src repo
mythz authored
4 using System.Linq;
5 using NUnit.Framework;
6 using ServiceStack.Common;
9c990b0 Demis Bellot Re-factor to use new SS.Common extensions Each/Map to avoid collisions w...
mythz authored
7 using ServiceStack.Common;
a62b637 Demis Bellot first commit of new git src repo
mythz authored
8 using ServiceStack.Text;
9
10 namespace ServiceStack.Redis.Tests.Examples.BestPractice
11 {
12
13 /// <summary>
14 /// A complete, self-contained example showing how to create a basic blog application using Redis.
15 /// </summary>
16
17 #region Blog Models
18
19 public class User
20 : IHasBlogRepository
21 {
22 public IBlogRepository Repository { private get; set; }
23
24 public User()
25 {
3c81276 Demis Bellot changed Incr/IncrBy/Decr/DecrBy to return longs
mythz authored
26 this.BlogIds = new List<long>();
a62b637 Demis Bellot first commit of new git src repo
mythz authored
27 }
28
3c81276 Demis Bellot changed Incr/IncrBy/Decr/DecrBy to return longs
mythz authored
29 public long Id { get; set; }
a62b637 Demis Bellot first commit of new git src repo
mythz authored
30 public string Name { get; set; }
3c81276 Demis Bellot changed Incr/IncrBy/Decr/DecrBy to return longs
mythz authored
31 public List<long> BlogIds { get; set; }
a62b637 Demis Bellot first commit of new git src repo
mythz authored
32
33 public List<Blog> GetBlogs()
34 {
35 return this.Repository.GetBlogs(this.BlogIds);
36 }
37
38 public Blog CreateNewBlog(Blog blog)
39 {
40 this.Repository.StoreBlogs(this, blog);
41
42 return blog;
43 }
44 }
45
46 public class Blog
47 : IHasBlogRepository
48 {
49 public IBlogRepository Repository { private get; set; }
50
51 public Blog()
52 {
53 this.Tags = new List<string>();
3c81276 Demis Bellot changed Incr/IncrBy/Decr/DecrBy to return longs
mythz authored
54 this.BlogPostIds = new List<long>();
a62b637 Demis Bellot first commit of new git src repo
mythz authored
55 }
56
3c81276 Demis Bellot changed Incr/IncrBy/Decr/DecrBy to return longs
mythz authored
57 public long Id { get; set; }
58 public long UserId { get; set; }
a62b637 Demis Bellot first commit of new git src repo
mythz authored
59 public string UserName { get; set; }
60 public List<string> Tags { get; set; }
3c81276 Demis Bellot changed Incr/IncrBy/Decr/DecrBy to return longs
mythz authored
61 public List<long> BlogPostIds { get; set; }
a62b637 Demis Bellot first commit of new git src repo
mythz authored
62
63 public List<BlogPost> GetBlogPosts()
64 {
65 return this.Repository.GetBlogPosts(this.BlogPostIds);
66 }
67
68 public void StoreNewBlogPosts(params BlogPost[] blogPosts)
69 {
70 this.Repository.StoreNewBlogPosts(this, blogPosts);
71 }
72 }
73
74 public class BlogPost
75 {
76 public BlogPost()
77 {
78 this.Categories = new List<string>();
79 this.Tags = new List<string>();
80 this.Comments = new List<BlogPostComment>();
81 }
82
3c81276 Demis Bellot changed Incr/IncrBy/Decr/DecrBy to return longs
mythz authored
83 public long Id { get; set; }
84 public long BlogId { get; set; }
a62b637 Demis Bellot first commit of new git src repo
mythz authored
85 public string Title { get; set; }
86 public string Content { get; set; }
87 public List<string> Categories { get; set; }
88 public List<string> Tags { get; set; }
89 public List<BlogPostComment> Comments { get; set; }
90 }
91
92 public class BlogPostComment
93 {
94 public string Content { get; set; }
95 public DateTime CreatedDate { get; set; }
96 }
97 #endregion
98
99
100 #region Blog Repository
101 public interface IHasBlogRepository
102 {
103 IBlogRepository Repository { set; }
104 }
105
106 public class BlogRepository
107 : IBlogRepository
108 {
109 const string CategoryTypeName = "Category";
110 const string TagCloudKey = "urn:TagCloud";
111 const string AllCategoriesKey = "urn:Categories";
112 const string RecentBlogPostsKey = "urn:BlogPosts:RecentPosts";
113 const string RecentBlogPostCommentsKey = "urn:BlogPostComment:RecentComments";
114
115 public BlogRepository(IRedisClient client)
116 {
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
117 this.redis = client;
a62b637 Demis Bellot first commit of new git src repo
mythz authored
118 }
119
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
120 private readonly IRedisClient redis;
a62b637 Demis Bellot first commit of new git src repo
mythz authored
121
122 public void StoreUsers(params User[] users)
123 {
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
124 var redisUsers = redis.As<User>();
125 Inject(users);
126 users.Where(x => x.Id == default(int))
127 .Each(x => x.Id = redisUsers.GetNextSequence());
128
129 redisUsers.StoreAll(users);
130 }
a62b637 Demis Bellot first commit of new git src repo
mythz authored
131
132 public List<User> GetAllUsers()
133 {
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
134 var redisUsers = redis.As<User>();
135 return Inject(redisUsers.GetAll());
136 }
a62b637 Demis Bellot first commit of new git src repo
mythz authored
137
138 public void StoreBlogs(User user, params Blog[] blogs)
139 {
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
140 var redisBlogs = redis.As<Blog>();
141 foreach (var blog in blogs)
142 {
143 blog.Id = blog.Id != default(int) ? blog.Id : redisBlogs.GetNextSequence();
144 blog.UserId = user.Id;
145 blog.UserName = user.Name;
146
147 user.BlogIds.AddIfNotExists(blog.Id);
148 }
149
150 using (var trans = redis.CreateTransaction())
151 {
152 trans.QueueCommand(x => x.Store(user));
153 trans.QueueCommand(x => x.StoreAll(blogs));
154
155 trans.Commit();
156 }
157
158 Inject(blogs);
159 }
a62b637 Demis Bellot first commit of new git src repo
mythz authored
160
3c81276 Demis Bellot changed Incr/IncrBy/Decr/DecrBy to return longs
mythz authored
161 public List<Blog> GetBlogs(IEnumerable<long> blogIds)
a62b637 Demis Bellot first commit of new git src repo
mythz authored
162 {
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
163 var redisBlogs = redis.As<Blog>();
164 return Inject(
165 redisBlogs.GetByIds(blogIds.Map(x => x.ToString())));
166 }
a62b637 Demis Bellot first commit of new git src repo
mythz authored
167
168 public List<Blog> GetAllBlogs()
169 {
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
170 var redisBlogs = redis.As<Blog>();
171 return Inject(redisBlogs.GetAll());
172 }
a62b637 Demis Bellot first commit of new git src repo
mythz authored
173
3c81276 Demis Bellot changed Incr/IncrBy/Decr/DecrBy to return longs
mythz authored
174 public List<BlogPost> GetBlogPosts(IEnumerable<long> blogPostIds)
a62b637 Demis Bellot first commit of new git src repo
mythz authored
175 {
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
176 var redisBlogPosts = redis.As<BlogPost>();
177 return redisBlogPosts.GetByIds(blogPostIds.Map(x => x.ToString())).ToList();
178 }
a62b637 Demis Bellot first commit of new git src repo
mythz authored
179
180 public void StoreNewBlogPosts(Blog blog, params BlogPost[] blogPosts)
181 {
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
182 var redisBlogPosts = redis.As<BlogPost>();
183 var redisComments = redis.As<BlogPostComment>();
184
185 //Get wrapper around a strongly-typed Redis server-side List
186 var recentPosts = redisBlogPosts.Lists[RecentBlogPostsKey];
187 var recentComments = redisComments.Lists[RecentBlogPostCommentsKey];
188
189 foreach (var blogPost in blogPosts)
190 {
191 blogPost.Id = blogPost.Id != default(int) ? blogPost.Id : redisBlogPosts.GetNextSequence();
192 blogPost.BlogId = blog.Id;
193 blog.BlogPostIds.AddIfNotExists(blogPost.Id);
194
195 //List of Recent Posts and comments
196 recentPosts.Prepend(blogPost);
197 blogPost.Comments.ForEach(recentComments.Prepend);
198
199 //Tag Cloud
200 blogPost.Tags.ForEach(x =>
201 redis.IncrementItemInSortedSet(TagCloudKey, x, 1));
202
203 //List of all post categories
204 blogPost.Categories.ForEach(x =>
205 redis.AddItemToSet(AllCategoriesKey, x));
206
207 //Map of Categories to BlogPost Ids
208 blogPost.Categories.ForEach(x =>
209 redis.AddItemToSet(UrnId.Create(CategoryTypeName, x), blogPost.Id.ToString()));
210 }
211
212 //Rolling list of recent items, only keep the last 5
213 recentPosts.Trim(0, 4);
214 recentComments.Trim(0, 4);
215
216 using (var trans = redis.CreateTransaction())
217 {
218 trans.QueueCommand(x => x.Store(blog));
219 trans.QueueCommand(x => x.StoreAll(blogPosts));
220
221 trans.Commit();
222 }
223 }
a62b637 Demis Bellot first commit of new git src repo
mythz authored
224
225 public List<BlogPost> GetRecentBlogPosts()
226 {
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
227 var redisBlogPosts = redis.As<BlogPost>();
228 return redisBlogPosts.Lists[RecentBlogPostsKey].GetAll();
a62b637 Demis Bellot first commit of new git src repo
mythz authored
229 }
230
231 public List<BlogPostComment> GetRecentBlogPostComments()
232 {
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
233 var redisComments = redis.As<BlogPostComment>();
234 return redisComments.Lists[RecentBlogPostCommentsKey].GetAll();
235 }
a62b637 Demis Bellot first commit of new git src repo
mythz authored
236
237 public IDictionary<string, double> GetTopTags(int take)
238 {
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
239 return redis.GetRangeWithScoresFromSortedSetDesc(TagCloudKey, 0, take - 1);
a62b637 Demis Bellot first commit of new git src repo
mythz authored
240 }
241
242 public HashSet<string> GetAllCategories()
243 {
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
244 return redis.GetAllItemsFromSet(AllCategoriesKey);
a62b637 Demis Bellot first commit of new git src repo
mythz authored
245 }
246
247 public void StoreBlogPost(BlogPost blogPost)
248 {
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
249 redis.Store(blogPost);
a62b637 Demis Bellot first commit of new git src repo
mythz authored
250 }
251
252 public BlogPost GetBlogPost(int postId)
253 {
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
254 return redis.GetById<BlogPost>(postId);
a62b637 Demis Bellot first commit of new git src repo
mythz authored
255 }
256
257 public List<BlogPost> GetBlogPostsByCategory(string categoryName)
258 {
259 var categoryUrn = UrnId.Create(CategoryTypeName, categoryName);
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
260 var documentDbPostIds = redis.GetAllItemsFromSet(categoryUrn);
a62b637 Demis Bellot first commit of new git src repo
mythz authored
261
e5f2eb4 Demis Bellot Remove all deprecated code, refactor GetTypedClient<T> to use As<T>
mythz authored
262 return redis.GetByIds<BlogPost>(documentDbPostIds.ToArray()).ToList();
a62b637 Demis Bellot first commit of new git src repo
mythz authored
263 }
264
265 public List<T> Inject<T>(IEnumerable<T> entities)
266 where T : IHasBlogRepository
267 {
268 var entitiesList = entities.ToList();
269 entitiesList.ForEach(x => x.Repository = this);
270 return entitiesList;
271 }
272
273 }
274 #endregion
275
276
c55b157 Sergey Bogdanov - replaced Console.WriteLine with Debug.WriteLine to minimize output to ...
desunit authored
277 [TestFixture, Explicit, Category("Integration")]
a62b637 Demis Bellot first commit of new git src repo
mythz authored
278 public class BlogPostBestPractice
279 {
280 readonly RedisClient redisClient = new RedisClient(TestConfig.SingleHost);
281 private IBlogRepository repository;
282
283 [SetUp]
284 public void OnBeforeEachTest()
285 {
286 redisClient.FlushAll();
287 repository = new BlogRepository(redisClient);
288
289 InsertTestData(repository);
290 }
291
292 public static void InsertTestData(IBlogRepository repository)
293 {
294 var ayende = new User { Name = "ayende" };
295 var mythz = new User { Name = "mythz" };
296
297 repository.StoreUsers(ayende, mythz);
298
299 var ayendeBlog = ayende.CreateNewBlog(new Blog { Tags = { "Architecture", ".NET", "Databases" } });
300
301 var mythzBlog = mythz.CreateNewBlog(new Blog { Tags = { "Architecture", ".NET", "Databases" }});
302
303 ayendeBlog.StoreNewBlogPosts(new BlogPost
304 {
305 Title = "RavenDB",
306 Categories = new List<string> { "NoSQL", "DocumentDB" },
307 Tags = new List<string> { "Raven", "NoSQL", "JSON", ".NET" },
308 Comments = new List<BlogPostComment>
309 {
310 new BlogPostComment { Content = "First Comment!", CreatedDate = DateTime.UtcNow,},
311 new BlogPostComment { Content = "Second Comment!", CreatedDate = DateTime.UtcNow,},
312 }
313 },
314 new BlogPost
315 {
316 BlogId = ayendeBlog.Id,
317 Title = "Cassandra",
318 Categories = new List<string> { "NoSQL", "Cluster" },
319 Tags = new List<string> { "Cassandra", "NoSQL", "Scalability", "Hashing" },
320 Comments = new List<BlogPostComment>
321 {
322 new BlogPostComment { Content = "First Comment!", CreatedDate = DateTime.UtcNow,}
323 }
324 });
325
326 mythzBlog.StoreNewBlogPosts(
327 new BlogPost
328 {
329 Title = "Redis",
330 Categories = new List<string> { "NoSQL", "Cache" },
331 Tags = new List<string> { "Redis", "NoSQL", "Scalability", "Performance" },
332 Comments = new List<BlogPostComment>
333 {
334 new BlogPostComment { Content = "First Comment!", CreatedDate = DateTime.UtcNow,}
335 }
336 },
337 new BlogPost
338 {
339 Title = "Couch Db",
340 Categories = new List<string> { "NoSQL", "DocumentDB" },
341 Tags = new List<string> { "CouchDb", "NoSQL", "JSON" },
342 Comments = new List<BlogPostComment>
343 {
344 new BlogPostComment {Content = "First Comment!", CreatedDate = DateTime.UtcNow,}
345 }
346 });
347 }
348
349 [Test]
350 public void View_test_data()
351 {
352 var mythz = repository.GetAllUsers().First(x => x.Name == "mythz");
353 var mythzBlogPostIds = mythz.GetBlogs().SelectMany(x => x.BlogPostIds);
354 var mythzBlogPosts = repository.GetBlogPosts(mythzBlogPostIds);
355
c55b157 Sergey Bogdanov - replaced Console.WriteLine with Debug.WriteLine to minimize output to ...
desunit authored
356 Debug.WriteLine(mythzBlogPosts.Dump());
a62b637 Demis Bellot first commit of new git src repo
mythz authored
357 /* Output:
358 [
359 {
360 Id: 3,
361 BlogId: 2,
362 Title: Redis,
363 Categories:
364 [
365 NoSQL,
366 Cache
367 ],
368 Tags:
369 [
370 Redis,
371 NoSQL,
372 Scalability,
373 Performance
374 ],
375 Comments:
376 [
377 {
378 Content: First Comment!,
379 CreatedDate: 2010-04-26T02:24:47.516949Z
380 }
381 ]
382 },
383 {
384 Id: 4,
385 BlogId: 2,
386 Title: Couch Db,
387 Categories:
388 [
389 NoSQL,
390 DocumentDB
391 ],
392 Tags:
393 [
394 CouchDb,
395 NoSQL,
396 JSON
397 ],
398 Comments:
399 [
400 {
401 Content: First Comment!,
402 CreatedDate: 2010-04-26T02:24:47.516949Z
403 }
404 ]
405 }
406 ]
407 */
408 }
409
410 [Test]
411 public void Show_a_list_of_blogs()
412 {
413 var blogs = repository.GetAllBlogs();
c55b157 Sergey Bogdanov - replaced Console.WriteLine with Debug.WriteLine to minimize output to ...
desunit authored
414 Debug.WriteLine(blogs.Dump());
a62b637 Demis Bellot first commit of new git src repo
mythz authored
415 /* Output:
416 [
417 {
418 Id: 1,
419 UserId: 1,
420 UserName: ayende,
421 Tags:
422 [
423 Architecture,
424 .NET,
425 Databases
426 ],
427 BlogPostIds:
428 [
429 1,
430 2
431 ]
432 },
433 {
434 Id: 2,
435 UserId: 2,
436 UserName: mythz,
437 Tags:
438 [
439 Architecture,
440 .NET,
441 Databases
442 ],
443 BlogPostIds:
444 [
445 3,
446 4
447 ]
448 }
449 ]
450 */
451 }
452
453 [Test]
454 public void Show_a_list_of_recent_posts_and_comments()
455 {
456 //Recent posts are already maintained in the repository
457 var recentPosts = repository.GetRecentBlogPosts();
458 var recentComments = repository.GetRecentBlogPostComments();
459
c55b157 Sergey Bogdanov - replaced Console.WriteLine with Debug.WriteLine to minimize output to ...
desunit authored
460 Debug.WriteLine("Recent Posts:\n" + recentPosts.Dump());
461 Debug.WriteLine("Recent Comments:\n" + recentComments.Dump());
a62b637 Demis Bellot first commit of new git src repo
mythz authored
462 /*
463 Recent Posts:
464 [
465 {
466 Id: 4,
467 BlogId: 2,
468 Title: Couch Db,
469 Categories:
470 [
471 NoSQL,
472 DocumentDB
473 ],
474 Tags:
475 [
476 CouchDb,
477 NoSQL,
478 JSON
479 ],
480 Comments:
481 [
482 {
483 Content: First Comment!,
484 CreatedDate: 2010-04-26T02:25:39.7419361Z
485 }
486 ]
487 },
488 {
489 Id: 3,
490 BlogId: 2,
491 Title: Redis,
492 Categories:
493 [
494 NoSQL,
495 Cache
496 ],
497 Tags:
498 [
499 Redis,
500 NoSQL,
501 Scalability,
502 Performance
503 ],
504 Comments:
505 [
506 {
507 Content: First Comment!,
508 CreatedDate: 2010-04-26T02:25:39.7419361Z
509 }
510 ]
511 },
512 {
513 Id: 2,
514 BlogId: 1,
515 Title: Cassandra,
516 Categories:
517 [
518 NoSQL,
519 Cluster
520 ],
521 Tags:
522 [
523 Cassandra,
524 NoSQL,
525 Scalability,
526 Hashing
527 ],
528 Comments:
529 [
530 {
531 Content: First Comment!,
532 CreatedDate: 2010-04-26T02:25:39.7039339Z
533 }
534 ]
535 },
536 {
537 Id: 1,
538 BlogId: 1,
539 Title: RavenDB,
540 Categories:
541 [
542 NoSQL,
543 DocumentDB
544 ],
545 Tags:
546 [
547 Raven,
548 NoSQL,
549 JSON,
550 .NET
551 ],
552 Comments:
553 [
554 {
555 Content: First Comment!,
556 CreatedDate: 2010-04-26T02:25:39.7039339Z
557 },
558 {
559 Content: Second Comment!,
560 CreatedDate: 2010-04-26T02:25:39.7039339Z
561 }
562 ]
563 }
564 ]
565
566 Recent Comments:
567 [
568 {
569 Content: First Comment!,
570 CreatedDate: 2010-04-26T02:25:39.7419361Z
571 },
572 {
573 Content: First Comment!,
574 CreatedDate: 2010-04-26T02:25:39.7419361Z
575 },
576 {
577 Content: First Comment!,
578 CreatedDate: 2010-04-26T02:25:39.7039339Z
579 },
580 {
581 Content: Second Comment!,
582 CreatedDate: 2010-04-26T02:25:39.7039339Z
583 },
584 {
585 Content: First Comment!,
586 CreatedDate: 2010-04-26T02:25:39.7039339Z
587 }
588 ]
589
590 */
591 }
592
593 [Test]
594 public void Show_a_TagCloud()
595 {
596 //Tags are maintained in the repository
597 var tagCloud = repository.GetTopTags(5);
c55b157 Sergey Bogdanov - replaced Console.WriteLine with Debug.WriteLine to minimize output to ...
desunit authored
598 Debug.WriteLine(tagCloud.Dump());
a62b637 Demis Bellot first commit of new git src repo
mythz authored
599 /* Output:
600 [
601 [
602 NoSQL,
603 4
604 ],
605 [
606 Scalability,
607 2
608 ],
609 [
610 JSON,
611 2
612 ],
613 [
614 Redis,
615 1
616 ],
617 [
618 Raven,
619 1
620 ]
621 ]
622 */
623 }
624
625 [Test]
626 public void Show_all_Categories()
627 {
628 //Categories are maintained in the repository
629 var allCategories = repository.GetAllCategories();
c55b157 Sergey Bogdanov - replaced Console.WriteLine with Debug.WriteLine to minimize output to ...
desunit authored
630 Debug.WriteLine(allCategories.Dump());
a62b637 Demis Bellot first commit of new git src repo
mythz authored
631 /* Output:
632 [
633 DocumentDB,
634 NoSQL,
635 Cluster,
636 Cache
637 ]
638 */
639 }
640
641 [Test]
642 public void Show_post_and_all_comments()
643 {
644 var postId = 1;
645 var blogPost = repository.GetBlogPost(postId);
c55b157 Sergey Bogdanov - replaced Console.WriteLine with Debug.WriteLine to minimize output to ...
desunit authored
646 Debug.WriteLine(blogPost.Dump());
a62b637 Demis Bellot first commit of new git src repo
mythz authored
647 /* Output:
648 {
649 Id: 1,
650 BlogId: 1,
651 Title: RavenDB,
652 Categories:
653 [
654 NoSQL,
655 DocumentDB
656 ],
657 Tags:
658 [
659 Raven,
660 NoSQL,
661 JSON,
662 .NET
663 ],
664 Comments:
665 [
666 {
667 Content: First Comment!,
668 CreatedDate: 2010-04-26T02:00:24.5982749Z
669 },
670 {
671 Content: Second Comment!,
672 CreatedDate: 2010-04-26T02:00:24.5982749Z
673 }
674 ]
675 }
676 */
677 }
678
679 [Test]
680 public void Add_comment_to_existing_post()
681 {
682 var postId = 1;
683 var blogPost = repository.GetBlogPost(postId);
684
685 blogPost.Comments.Add(
686 new BlogPostComment { Content = "Third Comment!", CreatedDate = DateTime.UtcNow });
687
688 repository.StoreBlogPost(blogPost);
689
690 var refreshBlogPost = repository.GetBlogPost(postId);
c55b157 Sergey Bogdanov - replaced Console.WriteLine with Debug.WriteLine to minimize output to ...
desunit authored
691 Debug.WriteLine(refreshBlogPost.Dump());
a62b637 Demis Bellot first commit of new git src repo
mythz authored
692 /* Output:
693 {
694 Id: 1,
695 BlogId: 1,
696 Title: RavenDB,
697 Categories:
698 [
699 NoSQL,
700 DocumentDB
701 ],
702 Tags:
703 [
704 Raven,
705 NoSQL,
706 JSON,
707 .NET
708 ],
709 Comments:
710 [
711 {
712 Content: First Comment!,
713 CreatedDate: 2010-04-26T02:08:13.5580978Z
714 },
715 {
716 Content: Second Comment!,
717 CreatedDate: 2010-04-26T02:08:13.5580978Z
718 },
719 {
720 Content: Third Comment!,
721 CreatedDate: 2010-04-26T02:08:13.6871052Z
722 }
723 ]
724 }
725 */
726 }
727
728 [Test]
729 public void Show_all_Posts_for_a_Category()
730 {
731 var documentDbPosts = repository.GetBlogPostsByCategory("DocumentDB");
c55b157 Sergey Bogdanov - replaced Console.WriteLine with Debug.WriteLine to minimize output to ...
desunit authored
732 Debug.WriteLine(documentDbPosts.Dump());
a62b637 Demis Bellot first commit of new git src repo
mythz authored
733 /* Output:
734 [
735 {
736 Id: 4,
737 BlogId: 2,
738 Title: Couch Db,
739 Categories:
740 [
741 NoSQL,
742 DocumentDB
743 ],
744 Tags:
745 [
746 CouchDb,
747 NoSQL,
748 JSON
749 ],
750 Comments:
751 [
752 {
753 Content: First Comment!,
754 CreatedDate: 2010-04-26T02:16:08.0332362Z
755 }
756 ]
757 },
758 {
759 Id: 1,
760 BlogId: 1,
761 Title: RavenDB,
762 Categories:
763 [
764 NoSQL,
765 DocumentDB
766 ],
767 Tags:
768 [
769 Raven,
770 NoSQL,
771 JSON,
772 .NET
773 ],
774 Comments:
775 [
776 {
777 Content: First Comment!,
778 CreatedDate: 2010-04-26T02:16:07.9662324Z
779 },
780 {
781 Content: Second Comment!,
782 CreatedDate: 2010-04-26T02:16:07.9662324Z
783 }
784 ]
785 }
786 ]
787 */
788 }
789
790 }
791 }
Something went wrong with that request. Please try again.