public ActionResult AddArticle(AddArticleViewModel model)
        {
            if (ModelState.IsValid)
            {
                Subject subject = _repo.GetSubject(model.SubjectId);
                AppUser user = _repo.GetUser(User.Identity.GetUserId());
                model.Text = model.Text.Replace(Environment.NewLine, "<br />");

                Article article = new Article { Headline = model.Headline, Text = model.Text,
                    Subject = subject, User = user, Date = DateTime.Now};

                if (model.Image != null)
                {
                    article.ImageType = model.Image.ContentType;
                    article.ImageData = new byte[model.Image.ContentLength];
                    model.Image.InputStream.Read(article.ImageData, 0, model.Image.ContentLength);
                }

                _repo.AddArticle(article);
                _repo.SaveChanges();
                return RedirectToAction("EditContent", "Admin");
            }

            model.Articles = new SelectList(_repo.Subjects(), "Id", "Name");
            return View(model);
        }
        public void TestPostAddArticleValidModelNoImage()
        {
            //Arrange
            AddArticleViewModel viewModel = new AddArticleViewModel
            {
                Headline = "Fake Headline",
                Text = "Fake Text"
            };
            Mock<IContentRepository> mockRepo = new Mock<IContentRepository>();
            mockRepo.Setup(x => x.GetSubject(It.IsAny<int>())).Returns(new Subject());
            mockRepo.Setup(x => x.GetUser(It.IsAny<string>())).Returns(new AppUser());
            mockRepo.Setup(x => x.AddArticle(It.IsAny<Article>()));
            mockRepo.Setup(x => x.SaveChanges());
            ManageContentController target = new ManageContentController(mockRepo.Object);

            //Act
            RedirectToRouteResult result = target.AddArticle(viewModel) as RedirectToRouteResult;

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual("Admin", result.RouteValues["Controller"]);
            Assert.AreEqual("EditContent", result.RouteValues["Action"]);
            Assert.IsTrue(target.ModelState.IsValid);
        }