Beispiel #1
0
        public void Given_BlogWithCategoriesWithTags_When_StartPostCommand_With_ValidParams_Then_PostStartedEvent(string host, string url, string title, string body, string publishAt, string categoryUrl, string categoryTitle, string tagUrl, string tagTitle, bool inforbar, bool hidden, bool comments)
        {
            var command = new StartPostCommand(host, url, title, body, DateTime.Parse(publishAt), categoryUrl, new HashSet <string> {
                tagUrl
            }, inforbar, hidden, comments);
            var expectedEvent = new PostStartedEvent(host, url, title, body, DateTime.Parse(publishAt), categoryTitle, categoryUrl, new List <PostStartedEvent.PostStartedEventTag> {
                new PostStartedEvent.PostStartedEventTag(tagUrl, tagTitle)
            }, inforbar, hidden, comments);

            Given.DefaultBlog().WithCategories().WithTags()
            .Begin()
            .When(command)
            .Then(expectedEvent)
            .End();
        }
Beispiel #2
0
        public void Handle(PostStartedEvent evnt)
        {
            var key = KeyUtils.GetStateKey(evnt.AggregateId);

            var state = _db.GetObject <BlogState>(key);

            if (state == null)
            {
                throw new Exception("Blog has to be started first.");
            }

            var bodyHtml      = TextUtils.GetHtmlFromMarkdown(evnt.Body);
            var bodyShortHtml = TextUtils.GetHtmlFromMarkdown(TextUtils.GetBodyShort(evnt.Body));

            var tags = evnt.Tags.Select(_ => new TagState
            {
                TagUrl   = _.Url,
                TagTitle = _.Title
            }).ToList();

            var post = new PostState
            {
                Url           = evnt.Url,
                Title         = evnt.Title,
                Body          = bodyHtml,
                BodyShort     = bodyShortHtml,
                PublishAt     = evnt.PublishAt,
                CategoryTitle = evnt.CategoryTitle,
                CategoryUrl   = evnt.CategoryUrl,
                Infobar       = evnt.Infobar,
                IsHidden      = evnt.Hidden,
                Tags          = tags
            };

            state.Posts.Add(post);

            _db.SetObject(key, state);
        }
Beispiel #3
0
        public void Apply(PostStartedEvent evnt)
        {
            var category = _categories.GetCategory(evnt.CategoryUrl);

            category.Posts.Add(new Post(evnt.Url, evnt.Title, evnt.Body));
        }