public void IncrementsPostCount()
 {
     var author = new UserAccount { Username = "******", EmailHash = "testhash" };
     var thread = new DiscussionThread("title", "body", "test,tags".Split(','), author);
     thread.PostCount.ShouldEqual(0);
     thread.AddPost("anotherUser");
     thread.PostCount.ShouldEqual(1);
     thread.LastActivity.ShouldBeWithinOneSecondFromNow();
     thread.LastActivityUsername.ShouldEqual("anotherUser");
 }
 public FubuContinuation NewThread(NewThreadCommand command)
 {
     var thread = new DiscussionThread(command.Title, command.Body, command.AllTagsEntered, command.Author);
     _session.Store(thread);
     _session.SaveChanges();
     return FubuContinuation.RedirectTo(new ViewThreadRequest
                                            {
                                                UriId = thread.UriId,
                                                Title = thread.Title
                                            });
 }
Пример #3
0
        public void ReturnsTop20ThreadSummaries()
        {
            var configStore = AutoMapperRegistry.BuildConfigStore();
            AutoMapperRegistry.ConfigureMaps(configStore);

            var endpoint = new HomeEndpoint(Session, new MappingEngine(configStore));
            var thread = new DiscussionThread("title", "body", new[] {"tag"}, new UserAccount());
            Session.Store(thread);
            Session.SaveChanges();

            var viewModel = endpoint.Home(new HomeRequest());
            viewModel.Threads.ShouldContain(x => x.Title == thread.Title);
        }
            public void IncrementsVoteCountAndRecalculatesTheScore()
            {
                var author = new UserAccount { Username = "******", EmailHash = "testhash" };
                var thread = new DiscussionThread("title", "body", "test,tags".Split(','), author);
                var originalScore = thread.Score;
                thread.UpVotes.ShouldEqual(1);
                thread.DownVotes.ShouldEqual(0);

                thread.VoteUp();
                thread.UpVotes.ShouldEqual(2);
                thread.DownVotes.ShouldEqual(0);
                thread.Score.ShouldBeGreaterThan(originalScore);

                thread.VoteDown();
                thread.UpVotes.ShouldEqual(2);
                thread.DownVotes.ShouldEqual(1);
                thread.Score.ShouldEqual(originalScore);

                thread.NetVotes.ShouldEqual(1);
            }
            public void InitializesPropertiesCorrectly()
            {
                var title = "New Thread";
                var body = "This is a body. And this is **really important**.";
                var author = new UserAccount { Username = "******", EmailHash = "testhash" };
                var thread = new DiscussionThread(title, body, "test,tags".Split(','), author);

                thread.Id.ShouldEqual("threads/");
                thread.Title.ShouldEqual(title);
                thread.MarkdownBody.ShouldEqual(body);
                thread.DisplayBody.ShouldEqual("<p>This is a body. And this is <strong>really important</strong>.</p>\n");
                thread.CreatedOn.ShouldBeWithinOneSecondFromNow();
                thread.LastActivity.ShouldBeWithinOneSecondFromNow();
                thread.UpVotes.ShouldEqual(1);
                thread.Score.ShouldBeGreaterThan(0);
                thread.Tags[0].ShouldEqual("test");
                thread.Tags[1].ShouldEqual("tags");
                thread.AuthorProfilePictureUrl.ShouldEqual(author.ProfilePictureUrl);
                thread.AuthorUsername.ShouldEqual(author.Username);
            }
        public void RecordsThreadViewIfNotViewedFromUserAndIPBefore()
        {
            var thread = new DiscussionThread("title", "body", new[] {"tags"}, DefaultUser);
            thread.ViewCount.ShouldEqual(0);
            Session.Store(thread);
            Session.SaveChanges();

            var request = new ViewThreadRequest
                              {
                                  IPAddress = "myIP",
                                  UriId = thread.UriId,
                                  UserAccount = DefaultUser
                              };
            var task = new RecordThreadViewTask(request);
            task.Initialize(Session, DocumentStore);
            task.Execute();
            Session.SaveChanges();

            var views = Session.Query<ThreadView>().Where(x => x.IPAddress == request.IPAddress && x.Username == DefaultUser.Username && x.DiscussionThreadId == thread.Id).ToList();
            views.Count().ShouldEqual(1);
            Session.Load<DiscussionThread>(thread.Id).ViewCount.ShouldEqual(1);
        }