Exemplo n.º 1
0
        public async Task Get_When_Called_Should_Return_OkObjectResult()
        {
            articleServiceMock.Setup(x => x.GetAllArticles()).Returns(MockData.TestArticlesMock());
            var result = await articleController.Get() as OkObjectResult;

            result.Should().BeOfType <OkObjectResult>().Which.StatusCode.Should().Be(200);
        }
Exemplo n.º 2
0
        public void Get_WhenCalled_ReturnsOkResult()
        {
            // Act
            var okResult = _controller.Get();

            // Assert
            Assert.IsType <OkObjectResult>(okResult.Result);
        }
Exemplo n.º 3
0
        public void Get_VerifyExisting()
        {
            var result = (ObjectResult)_articleController.Get(1);

            Assert.Equal(typeof(Article), result.Value.GetType());
            Assert.Equal("First", ((Article)result.Value).Title);

            result = (ObjectResult)_articleController.Get(3);
            Assert.Equal(typeof(Article), result.Value.GetType());
            Assert.Equal("Third", ((Article)result.Value).Title);

            result = (ObjectResult)_articleController.Get(5);
            Assert.Null(result.Value);
        }
Exemplo n.º 4
0
        public void Put()
        {
            int Id = 0;

            //Arrange
            using (var ctx = new JournalDbContext(DbOptions))
            {
                var controller = new ArticleController(new ArticleService(ctx), MapperConfig.Configure());

                //Act
                var result         = controller.Get();
                var okObjectResult = result as OkObjectResult;
                var model          = okObjectResult.Value as IEnumerable <ArticleModel>;

                Id = model.First().Id;

                controller.Put(model.First().Id, new ArticleModel
                {
                    Id    = model.First().Id,
                    Title = "Sudoku"
                });
            }

            //Assert
            using (var ctx = new JournalDbContext(DbOptions))
            {
                Assert.Equal(2, ctx.Articles.Count());
                Assert.Equal("Sudoku", ctx.Articles.Where(a => a.Id == Id).Single().Title);
            }
        }
Exemplo n.º 5
0
        public void RESTArticleGetByWrongId()
        {
            var controller = new ArticleController(_articleRepository, false);

            var result = controller.Get(40).Result;

            Assert.IsTrue(result is NotFoundResult);
        }
Exemplo n.º 6
0
        public async Task Get_Should_Return_Valid_ArticleResponse()
        {
            mockContext.Setup(it => it.GetByIdAsync <Article>(It.IsAny <int>(), It.IsAny <bool>(), It.IsAny <bool>())).
            Returns(Task.FromResult(new Article()
            {
                Id          = 1,
                Title       = "Title",
                Body        = "Body",
                IsPublished = false,
                PublishDate = null
            }));

            var response = await articleController.Get(1);

            var contentResult = response as OkNegotiatedContentResult <ArticleResponse>;

            Assert.AreEqual(1, contentResult.Content.Id);
        }
        protected void gvList_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            ArticleId = Convert.ToInt32(e.CommandArgument);
            ArticleInfo objArticle = ArticleController.Get(ArticleId);

            switch (e.CommandName)
            {
            case "Select":
                BindArticle(ArticleId);
                SetButtonStatus("Select");
                break;

            case "Copy":
                ArticleInfo objNewArticle = objArticle;
                objNewArticle.UserId = UserId;
                ArticleId            = ArticleController.Add(objNewArticle);
                BindArticleList();
                BindArticle(ArticleId);
                SetButtonStatus("Select");
                break;

            case "Del":
                ArticleController.Delete(ArticleId);
                ArticleId = -1;
                BindArticleList();
                break;

            case "Auth":
                ArticleController.UpdateAuthed(ArticleId, !objArticle.Authed);
                BindArticleList();
                break;

            case "Active":
                ArticleController.UpdateActive(ArticleId, !objArticle.Active);
                BindArticleList();
                break;

            case "Featured":
                ArticleController.UpdateFeatured(ArticleId, !objArticle.Featured);
                BindArticleList();
                break;

            case "Draft":
                ArticleController.UpdateDraft(ArticleId, !objArticle.Draft);
                BindArticleList();
                break;

            default:
                break;
            }
        }
Exemplo n.º 8
0
        public void RESTArticleGetAllValues()
        {
            var controller = new ArticleController(_articleRepository, false);

            var result   = controller.Get().Result;
            var okResult = result as OkObjectResult;
            var data     = okResult.Value as IEnumerable <article>;

            Assert.IsNotNull(data);

            var test2 = data.ToList();

            Assert.AreEqual(12, test2.Count);
        }
Exemplo n.º 9
0
        public void RESTArticleGetById()
        {
            var controller = new ArticleController(_articleRepository, false);

            var result   = controller.Get(1).Result;
            var okResult = result as OkObjectResult;
            var data     = okResult.Value as article;

            Assert.IsNotNull(data);
            Assert.AreEqual(1, data.id);
            Assert.AreEqual("Naissance du Coronavirus", data.title);
            Assert.AreEqual("Le coronavirus est une maladie qui est apparu en Chine dans la ville de Wuhan.", data.description);
            Assert.AreEqual("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce accumsan semper sodales. Fusce rhoncus, justo sed lacinia lacinia, sapien tellus dictum massa, ac viverra diam nibh non lacus. Sed tristique, eros ut fringilla sollicitudin, purus lacus facilisis orci, a euismod lectus elit sed nisi. Integer vestibulum erat vel metus consectetur auctor. Phasellus in suscipit sapien, nec rutrum dui. Maecenas tristique ornare velit, non dictum ante. Morbi interdum magna eu nulla cursus, non tincidunt odio mattis. Nam vehicula lectus ut eleifend luctus. Cras a ullamcorper lectus, ac cursus elit. Fusce nec ex risus. Morbi ipsum ligula, pulvinar ac laoreet sed, ultrices id ipsum. Duis blandit, augue vel pretium venenatis, velit sapien cursus nisl, a gravida lectus ex a dolor.", data.full_article);
            Assert.AreEqual(2, data.SourceId);
        }
        public void Should_Get_Article_By_Invalid_Id_Should_Fail()
        {
            #region Arrange

            var invalidArticleId          = 6;
            IArticleRepository repository = new ArticleRepository();
            IArticleService    service    = new ArticleService(repository);
            var controller = new ArticleController(service);

            #endregion

            #region Act

            controller.Get(invalidArticleId);

            #endregion

            // Assert by [ExpectedException] attr.
        }
Exemplo n.º 11
0
        public void Get()
        {
            using (var ctx = new JournalDbContext(DbOptions))
            {
                //Arrange
                var controller = new ArticleController(new ArticleService(ctx), MapperConfig.Configure());

                //Act
                var result = controller.Get();

                //Assert
                var okObjectResult = result as OkObjectResult;
                Assert.NotNull(okObjectResult);

                var model = okObjectResult.Value as IEnumerable <ArticleModel>;
                Assert.NotNull(model);

                Assert.Equal(2, model.Count());
            }
        }
Exemplo n.º 12
0
        public void Delete()
        {
            //Arrange
            using (var ctx = new JournalDbContext(DbOptions))
            {
                var controller = new ArticleController(new ArticleService(ctx), MapperConfig.Configure());

                //Act
                var result         = controller.Get();
                var okObjectResult = result as OkObjectResult;
                var model          = okObjectResult.Value as IEnumerable <ArticleModel>;

                controller.Delete(model.First().Id);
            }

            //Assert
            using (var ctx = new JournalDbContext(DbOptions))
            {
                Assert.Equal(1, ctx.Articles.Count());
            }
        }
        public void Should_Get_All_Articles_From_Store()
        {
            #region Arrange

            var numberOfArticles          = 5;
            IArticleRepository repository = new ArticleRepository();
            IArticleService    service    = new ArticleService(repository);
            var controller = new ArticleController(service);

            #endregion

            #region Act

            IEnumerable <Article> articles = controller.Get();

            #endregion

            #region Assert

            Assert.AreEqual(articles.Count(), numberOfArticles);

            #endregion
        }
Exemplo n.º 14
0
        public void Get_ReturnsAllArticles_ShouldSuccessed()
        {
            var result = _articleController.Get() as JsonResult;

            result.Value.Should().NotBeNull();
        }
        private void BindArticle(int articleId)
        {
            lblInvalidCategory.Visible = false;
            ArticleInfo objArticle = ArticleController.Get(articleId);

            if (objArticle == null)
            {
                return;
            }


            txtTitle.Text    = objArticle.Title;
            txtAuthor.Text   = objArticle.Author;
            txtSource.Text   = objArticle.Source;
            chkQuote.Checked = objArticle.Quote;
            txtPinOrder.Text = Convert.ToString(objArticle.PinOrder);
            chkDraft.Checked = objArticle.Draft;

            ctlLinkUrl.Url      = objArticle.LinkUrl;
            chkFeatured.Checked = objArticle.Featured;
            chkAuthed.Checked   = objArticle.Authed;
            chkActive.Checked   = objArticle.Active;

            //Image

            if (UserInfo.IsInRole(PortalSettings.AdministratorRoleName))
            {
                ctlImage.Url = objArticle.Image;
            }
            else
            {
                ctlUserImage.Url = objArticle.Image;
            }
            txtImageDescription.Text = objArticle.ImageDescription;
            RecursiveHelper.FillAspNetTreeCheckBox(ref tvCategory, objArticle.Categories, true);

            List <ArticleToTagInfo> tags = (from t in ArticleToTagController.ListByArticle(articleId) select t).ToList();

            txtTag1.Text  = tags.Count > 0 ? tags[0].Tag : "";
            txtTag2.Text  = tags.Count > 1 ? tags[1].Tag : "";
            txtTag3.Text  = tags.Count > 2 ? tags[2].Tag : "";
            txtTag4.Text  = tags.Count > 3 ? tags[3].Tag : "";
            txtTag5.Text  = tags.Count > 4 ? tags[4].Tag : "";
            txtTag6.Text  = tags.Count > 5 ? tags[5].Tag : "";
            txtTag7.Text  = tags.Count > 6 ? tags[6].Tag : "";
            txtTag8.Text  = tags.Count > 7 ? tags[7].Tag : "";
            txtTag9.Text  = tags.Count > 8 ? tags[8].Tag : "";
            txtTag10.Text = tags.Count > 9 ? tags[9].Tag : "";

            //Date
            if (!Null.IsNull(objArticle.PublishDate))
            {
                txtPublishDate.Text = objArticle.PublishDate.ToShortDateString();
            }
            if (!Null.IsNull(objArticle.ExpireDate))
            {
                txtExpireDate.Text = objArticle.ExpireDate.ToShortDateString();
            }

            cblViewRoles = Utils.FillRolesCheckBox(cblViewRoles, objArticle.ViewRoles, PortalSettings.AdministratorRoleId, PortalId);

            //rating
            chkAllowRating.Checked = objArticle.AllowRating;
            cblRatingRoles         = Utils.FillRolesCheckBox(cblRatingRoles, objArticle.RatingRoles, PortalSettings.AdministratorRoleId, PortalId);

            //Comment value
            chkAllowComment.Checked    = objArticle.AllowComment;
            chkAutoAuthComment.Checked = objArticle.AutoAuthComment;
            cblCommentRoles            = Utils.FillRolesCheckBox(cblCommentRoles, objArticle.CommentRoles, PortalSettings.AdministratorRoleId, PortalId);

            //
            chkAllowRecommend.Checked = objArticle.AllowRecommend;
            cblRecommendRoles         = Utils.FillRolesCheckBox(cblRecommendRoles, objArticle.RecommendRoles, PortalSettings.AdministratorRoleId, PortalId);

            cblDownloadRoles = Utils.FillRolesCheckBox(cblDownloadRoles, objArticle.DownloadRoles, PortalSettings.AdministratorRoleId, PortalId);



            txtSummary.Text = objArticle.Summary;
            txtDetail.Text  = Server.HtmlDecode(objArticle.Article);

            AttachmentList = new List <AttachmentInfo>();
            List <AttachmentInfo> aiList = AttachmentController.ListByArticle(articleId);

            for (int i = 0; i < aiList.Count; i++)
            {
                AttachmentInfo ai = new AttachmentInfo();
                ai.Id        = i;
                ai.ArticleId = articleId;
                ai.FilePath  = aiList[i].FilePath;
                AttachmentList.Add(ai);
            }

            gvAttachment.DataSource = AttachmentList;
            gvAttachment.DataBind();
        }