public void EditChapter_Should_Edit_Chapter_Content_Or_Title()
        {
            //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",
            };

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

            var record = new ChapterEditModel
            {
                Author    = someUser.UserName,
                Content   = "Some new content",
                CreatedOn = chapter.CreatedOn,
                Id        = chapter.Id,
                StoryId   = story.Id,
                Title     = "New Title"
            };

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

            //act
            this.chapterService.EditChapter(record);

            //assert
            var result = this.Context.Chapters.ProjectTo <ChapterEditModel>().FirstOrDefault(x => x.Id == chapter.Id);

            result.Should().NotBeNull().And.Subject.Should().BeEquivalentTo(record);
        }
Exemplo n.º 2
0
        public void EditChapter(ChapterEditModel editModel)
        {
            var chapter = this.Context.Chapters.Find(editModel.Id);

            chapter.Content   = editModel.Content;
            chapter.Title     = editModel.Title;
            chapter.CreatedOn = editModel.CreatedOn;

            this.Context.Chapters.Update(chapter);
            this.Context.SaveChanges();
        }
        public void GetChapterToEditById_Should_Return_The_ChapterEditModel_By_Id()
        {
            //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 = "someUserId",
            };

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

            var record = new ChapterEditModel
            {
                Author    = someUser.UserName,
                Content   = chapter.Content,
                CreatedOn = chapter.CreatedOn,
                Id        = chapter.Id,
                StoryId   = story.Id,
                Title     = chapter.Title
            };

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

            //act
            int chapterId = chapter.Id;
            var result    = this.chapterService.GetChapterToEditById(chapterId);

            //assert
            result.Should().NotBeNull().And.Subject.Should().BeEquivalentTo(record);
        }
Exemplo n.º 4
0
        public IActionResult EditChapter(ChapterEditModel editModel)
        {
            if (!ModelState.IsValid)
            {
                this.ViewData[GlobalConstants.ChapterLength] = editModel.Content?.Length ?? 0;
                return(this.View(editModel));
            }

            this.ChapterService.EditChapter(editModel);

            return(RedirectToAction("Details", "Stories", new { id = editModel.StoryId }));
        }
        public void GetChapterToEdit_Return_ChapterEditModel_From_Id()
        {
            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        = "1",
                Content   = "content1",
                AuthorId  = user.Id,
                BookId    = book.Id,
                Title     = "title1",
                CreatedOn = DateTime.UtcNow
            };

            var chapterEditModel = new ChapterEditModel
            {
                Id        = chapter.Id,
                Author    = user.UserName,
                Content   = chapter.Content,
                CreatedOn = chapter.CreatedOn,
                BookId    = book.Id,
                Title     = chapter.Title
            };

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

            var result = this.chapterService.GetChapterToEdit(chapter.Id);

            result.Should().NotBeNull()
            .And.Subject.Should().Equals(chapterEditModel);
        }
Exemplo n.º 6
0
        public void EditChapter(ChapterEditModel model)
        {
            var chapter = this.Context.Chapters.Find(model.Id);

            chapter.Content   = model.Content;
            chapter.Title     = model.Title;
            chapter.CreatedOn = model.CreatedOn;

            var currentBook = this.Context.Books.First(x => x.Chapters.Contains(chapter));

            currentBook.LastEditedOn = DateTime.UtcNow;

            this.Context.Chapters.Update(chapter);
            this.Context.Books.Update(currentBook);
            this.Context.SaveChanges();
        }
        public void EditChapter_Should_Success()
        {
            var book = new Book()
            {
                Id       = "1",
                Summary  = "asd",
                Title    = "asdasd",
                AuthorId = "111"
            };

            var chapter = new Chapter()
            {
                Id        = "1",
                AuthorId  = "111",
                BookId    = book.Id,
                Title     = "123",
                Content   = "123",
                CreatedOn = DateTime.UtcNow
            };

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

            var chapterEditModel = new ChapterEditModel()
            {
                Id        = "1",
                Author    = "gosho",
                BookId    = book.Id,
                Content   = "newcontent",
                CreatedOn = DateTime.UtcNow,
                Title     = "newtitle"
            };

            this.chapterService.EditChapter(chapterEditModel);

            var result = this.Context.Chapters.Find("1");

            result.Should().NotBeNull()
            .And.Subject.As <Chapter>()
            .Title.Should().BeEquivalentTo(chapterEditModel.Title);
        }
        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>();
        }
Exemplo n.º 9
0
        public void EditChapter_Should_Return_Error_InvalidInput()
        {
            var chapter = new ChapterEditModel
            {
                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.EditChapter(chapter);

            result.Should()
            .BeOfType <ViewResult>()
            .Which.Model.Should()
            .BeOfType <ChapterEditModel>();
        }