PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/Samples/Blog/Bifrost.Samples.Blog.Domain.Specs/Posts/for_Post_command_handlers/when_handling_create_post.cs

#
C# | 49 lines | 43 code | 6 blank | 0 comment | 0 complexity | 8249fdb9ed97ddcb2f8125c70d4e38bf MD5 | raw file
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using Bifrost.MSpec.Events;
  3. using Bifrost.Samples.Blog.Domain.Posts;
  4. using Bifrost.Samples.Blog.Domain.Posts.Commands;
  5. using Bifrost.Samples.Blog.Events.Posts;
  6. using Machine.Specifications;
  7. namespace Bifrost.Samples.Blog.Domain.Specs.Posts.for_Post_command_handlers
  8. {
  9. public class when_handling_create_post : given.a_post_command_handler
  10. {
  11. static Post post;
  12. static CreatePost create_post;
  13. static Guid post_id;
  14. Establish context = () =>
  15. {
  16. post_id = Guid.NewGuid();
  17. post = new Post(post_id);
  18. factory_mock.Setup(f => f.Create(post_id)).Returns(post);
  19. };
  20. Because of = () =>
  21. {
  22. create_post = new CreatePost
  23. {
  24. Id = post_id,
  25. Title = "A Title",
  26. Body = "A Body",
  27. BlogId = Guid.NewGuid(),
  28. };
  29. command_handler.Handle(create_post);
  30. };
  31. It should_create_a_post = () => factory_mock.Verify(f => f.Create(Moq.It.IsAny<Guid>()));
  32. It should_apply_post_created_with_values = () =>
  33. post.ShouldHaveEvent<PostCreated>().AtBeginning().
  34. Where(c => c.Title.ShouldEqual(create_post.Title),
  35. c => c.BlogId.ShouldEqual(create_post.BlogId));
  36. It should_apply_title_set_with_values = () =>
  37. post.ShouldHaveEvent<TitleSet>().AtSequenceNumber(1).
  38. Where(c => c.Title.ShouldEqual(create_post.Title));
  39. It should_apply_body_set_with_values = () =>
  40. post.ShouldHaveEvent<BodySet>().AtEnd().
  41. Where(c => c.Body.ShouldEqual(create_post.Body));
  42. }
  43. }