コード例 #1
0
        public void UpdatePublishDateOfExistintPost_WillUpdateTheDateAndTimeCorrectly()
        {
            Session.Store(new Post {
                PublishAt = Now.AddDays(-3)
            });
            Session.Store(new Post {
                PublishAt = Now.AddHours(-1)
            });
            Session.Store(new Post {
                PublishAt = Now.AddHours(12)
            });
            Session.SaveChanges();

            var lastPost = Session.Query <Post>()
                           .OrderByDescending(post => post.PublishAt)
                           .First();

            Assert.Equal(Now.AddHours(12), lastPost.PublishAt);

            var rescheduler = new PostSchedulingStrategy(Session, Now);

            lastPost.PublishAt = rescheduler.Schedule(Now.AddHours(6));
            Session.SaveChanges();

            Assert.Equal(Now.AddHours(6), lastPost.PublishAt);
        }
コード例 #2
0
        public void WhenPostingNewPostWithoutPublishDateSpecified_AndThereIsNoLastPost_ScheduleItForTomorrowAtNoot()
        {
            var rescheduler = new PostSchedulingStrategy(Session, Now);

            var result = rescheduler.Schedule();

            Assert.Equal(Now.AddDays(1).SkipToNextWorkDay().AtNoon(), result);
        }
コード例 #3
0
        public ActionResult Update(PostInput input)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", input));
            }

            var post = RavenSession.Load <Post>(input.Id) ?? new Post {
                CreatedAt = DateTimeOffset.Now
            };

            input.MapPropertiesToInstance(post);

            // Be able to record the user making the actual post
            var user = RavenSession.GetCurrentUser();

            if (string.IsNullOrEmpty(post.AuthorId))
            {
                post.AuthorId = user.Id;
            }
            else
            {
                post.LastEditedByUserId = user.Id;
                post.LastEditedAt       = DateTimeOffset.Now;
            }

            if (post.PublishAt == DateTimeOffset.MinValue)
            {
                var postScheduleringStrategy = new PostSchedulingStrategy(RavenSession, DateTimeOffset.Now);
                post.PublishAt = postScheduleringStrategy.Schedule();
            }

            // Actually save the post now
            RavenSession.Store(post);

            if (input.IsNewPost())
            {
                // Create the post comments object and link between it and the post
                var comments = new PostComments
                {
                    Comments = new List <PostComments.Comment>(),
                    Spam     = new List <PostComments.Comment>(),
                    Post     = new PostComments.PostReference
                    {
                        Id        = post.Id,
                        PublishAt = post.PublishAt,
                    }
                };

                RavenSession.Store(comments);

                // Once the Comments have been saved, update and save the post
                post.CommentsId = comments.Id;
                RavenSession.Store(post);
            }

            return(RedirectToAction("Details", new { Id = post.MapTo <PostReference>().DomainId }));
        }
コード例 #4
0
        public void WhenPostingNewPostWithPublishDateSpecified_AndThereIsNoLastPost_ScheduleItForSpecifiedDate()
        {
            var rescheduler = new PostSchedulingStrategy(Session, Now);

            var scheduleDate = Now.AddHours(1);
            var result       = rescheduler.Schedule(scheduleDate);

            Assert.Equal(scheduleDate, result);
        }
コード例 #5
0
        public void WhenPostingNewPostWithoutPublishDateSpecified_AndTheLastPostPublishDateIsAFewDaysAgo_ScheduleItForTomorrowAtNoot()
        {
            Session.Store(new Post {
                PublishAt = Now.AddDays(-3)
            });
            Session.SaveChanges();

            var rescheduler = new PostSchedulingStrategy(Session, Now);

            var result = rescheduler.Schedule();

            Assert.Equal(Now.AddDays(1).SkipToNextWorkDay().AtNoon(), result);
        }
コード例 #6
0
        public ActionResult Add(PostInput input)
        {
            if (!ModelState.IsValid)
            {
                return(View("Edit", input));
            }

            // Be able to record the user making the actual post
            var user = RavenSession.GetCurrentUser();

            // Create the post comments object and link between it and the post
            var comments = new PostComments
            {
                Comments = new List <PostComments.Comment>(),
                Spam     = new List <PostComments.Comment>()
            };

            RavenSession.Store(comments);

            // Create new post object
            var post = new Post
            {
                Tags               = TagsResolver.ResolveTagsInput(input.Tags),
                PublishAt          = input.PublishAt,
                AllowComments      = input.AllowComments,
                AuthorId           = user.Id,
                LastEditedByUserId = user.Id,
                LastEditedAt       = DateTimeOffset.Now,
                CommentsId         = comments.Id,
                ContentType        = input.ContentType,
                Body               = input.Body,
                CreatedAt          = DateTimeOffset.Now,
                Title              = input.Title,
            };

            if (post.PublishAt == DateTimeOffset.MinValue)
            {
                var postScheduleringStrategy = new PostSchedulingStrategy(RavenSession, DateTimeOffset.Now);
                post.PublishAt = postScheduleringStrategy.Schedule();
            }

            // Actually save the post now
            RavenSession.Store(post);
            comments.Post = new PostComments.PostReference
            {
                Id        = post.Id,
                PublishAt = post.PublishAt,
            };

            return(RedirectToAction("Details", new { id = post.Id.ToIntId() }));
        }
コード例 #7
0
        public void WhenPostingNewPostWithPublishDateSpecified_AndTheLastPostPublishDateIsAFewDaysAgo_ScheduleItForSpecifiedDate()
        {
            Session.Store(new Post {
                PublishAt = Now.AddDays(-3)
            });
            Session.SaveChanges();

            var rescheduler = new PostSchedulingStrategy(Session, Now);

            var scheduleDate = Now.AddHours(1);
            var result       = rescheduler.Schedule(scheduleDate);

            Assert.Equal(scheduleDate, result);
            Assert.NotEqual(scheduleDate.AddDays(-2), result);
        }
コード例 #8
0
        public void WhenPostingNewPost_DoNotReschedulePublishedPosts()
        {
            Session.Store(new Post {
                PublishAt = Now.AddDays(-3)
            });
            Session.Store(new Post {
                PublishAt = Now.AddHours(-1)
            });
            Session.SaveChanges();

            var rescheduler = new PostSchedulingStrategy(Session, Now);

            rescheduler.Schedule();

            Assert.Empty(Session.Query <Post>().Where(post => post.PublishAt > Now));
        }