Example #1
0
        public void GivenTagExistsInSearchRequest_WhenFeedIsRendered_HighlightsTagFeed()
        {
            // Arrange, setup our mock states
            var authenticatedState = new UserState(false, null, new ConduitUserDto {
                Username = "******"
            });
            var tagState     = new TagState(false, null, null);
            var articleState = new ArticleState(false, null, null, null, null, null, new ArticleSearchRequest(0, 0, null, null, "test"), 0);

            _mockUserState.Setup(s => s.Value).Returns(authenticatedState);
            _mockTagState.Setup(s => s.Value).Returns(tagState);
            _mockArticleState.Setup(s => s.Value).Returns(articleState);

            // Act
            var component   = RenderComponent <Client.Pages.Index>();
            var tagListItem = component.FindAll(".nav-item").Last();

            // Assert, verify the tag feed is active
            component.FindAll(".nav-item").Count.ShouldBe(3);

            // Assert the anchor tag is active
            tagListItem.FirstElementChild.ClassList.ShouldContain("active");

            // Assert the iconic pound sign is rendered
            tagListItem.FirstElementChild.FirstElementChild.ClassList.ShouldContain("ion-pound");

            // Assert the text is displayed in the anchor title
            tagListItem.FirstElementChild.LastElementChild.InnerHtml.ShouldContain(articleState.CurrentSearchRequest !.Tag);
        }
Example #2
0
        public static ArticleState ReduceSetCurrentCommitAction(ArticleState state, SetCurrentArticleCommitAction action)
        {
            var currentCommit = state.Commits.FirstOrDefault(c => c.Id == action.CommitId)
                                ?? state.Commits.FirstOrDefault(c => c.Id == state.CurrentArticle.CurrentCommitId);

            state.CurrentArticle.Content         = currentCommit.Content;
            state.CurrentArticle.CurrentCommitId = action.CommitId;
            return(new ArticleState(state.IsLoading, state.CurrentArticle, state.Commits));
        }
Example #3
0
 public ArticleSummary(ArticleState articleState)
 {
     Id           = articleState.Id;
     CreationDate = articleState.CreationDate;
     Title        = articleState.Title;
     Abstract     = articleState.Abstract;
     Tags         = articleState.Tags;
     Author       = articleState.Author;
     Image        = articleState.Image;
 }
 /// <summary>
 /// 修改稿件状态方法
 /// </summary>
 /// <param name="articleState">稿件状态实体</param>
 /// <returns>受影响的行数</returns>
 public static int UpdataArticele(ArticleState articleState)
 {
     DBHelper.DBVisit.ObjDBAccess.CommandStr = "update ArticleState set ArticleState_Name=@name where ArticleState_ID=@id";
     SqlParameter[] sqlPm = new SqlParameter[]   //参数列表
     {
         new SqlParameter("@name", articleState.Name),
         new SqlParameter("@id", articleState.Id)
     };
     DBHelper.DBVisit.ObjDBAccess.CmdParas.AddRange(sqlPm);
     return(DBHelper.DBVisit.ObjDBAccess.ExecuteUnSelectSqlCommand());  //调用DBhelp执行修改
 }
Example #5
0
        public static ArticleState ReduceAddCommentSuccessAction(ArticleState state, AddCommentSuccessAction action)
        {
            // Grab a reference to the current comment list, initialize if not available
            var currentComments = state.CurrentCommentList is null ?
                                  new List <CommentDto>() :
                                  state.CurrentCommentList.ToList();

            // Add and order by date if there are more than one comment
            currentComments.Add(action.Comment);
            currentComments = currentComments.OrderByDescending(c => c.CreatedAt).ToList();

            return(new ArticleState(false, null, state.CurrentArticle, state.IsFollowingUser, state.CurrentArticleList, currentComments, state.CurrentSearchRequest, state.TotalArticles));
        }
Example #6
0
 /// <summary>
 /// 作用:修改项目状态  成功返回ture 失败  返回false
 ///作者:汪建龙
 ///编写时间:2017年1月5日12:51:32
 /// </summary>
 /// <param name="id"></param>
 /// <param name="state"></param>
 /// <returns></returns>
 public bool Edit(int id, ArticleState state)
 {
     using (var db = GetDbContext())
     {
         var entry = db.Articles.Find(id);
         if (entry != null)
         {
             entry.State = state;
             db.SaveChanges();
             return(true);
         }
     }
     return(false);
 }
Example #7
0
        public static ArticleState ReduceDeleteCommentSuccessAction(ArticleState state, DeleteCommentSuccessAction action)
        {
            // In theory, this should never happen
            if (state.CurrentCommentList is null)
            {
                return(new ArticleState(false, null, state.CurrentArticle, state.IsFollowingUser, state.CurrentArticleList, null, state.CurrentSearchRequest, state.TotalArticles));
            }

            // Remove the comment and reorder the list
            var updatedCommentList = state.CurrentCommentList
                                     .Where(c => c.Id != action.Id)
                                     .OrderByDescending(c => c.CreatedAt);

            return(new ArticleState(false, null, state.CurrentArticle, state.IsFollowingUser, state.CurrentArticleList, updatedCommentList, state.CurrentSearchRequest, state.TotalArticles));
        }
Example #8
0
        public Article(string id, string title, string content, DateTime createDate, ArticleState state, string categoryId = null, IList <string> tags = null)
        {
            Assert.IsNotNullOrWhiteSpace("文章id", id);
            Assert.IsNotNullOrWhiteSpace("文章标题", title);
            Assert.IsNotNullOrWhiteSpace("文章内容", content);
            Assert.IsNotNull("文章创建日期", createDate);

            this.Id         = id;
            this.Title      = title;
            this.Content    = content;
            this.CategoryId = categoryId;
            this.Tags       = tags ?? new List <string>();
            this.State      = state;
            this.CreateDate = createDate;
        }
Example #9
0
 public static Article CreateArticle(int id, Guid uid, int articleTypeId, ArticleState state, int siteId, XElement content,
                                     int categoryId, DateTime date, IArticleRepository rep)
 {
     return(new Article
     {
         ArticleId = id,
         ArticleUid = uid,
         ArticleType = rep.FetchType(articleTypeId),
         State = state,
         SiteId = siteId,
         Content = content,
         CategoryId = categoryId,
         Date = date
     });
 }
        /// <summary>
        /// 根据ID找稿件状态
        /// </summary>
        /// <param name="id">要查找的图书状态</param>
        /// <returns>返回找到对象</returns>
        public static ArticleState GetArticleStateById(int id)
        {
            DBHelper.DBVisit.ObjDBAccess.CommandStr = "select ArticleState_Name,ArticleState_ID from ArticleState where ArticleState_ID=@id";  //SQL修改语句
            SqlParameter[] sqlPm = new SqlParameter[]
            {
                new SqlParameter("@id", id),
            };
            DBHelper.DBVisit.ObjDBAccess.CmdParas.AddRange(sqlPm);
            DataSet ds = DBHelper.DBVisit.ObjDBAccess.ExecuteSelectSqlCommand();

            ArticleState articleState = new ArticleState();                                    //创建一个对象

            articleState.Id   = int.Parse(ds.Tables[0].Rows[0]["ArticleState_ID"].ToString()); //给对象的属性赋值
            articleState.Name = ds.Tables[0].Rows[0]["ArticleState_Name"].ToString();
            return(articleState);
        }
Example #11
0
        public Article(string id, string title, string content, DateTime createDate, ArticleState state, string categoryId = null, IList <string> tags = null)
        {
            Assert.IsNotNullOrWhiteSpace("文章id", id);
            Assert.IsNotNullOrWhiteSpace("文章标题", title);
            Assert.IsNotNullOrWhiteSpace("文章内容", content);
            if (createDate <= new DateTime(2000, 1, 1))
            {
                throw new ArticleDomainException("文章创建时间不正确");
            }

            this.Id         = id;
            this.Title      = title;
            this.Content    = content;
            this.CategoryId = categoryId;
            this.Tags       = tags ?? new List <string>();
            this.State      = state;
            this.CreateDate = createDate;
        }
Example #12
0
        public void GivenInitialLoad_WhenUserIsNotAuthenticated_DisplaysGlobalFeed()
        {
            // Arrange, setup our mock states
            var unauthenticatedState = new UserState(false, null, null);
            var tagState             = new TagState(false, null, null);
            var articleState         = new ArticleState(false, null, null, null, null, null, null, 0);

            _mockUserState.Setup(s => s.Value).Returns(unauthenticatedState);
            _mockTagState.Setup(s => s.Value).Returns(tagState);
            _mockArticleState.Setup(s => s.Value).Returns(articleState);

            // Act
            var component = RenderComponent <Client.Pages.Index>();

            // Assert, verify only the global feed is rendered
            component.FindAll(".nav-item").Count.ShouldBe(1);
            component.Find(".nav-item").FirstElementChild.InnerHtml.ShouldBe("Global Feed");
        }
Example #13
0
        private void GenerateArticles()
        {
            ArticleState New()
            {
                List <Tuple <string, string> > GetTopics()
                {
                    var ret = new List <Tuple <string, string> > {
                        RandomGenerationData.TopicList[
                            RandomGenerationData.Random.Next(RandomGenerationData.TopicList.Count)]
                    };

                    return(ret);
                }

                var topic = GetTopics();
                var res   = new ArticleState {
                    Id           = Guid.NewGuid(),
                    CreationDate = DateTime.Now.AddHours(-RandomGenerationData.Random.Next(10000)),
                    Abstract     = RandomGenerationData.ExcerptsList[
                        RandomGenerationData.Random.Next(RandomGenerationData.ExcerptsList.Count)],
                    Content = RandomGenerationData.Contents[
                        RandomGenerationData.Random.Next(RandomGenerationData.Contents.Count)],
                    Image = new Uri(
                        RandomGenerationData.ImagesList[
                            RandomGenerationData.Random.Next(RandomGenerationData.ImagesList.Count)]),
                    Language  = RandomGenerationData.Random.Next(2) > 0 ? Language.English : Language.Mandarin,
                    Tags      = topic.Select(tuple => tuple.Item2).ToList(),
                    Catergory = RandomGenerationData.Random.Next(2) > 0
                        ? ArticleCategory.Science
                        : ArticleCategory.Technology,
                    Title = String.Format(
                        RandomGenerationData.TitleList[
                            RandomGenerationData.Random.Next(RandomGenerationData.TitleList.Count)],
                        topic.First().Item1),
                };

                return(res);
            }

            for (var i = 0; i < ArticlesNumber; i++)
            {
                Articles.AddLast(New());
            }
        }
Example #14
0
        public void GivenInitialPageLoad_WhenLifecycleIsInvoked_DispatchesActionsFromFacade()
        {
            // Arrange, setup our mock states
            var authenticatedState = new UserState(false, null, new ConduitUserDto {
                Username = "******"
            });
            var tagState     = new TagState(false, null, null);
            var articleState = new ArticleState(false, null, null, null, null, null, new ArticleSearchRequest(0, 0, null, null, "test"), 0);

            _mockUserState.Setup(s => s.Value).Returns(authenticatedState);
            _mockTagState.Setup(s => s.Value).Returns(tagState);
            _mockArticleState.Setup(s => s.Value).Returns(articleState);

            // Act
            var component = RenderComponent <Client.Pages.Index>();

            // Assert
            _mockFacade.Verify(m => m.GetArticles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), 10, 0), Times.Once);
            _mockFacade.Verify(m => m.LoadTags(), Times.Once);
        }
Example #15
0
        public async Task <IActionResult> PostState(int aid, ArticleState state)
        {
            var article = await _articleService.Get <ArticleDto>(a => a.Id == aid);

            if (!article.PublishTime.HasValue && state == ArticleState.Published)
            {
                await _articleService.Update <ArticleDto>(a => a.Id == aid, a => new ArticleDto {
                    State = state, PublishTime = DateTime.Now
                });
            }
            else
            {
                await _articleService.Update <ArticleDto>(a => a.Id == aid, a => new ArticleDto
                {
                    State = state
                });
            }

            return(Ok(new ResponseResult()));
        }
        private Task Broadcast <TTargetGrain>(ArticleState article) where TTargetGrain : IGrain
        {
            if (typeof(TTargetGrain) == typeof(ILocalLatestArticleAggregator))
            {
                return(GrainFactory.GetGrain <ILocalLatestArticleAggregator>(0).Aggregate(article));
            }

            if (typeof(TTargetGrain) == typeof(ILocalSearchArticleAggregator))
            {
                return(GrainFactory.GetGrain <ILocalSearchArticleAggregator>(0).Aggregate(article));
            }

            if (typeof(TTargetGrain) == typeof(ILocalLatestArticleByTagAggregator))
            {
                return(Task.WhenAll(article.Tags.Select(tag =>
                                                        GrainFactory.GetGrain <ILocalLatestArticleByTagAggregator>(tag).Aggregate(article))));
            }

            Console.WriteLine($"Unimplemented aggregator type : {typeof(TTargetGrain).Name}");
            return(Task.CompletedTask);
        }
Example #17
0
        public void GivenPopulatedTagsInState_WhenIsClicked_DispatchesGetArticlesActionFromFacade()
        {
            // Arrange, setup our mock states
            var authenticatedState = new UserState(false, null, new ConduitUserDto {
                Username = "******"
            });
            var tagState     = new TagState(false, null, new[] { "test" });
            var articleState = new ArticleState(false, null, null, null, null, null, null, 0);

            _mockUserState.Setup(s => s.Value).Returns(authenticatedState);
            _mockTagState.Setup(s => s.Value).Returns(tagState);
            _mockArticleState.Setup(s => s.Value).Returns(articleState);

            // Act
            var component = RenderComponent <Client.Pages.Index>();

            component.Find(".tag-pill.tag-default").Click();

            // Assert, will be call on page initialization and on tag click
            _mockFacade.Verify(m => m.GetArticles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), 10, 0), Times.Exactly(2));
            _mockFacade.Verify(m => m.GetArticles(tagState.Tags.First(), It.IsAny <string>(), It.IsAny <string>(), 10, 0), Times.Once);
        }
Example #18
0
        public void GivenInitialLoad_WhenUserAuthenticated_DisplaysFeedsAndHighlightsGlobal()
        {
            // Arrange, setup our mock states
            var authenticatedState = new UserState(false, null, new ConduitUserDto {
                Username = "******"
            });
            var tagState     = new TagState(false, null, null);
            var articleState = new ArticleState(false, null, null, null, null, null, null, 0);

            _mockUserState.Setup(s => s.Value).Returns(authenticatedState);
            _mockTagState.Setup(s => s.Value).Returns(tagState);
            _mockArticleState.Setup(s => s.Value).Returns(articleState);

            // Act
            var component = RenderComponent <Client.Pages.Index>();

            // Assert
            component.FindAll(".nav-item").Count.ShouldBe(2);
            component.FindAll(".nav-item").First().FirstElementChild.InnerHtml.ShouldBe("Your Feed");
            component.FindAll(".nav-item").Last().FirstElementChild.InnerHtml.ShouldBe("Global Feed");
            component.FindAll(".nav-item").Last().LastElementChild.ClassList.ShouldContain("active");
        }
Example #19
0
        public void GivenPopulatedTagsInState_WhenPageIsRendered_DisplaysTagList()
        {
            // Arrange, setup our mock states
            var authenticatedState = new UserState(false, null, new ConduitUserDto {
                Username = "******"
            });
            var tagState     = new TagState(false, null, new[] { "test" });
            var articleState = new ArticleState(false, null, null, null, null, null, null, 0);

            _mockUserState.Setup(s => s.Value).Returns(authenticatedState);
            _mockTagState.Setup(s => s.Value).Returns(tagState);
            _mockArticleState.Setup(s => s.Value).Returns(articleState);

            // Act
            var component = RenderComponent <Client.Pages.Index>();

            // Assert
            component.Find(".sidebar").ShouldNotBeNull();
            component.Find(".sidebar").ChildElementCount.ShouldBe(2);
            component.Find(".tag-list").ChildElementCount.ShouldBe(1);
            component.Find(".tag-pill.tag-default").InnerHtml.ShouldBe(tagState.Tags.First());
        }
Example #20
0
        public void GivenComponentIsLoaded_WhenUserClicksFeed_HighlightsUserFeed()
        {
            // Arrange, setup our mock states
            var authenticatedState = new UserState(false, null, new ConduitUserDto {
                Username = "******"
            });
            var tagState     = new TagState(false, null, null);
            var articleState = new ArticleState(false, null, null, null, null, null, null, 0);

            _mockUserState.Setup(s => s.Value).Returns(authenticatedState);
            _mockTagState.Setup(s => s.Value).Returns(tagState);
            _mockArticleState.Setup(s => s.Value).Returns(articleState);

            // Act, render the component and invoke the @onclick handler for the user feed
            var component = RenderComponent <Client.Pages.Index>();

            component.FindAll(".nav-link").First().ClassList.ShouldNotContain("active");
            component.FindAll(".nav-link").First().Click();

            // Assert, verify Your Feed is active
            component.FindAll(".nav-link").First().InnerHtml.ShouldBe("Your Feed");
            component.FindAll(".nav-link").First().ClassList.ShouldContain("active");
        }
Example #21
0
 public static ArticleState ReduceDeleteArticleSuccessAction(ArticleState state, DeleteArticleSuccessAction _) =>
 new ArticleState(false, null, null, state.IsFollowingUser, state.CurrentArticleList, null, state.CurrentSearchRequest, state.TotalArticles);
Example #22
0
 // a.State == ArticleState.???
 private Expression MakeArticleState(ParameterExpression par, ArticleState state)
 {
     return(Expression.Equal(
                Expression.MakeMemberAccess(par, _articleState),
                Expression.Constant(state, typeof(ArticleState))));
 }
Example #23
0
 public static ArticleState ReduceLoadCommentsAction(ArticleState state, LoadCommentsAction _) =>
 new ArticleState(true, null, state.CurrentArticle, state.IsFollowingUser, state.CurrentArticleList, null, state.CurrentSearchRequest, state.TotalArticles);
 public static ArticleState ReduceUnfollowUserFromArticleSuccessAction(ArticleState state, UnfollowUserFromArticleSuccessAction _) =>
 new ArticleState(false, null, state.CurrentArticle, false, state.CurrentArticleList, state.CurrentCommentList, state.CurrentSearchRequest, state.TotalArticles);
 public Task Aggregate(ArticleState article) => Task.WhenAll(
     Broadcast <ILocalLatestArticleAggregator>(article),
     Broadcast <ILocalLatestArticleByTagAggregator>(article),
     Broadcast <ILocalSearchArticleAggregator>(article));
 public static ArticleState ReduceUnfavoritePostFromArticle(ArticleState state, UnfavoritePostFromArticleAction _) =>
 new ArticleState(true, null, state.CurrentArticle, state.IsFollowingUser, state.CurrentArticleList, state.CurrentCommentList, state.CurrentSearchRequest, state.TotalArticles);
 public static ArticleState ReduceUnfavoritePostFromSuccessArticle(ArticleState state, UnfavoritePostFromArticleSuccessAction action) =>
 new ArticleState(false, null, action.Article, state.IsFollowingUser, state.CurrentArticleList, state.CurrentCommentList, state.CurrentSearchRequest, state.TotalArticles);
 public static ArticleState ReduceUnfavoritePostFromFailureArticle(ArticleState state, UnfavoritePostFromArticleFailureAction action) =>
 new ArticleState(false, action.Errors, state.CurrentArticle, state.IsFollowingUser, state.CurrentArticleList, state.CurrentCommentList, state.CurrentSearchRequest, state.TotalArticles);
Example #29
0
 public static ArticleState ReduceDeleteArticleFailureAction(ArticleState state, DeleteArticleFailureAction action) =>
 new ArticleState(false, action.Errors, state.CurrentArticle, state.IsFollowingUser, state.CurrentArticleList, state.CurrentCommentList, state.CurrentSearchRequest, state.TotalArticles);
Example #30
0
 public static ArticleState ReduceGetArticlesSuccessAction(ArticleState state, GetArticlesSuccessAction action) =>
 new ArticleState(false, null, state.CurrentArticle, state.IsFollowingUser, action.Articles, state.CurrentCommentList, state.CurrentSearchRequest, action.Count);