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 EditChapter_Should_Return_Not_Found() { var chapterService = new Mock <IChapterService>(); var controller = new ChaptersController(chapterService.Object); int id = 0; chapterService.Setup(x => x.GetChapterToEditById(id)).Returns(() => null); var result = controller.EditChapter(id); result.Should().BeOfType <NotFoundResult>(); }
public ChaptersControllerTest() { _fakeChapterList.Add(new Chapter { Id = 1 }); _fakeChapterList.Add(new Chapter { Id = 2 }); _fakeChapterListViewModel.Add(new ChapterViewModel { Id = 1 }); _fakeChapterListViewModel.Add(new ChapterViewModel { Id = 2 }); _mockRepo = new Mock <IChapterRepository>(); _mockController = new ChaptersController(_mockRepo.Object); }
public void EditChapter_Should_ReturnError_AddChapter() { var chapter = new ChapterEditModel { 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.EditChapter(chapter); result.Should().BeOfType <ViewResult>().Which.Model.Should().BeOfType <ChapterEditModel>(); }