PageRenderTime 6ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms 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
 1using System;
 2using Bifrost.MSpec.Events;
 3using Bifrost.Samples.Blog.Domain.Posts;
 4using Bifrost.Samples.Blog.Domain.Posts.Commands;
 5using Bifrost.Samples.Blog.Events.Posts;
 6using Machine.Specifications;
 7
 8namespace Bifrost.Samples.Blog.Domain.Specs.Posts.for_Post_command_handlers
 9{
10
11    public class when_handling_create_post : given.a_post_command_handler
12    {
13        static Post post;
14        static CreatePost create_post;
15        static Guid post_id;
16
17        Establish context = () =>
18                                {
19                                    post_id = Guid.NewGuid();
20                                    post = new Post(post_id);
21                                    factory_mock.Setup(f => f.Create(post_id)).Returns(post);
22                                };
23
24        Because of = () =>
25                         {
26                             create_post = new CreatePost
27                                               {
28                                                   Id = post_id,
29                                                   Title = "A Title",
30                                                   Body = "A Body",
31                                                   BlogId = Guid.NewGuid(),
32                                               };
33                             command_handler.Handle(create_post);
34                         };
35
36        It should_create_a_post = () => factory_mock.Verify(f => f.Create(Moq.It.IsAny<Guid>()));
37        It should_apply_post_created_with_values = () =>
38                                                   post.ShouldHaveEvent<PostCreated>().AtBeginning().
39                                                       Where(c => c.Title.ShouldEqual(create_post.Title),
40                                                              c => c.BlogId.ShouldEqual(create_post.BlogId));
41        It should_apply_title_set_with_values = () =>
42                                                post.ShouldHaveEvent<TitleSet>().AtSequenceNumber(1).
43                                                    Where(c => c.Title.ShouldEqual(create_post.Title));
44        It should_apply_body_set_with_values = () =>
45                                        post.ShouldHaveEvent<BodySet>().AtEnd().
46                                            Where(c => c.Body.ShouldEqual(create_post.Body));
47
48    }
49}