Esempio n. 1
0
        public void UpdateArticle_Test()
        {
            var dbArticles = new List <Article>();

            this._sut = new ArticleService(_fakeArticleUnitOfWork.Object, _mapper);

            CreateArticleDTO article = FakeArticles.CreateArticleWithTwoTagsDto();

            _fakeArticleRepository.Setup(m => m.Add(It.IsAny <Article>()))
            .Callback((Article a) => { dbArticles.Add(a); }).Verifiable();

            _fakeArticleUnitOfWork.Setup(setup => setup.Commit()).Returns(1).Verifiable();

            _fakeArticleRepository.Setup(setup => setup.Update(It.IsAny <Article>())).Callback((Article a) =>
            {
                dbArticles.Remove(a);
                dbArticles.Add(a);
            });

            _sut.AddArticle(article);

            GetArticleDTO getArticleDto = FakeArticles.CreateGetArticle();

            _sut.UpdateArticle(getArticleDto);

            Assert.AreEqual(dbArticles[0].Header, getArticleDto.Header);
        }
Esempio n. 2
0
        public IList <GetArticleDTO> GetArticles()
        {
            IList <Article>       articles    = _articleRepository.Table.ToList <Article>();
            IList <GetArticleDTO> articleList = new List <GetArticleDTO>();

            foreach (var article in articles)
            {
                GetArticleDTO articleDTO = new GetArticleDTO()
                {
                    id          = article.id,
                    teaser      = article.teaser,
                    headline    = article.headline,
                    subtitle    = article.subtitle,
                    byline      = article.byline,
                    lead        = article.lead,
                    content     = article.content,
                    credit      = article.credit,
                    authorId    = article.authorId,
                    AuthorName  = article.Author.name,
                    leadImage   = article.leadImage,
                    leadcaption = article.leadcaption,
                    leadcredit  = article.leadcredit,
                    date        = article.date,
                    createddate = article.createddate
                };
                articleList.Add(articleDTO);
            }


            return(articleList);
        }
Esempio n. 3
0
        public GetArticleDTO GetArticleById(int id)
        {
            Article       article    = _articleRepository.GetById(id);
            GetArticleDTO articleDTO = null;

            if (id != 0)
            {
                articleDTO = new GetArticleDTO()
                {
                    teaser      = article.teaser,
                    headline    = article.headline,
                    subtitle    = article.subtitle,
                    byline      = article.byline,
                    lead        = article.lead,
                    content     = article.content,
                    credit      = article.credit,
                    authorId    = article.authorId,
                    AuthorName  = article.Author.name,
                    leadImage   = article.leadImage,
                    leadcaption = article.leadcaption,
                    leadcredit  = article.leadcredit,
                    date        = article.date,
                    createddate = article.createddate,
                };
            }

            return(articleDTO);
        }
        // GET: Articles/Edit/5
        public ActionResult Edit(int id)
        {
            GetArticleDTO article             = _articlesService.GetArticleById(id);
            IEnumerable <GetAuthorDTO> author = _authorService.GetAuthors();

            ViewBag.authorid = new SelectList(author, "id", "name");

            return(View(article));
        }
        // GET: Articles/Delete/5
        public ActionResult Delete(int id)
        {
            GetArticleDTO article = _articlesService.GetArticleById(id);

            return(View(article));
        }
Esempio n. 6
0
        public void UpdateArticle(GetArticleDTO articleDto)
        {
            UnitOfWork.ArticleRepository.Update(Mapper.Map <GetArticleDTO, Article>(articleDto));

            UnitOfWork.Commit();
        }