public void AddChapter_Should_AddChapter() { var chapter = new ChapterInputModel() { StoryId = 1, Author = "SomeAuthor", Content = null, CreatedOn = DateTime.UtcNow, Title = "SomeTitle" }; var chapterService = new Mock <IChapterService>(); var controller = new ChaptersController(chapterService.Object); var result = controller.AddChapter(chapter); int storyId = chapter.StoryId; string redirectActionName = "Details"; string controlerToRedirectTo = "Stories"; result.Should().BeOfType <RedirectToActionResult>().Which.ActionName.Should().Be(redirectActionName); result.Should().BeOfType <RedirectToActionResult>().Which.ControllerName.Should().Be(controlerToRedirectTo); result.Should().BeOfType <RedirectToActionResult>() .Which.RouteValues.Values.Count .Should().Be(1).And.Subject .Should().Be(storyId); }
public void AddChapter_Should_ReturnError_AddChapter() { var chapter = new ChapterInputModel() { StoryId = 1, Author = "SomeAuthor", Content = null, CreatedOn = DateTime.UtcNow, Title = "SomeTitle" }; var chapterService = new Mock <IChapterService>(); var controller = new ChaptersController(chapterService.Object); controller.ModelState.AddModelError("Content", "StringLength"); var result = controller.AddChapter(chapter); result.Should().BeOfType <ViewResult>().Which.Model.Should().BeOfType <ChapterInputModel>(); }