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);
        }
Beispiel #2
0
        public void AddChapter_Valid()
        {
            var chapter = new ChapterInputModel()
            {
                BookId    = "1",
                Author    = "usertest",
                CreatedOn = DateTime.UtcNow,
                Content   = null,
                Title     = "title"
            };

            var chapterService = new Mock <IChapterService>();

            var controller = new BookCreatorApp.Controllers.ChaptersController(chapterService.Object);

            var result = controller.AddChapter(chapter);

            string redirectToActionName = "Details";
            string redirectTo           = "Books";

            result.Should().BeOfType <RedirectToActionResult>().Which.ActionName.Should().Be(redirectToActionName);
            result.Should().BeOfType <RedirectToActionResult>().Which.ControllerName.Should().Be(redirectTo);
            result.Should().BeOfType <RedirectToActionResult>()
            .Which.RouteValues.Values.Count
            .Should().Be(1).And.Subject
            .Should().Be(1);
        }
Beispiel #3
0
        public IActionResult AddChapter(ChapterInputModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                this.ViewData[GlobalConstants.ChapterLength] = inputModel.Content?.Length ?? 0;
                this.ViewData[GlobalConstants.StoryId]       = inputModel.StoryId;
                return(this.View(inputModel));
            }

            this.ChapterService.AddChapter(inputModel);

            return(RedirectToAction("Details", "Stories", new { id = inputModel.StoryId }));
        }
        public void AddChapter_Should_Success()
        {
            var user = new BookCreatorUser
            {
                UserName = "******",
                Name     = "Gosho Ivanov"
            };

            this.userManager.CreateAsync(user).GetAwaiter();
            this.Context.SaveChanges();

            var book = new Book
            {
                Id       = "1",
                Summary  = "asd",
                Title    = "asdasd",
                AuthorId = user.Id
            };

            var chapter = new Chapter
            {
                Id        = "2",
                Content   = "content2",
                AuthorId  = user.Id,
                BookId    = book.Id,
                Title     = "title2",
                CreatedOn = DateTime.UtcNow
            };

            var chapterInputModel = new ChapterInputModel
            {
                Author    = user.UserName,
                BookId    = book.Id,
                Content   = "newnew",
                CreatedOn = DateTime.UtcNow,
                Title     = "newnewTitle"
            };

            this.Context.Chapters.Add(chapter);
            this.Context.Books.Add(book);
            this.Context.SaveChanges();

            var newChapterId = this.chapterService.AddChapter(chapterInputModel);

            var result = this.Context.Chapters.Find(newChapterId);

            result.Should().NotBeNull()
            .And.Subject.Should()
            .BeOfType <Chapter>();
        }
Beispiel #5
0
        public void AddChapter(ChapterInputModel inputModel)
        {
            var user    = this.UserManager.FindByNameAsync(inputModel.Author).GetAwaiter().GetResult();
            var chapter = Mapper.Map <Chapter>(inputModel);

            chapter.AuthorId = user.Id;
            var story = this.Context.FictionStories.Find(inputModel.StoryId);

            story.LastEditedOn = inputModel.CreatedOn;

            this.Context.FictionStories.Update(story);
            this.Context.Chapters.Add(chapter);
            this.Context.SaveChanges();

            this.NotificationService.AddNotification(inputModel.StoryId, inputModel.Author, story.Title);
        }
Beispiel #6
0
        public string AddChapter(ChapterInputModel model)
        {
            var currentUser = this.UserManager.FindByNameAsync(model.Author).GetAwaiter().GetResult();
            var chapter     = Mapper.Map <Chapter>(model);

            chapter.AuthorId = currentUser.Id;

            var book = this.Context.Books.Find(model.BookId);

            book.LastEditedOn = model.CreatedOn;

            this.Context.Books.Update(book);
            this.Context.Chapters.Add(chapter);
            this.Context.SaveChanges();

            this.notificationService.AddNotification(book.Id, currentUser.UserName, book.Title);

            return(chapter.Id);
        }
        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>();
        }
Beispiel #8
0
        public void AddChapter_Should_Return_Error_InvalidInput()
        {
            var chapter = new ChapterInputModel
            {
                BookId    = "1",
                Author    = "usertest",
                Content   = null,
                CreatedOn = DateTime.UtcNow,
                Title     = "title"
            };

            var chapterService = new Mock <IChapterService>();

            var controller = new BookCreatorApp.Controllers.ChaptersController(chapterService.Object);

            controller.ModelState.AddModelError("Content", "StringLength");

            var result = controller.AddChapter(chapter);

            result.Should()
            .BeOfType <ViewResult>()
            .Which.Model.Should()
            .BeOfType <ChapterInputModel>();
        }
        public void AddChapter_Should_Add_New_Chapter_To_Story()
        {
            //arrange

            var someUser = new FanFictionUser
            {
                Id       = "AnotherUserId",
                Nickname = "ThirdUser",
                UserName = "******",
            };

            var story = new FanFictionStory
            {
                Id       = 1,
                Author   = someUser,
                Summary  = "some summary",
                Title    = "Story To test",
                AuthorId = "AnotherUserId",
            };

            // for testing purposes first chapter is with id =1 or Ef throws exception when adding the new chapter
            // it get's set to 1 and gets a conflict,also datetime.UtcNow and datetime.Now again for testing purposes
            // to ensure we always get the last chapter and that they are  ordered in the correct way.So the test to have a point

            var chapter = new Chapter
            {
                Id                = 2,
                Content           = "SomeContent",
                AuthorId          = someUser.Id,
                FanFictionUser    = someUser,
                FanFictionStory   = story,
                FanFictionStoryId = story.Id,
                Title             = "Test Chapter",
                CreatedOn         = DateTime.UtcNow
            };

            var newchapter = new ChapterInputModel
            {
                Author    = someUser.UserName,
                Content   = "Some new content",
                CreatedOn = DateTime.Now,
                StoryId   = story.Id,
                Title     = "New chapter"
            };

            userManager.CreateAsync(someUser).GetAwaiter();
            this.Context.Chapters.Add(chapter);
            this.Context.FictionStories.Add(story);
            this.Context.SaveChanges();

            //act
            this.chapterService.AddChapter(newchapter);

            //assert

            var result = this.Context.Chapters.OrderBy(x => x.CreatedOn).Last(x => x.FanFictionStoryId == story.Id);

            result.Should().NotBeNull()
            .And.Subject.As <Chapter>()
            .Title.Should().BeSameAs(newchapter.Title);
        }