public void TestIfCreatePageRedirectsToCorrectActionWithValidModel() { var articleToAdd = new ArticlesSaveViewModel() { Contetnt = "There are few artists in hip-hop who have ever truly matched their hype.", Title = "Nas, 'Illmatic' At 20", ImageUrl = "http://ebid.s3.amazonaws.com/upload_big/1/2/3/1405024178-12177-9126.jpg" }; this.controller .WithCallTo(c => c.Create(articleToAdd)) .ShouldRedirectTo <ArticlesController>(typeof(ArticlesController).GetMethod("Details")); }
public void TestIfCreatePageRedirectsToCorrectActionWithValidModel() { var articleToAdd = new ArticlesSaveViewModel() { Contetnt = "There are few artists in hip-hop who have ever truly matched their hype.", Title = "Nas, 'Illmatic' At 20", ImageUrl = "http://ebid.s3.amazonaws.com/upload_big/1/2/3/1405024178-12177-9126.jpg" }; this.controller .WithCallTo(c => c.Create(articleToAdd)) .ShouldRedirectTo<ArticlesController>(typeof(ArticlesController).GetMethod("Details")); }
public void TestIfrticleValidationByCreatingIsWorking() { var model = new ArticlesSaveViewModel { Contetnt = "Invalid", Title = "Inv", ImageUrl = "invalid" }; var context = new ValidationContext(model, null, null); var results = new List <ValidationResult>(); var isModelStateValid = Validator.TryValidateObject(model, context, results, true); Assert.IsTrue(results.Count == 3); }
public ActionResult Create() { var model = new ArticlesSaveViewModel { AtricleCategory = this.articleCategoriesService .AllArticleCategories() .Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }) }; return this.View(model); }
public ActionResult Create() { var model = new ArticlesSaveViewModel { AtricleCategory = this.articleCategoriesService .AllArticleCategories() .Select(x => new SelectListItem { Value = x.Id.ToString(), Text = x.Name }) }; return(this.View(model)); }
public void TestIfrticleValidationByCreatingIsWorking() { var model = new ArticlesSaveViewModel { Contetnt = "Invalid", Title = "Inv", ImageUrl = "invalid" }; var context = new ValidationContext(model, null, null); var results = new List<ValidationResult>(); var isModelStateValid = Validator.TryValidateObject(model, context, results, true); Assert.IsTrue(results.Count == 3); }
public ActionResult Create(ArticlesSaveViewModel model) { if (model != null && ModelState.IsValid) { model.Title = this.sanitizeService.Sanitize(model.Title); model.Contetnt = this.sanitizeService.Sanitize(model.Contetnt); var newArticle = AutoMapper.Mapper.Map<Article>(model); newArticle.UserId = this.CurrentUser.Id; var result = this.articlesService.AddArticle(newArticle); return this.RedirectToAction("Details", "Articles", new { area = "", id = result.Id }); } return this.View(model); }
public ActionResult Create(ArticlesSaveViewModel model) { if (model != null && ModelState.IsValid) { model.Title = this.sanitizeService.Sanitize(model.Title); model.Contetnt = this.sanitizeService.Sanitize(model.Contetnt); var newArticle = AutoMapper.Mapper.Map <Article>(model); newArticle.UserId = this.CurrentUser.Id; var result = this.articlesService.AddArticle(newArticle); return(this.RedirectToAction("Details", "Articles", new { area = "", id = result.Id })); } return(this.View(model)); }