public async void EditShouldReturnArticleModel() { mockArticleRepos.Setup(x => x.GetAsync(It.IsAny <int>())).ReturnsAsync(new Article() { Author = new User { FirstName = "publisher", LastName = "publisher" }, Likes = new List <Like>(), Id = 15, UserId = 5, Active = false, Published = DateTime.Now, Content = "Test", Title = "Test" }); var target = await controller.Edit(It.IsAny <int>()); var viewResult = Assert.IsType <ViewResult>(target); Assert.IsAssignableFrom <ArticleModel>(viewResult.ViewData.Model); }
public async Task <IActionResult> OnPostEdit() { if (!ModelState.IsValid) { return(Page()); } if (Image != null) { if (Path.GetExtension(Image.FileName).Equals(".png") || Path.GetExtension(Image.FileName).Equals(".jpeg") || Path.GetExtension(Image.FileName).Equals(".jpg") || Path.GetExtension(Image.FileName).Equals(".gif") || Path.GetExtension(Image.FileName).Equals(".bmp")) { BinaryReader reader = new BinaryReader(Image.OpenReadStream()); Article.Image = reader.ReadBytes((int)Image.Length); } } await _articleController.Edit(Article, User); return(RedirectToPage("/Article")); }