Пример #1
0
        public void CreateNewItemsReturnsTheRightIdsToUpdateThePageEntries()
        {
            UserS.SeedPeshoAndGosho(this.context);
            var video    = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId);
            var newNotes = VideoS.GenerateNoteCreateSimpleNested(VideoS.preExistingNote1Id);

            ChangeTrackerOperations.DetachAll(this.context);
            Func <int[][]> function = this.GetPartialSaveFunction(video.Id, UserS.GoshoUsername, newNotes);
            var            result   = function.Invoke();

            ///This means everything is ok
            result[0][0].Should().Be(0);

            var separatedResult = result.Skip(1).ToList();

            var newNote1DbId = context.VideoNotes.Where(x => x.Content == VideoS.Note1Content).SingleOrDefault().Id;
            var newNote2DbId = context.VideoNotes.Where(x => x.Content == VideoS.Note2Content).SingleOrDefault().Id;
            var newNote3DbId = context.VideoNotes.Where(x => x.Content == VideoS.Note3Content).SingleOrDefault().Id;

            var expectedOutcome = new List <int[]>
            {
                new int[] { VideoS.Note1InPageId, newNote1DbId },
                new int[] { VideoS.Note2InPageId, newNote2DbId },
                new int[] { VideoS.Note3InPageId, newNote3DbId },
            };

            for (int i = 0; i < expectedOutcome.Count; i++)
            {
                var pair = expectedOutcome[i];
                separatedResult.Should().Contain(x => x[0] == pair[0] && x[1] == pair[1]);
                var ind = separatedResult.FindIndex(x => x[0] == pair[0] && x[1] == pair[1]);
                separatedResult.RemoveAt(ind);
            }
            separatedResult.Should().HaveCount(0);
        }
Пример #2
0
        [Test]///Checked
        public void ShoudCreate3nestedNotesStartingAtRootCorrectly()
        {
            UserS.SeedPeshoAndGosho(this.context);
            var video    = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId);
            var newNotes = VideoS.GenerateNoteCreateSimpleNested(null);

            ChangeTrackerOperations.DetachAll(this.context);
            Action action = GetPartialSaveAction(video.Id, UserS.GoshoUsername, newNotes);

            action.Invoke();

            video = context.Videos
                    .Include(x => x.Notes)
                    .SingleOrDefault(x => x.Id == video.Id);

            var level1Note = video.Notes.SingleOrDefault(x => x.Content == "NestedLevel1");

            level1Note.Note.Should().BeNull();
            level1Note.ChildNotes.Count.Should().Be(1);

            var level2Note = level1Note.ChildNotes.SingleOrDefault();

            level2Note.Content.Should().Be("NestedLevel2");
            level2Note.ChildNotes.Count.Should().Be(1);

            var level3Note = level2Note.ChildNotes.SingleOrDefault();

            level3Note.Content.Should().Be("NestedLevel3");
            level3Note.ChildNotes.Count.Should().Be(0);

            video.Notes.Count.Should().Be(5);
        }
Пример #3
0
        public void IfTheNestingLevelIsGreaterThan4Throw()
        {
            UserS.SeedPeshoAndGosho(this.context);
            var video    = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId);
            var newNotes = VideoS.GenerateNoteCreateSimpleNested(VideoS.preExistingNote1Id, 4);

            ChangeTrackerOperations.DetachAll(this.context);
            Action action = this.GetPartialSaveAction(video.Id, UserS.GoshoUsername, newNotes);

            action.Should().Throw <BadRequestError>().WithMessage("The notes you are trying to save are nested deeper the four levels!");
        }