Esempio n. 1
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);
        }
Esempio n. 2
0
        ///Excluding Id, name, description for now
        public void SaveShouldChangePrimitiveProperties()
        {
            const string newSource           = "best source";
            const string newMainNoteContent  = "best main note content!";
            const bool   newEditorMode       = true;
            const bool   newShowSourceEditor = true;

            UserS.SeedPeshoAndGosho(this.context);
            var note = NoteS.SeedNoteToUser(UserS.PeshoId, this.context);

            var editInput = new NoteEdit
            {
                Id               = note.Id,
                EditorMode       = newEditorMode,
                MainNoteContent  = newMainNoteContent,
                ShowSourceEditor = newShowSourceEditor,
                Source           = newSource,
            };

            Action action = () => this.noteService.Save(editInput, UserS.PeshoUsername);

            action.Invoke();

            note.EditorMode.Should().Be(newEditorMode);
            note.Source.Should().Be(newSource);
            note.MainNoteContent.Should().Be(newMainNoteContent);
            note.ShowSourceEditor.Should().Be(newShowSourceEditor);
        }
Esempio n. 3
0
        [Test]///Checked
        public void AppliesDeletedChangeToExistingNotesShouldSoftDeleteThem()
        {
            UserS.SeedPeshoAndGosho(context);
            var video   = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId);
            var changes = new string[][]
            {
                new string[] { "1", "Deleted", "Not Used" },
                new string[] { "2", "Deleted", "Not Used" }
            };

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

            action.Invoke();

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

            var note1 = video.Notes.SingleOrDefault(x => x.Id == 1);
            var note2 = video.Notes.SingleOrDefault(x => x.Id == 2);

            note1.IsDeleted.Should().Be(true);
            note2.IsDeleted.Should().Be(true);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
 public override void Setup()
 {
     base.Setup();
     base.Setup();
     this.userService = new UserService(this.context);
     UserS.SeedPeshoAndGosho(this.context);
 }
Esempio n. 6
0
        [Test]///Checked
        public void SaveShouldChangeCompFieldsIfTheyAreNotNull()
        {
            const string newDescription    = "New Description";
            const string newName           = "NewName";
            const string newTargetLanguage = "New Target Language";
            const string newSourceLanguage = "New Source Language";

            UserS.SeedPeshoAndGosho(context);
            var comps    = CompS.SeedTwoCompsToUser(context, UserS.GoshoId);
            var usedComp = comps[0];
            var compSave = new ComparisonSave
            {
                Id             = usedComp.Id,
                Description    = newDescription,
                Name           = newName,
                TargetLanguage = newTargetLanguage,
                SourceLanguage = newSourceLanguage,
            };

            ChangeTrackerOperations.DetachAll(this.context);
            Action action = () => this.comparisonService.Save(compSave, UserS.GoshoUsername);

            action.Invoke();

            ///reataching the entity we want to monitor
            usedComp = context.Comparisons.SingleOrDefault(x => x.Id == usedComp.Id);

            usedComp.Description.Should().Be(newDescription);
            usedComp.Name.Should().Be(newName);
            usedComp.TargetLanguage.Should().Be(newTargetLanguage);
            usedComp.SourceLanguage.Should().Be(newSourceLanguage);
        }
Esempio n. 7
0
        [Test]///Checked
        public void AppliesSeekToChangesToExistingNotesCorrectly()
        {
            const int Note1NewSeekTo = 15;
            const int Note2NewSeekTo = 16;

            UserS.SeedPeshoAndGosho(context);
            var video   = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId);
            var changes = new string[][]
            {
                new string[] { "1", "SeekTo", Note1NewSeekTo.ToString() },
                new string[] { "2", "SeekTo", Note2NewSeekTo.ToString() }
            };

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

            action.Invoke();

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

            var note1 = video.Notes.SingleOrDefault(x => x.Id == 1);
            var note2 = video.Notes.SingleOrDefault(x => x.Id == 2);

            note1.SeekTo.Should().Be(Note1NewSeekTo);
            note2.SeekTo.Should().Be(Note2NewSeekTo);
        }
Esempio n. 8
0
        [Test]///Checked
        public void SaveShouldNotChangeCompFieldsIfTheyAreNull()
        {
            UserS.SeedPeshoAndGosho(context);
            var comps    = CompS.SeedTwoCompsToUser(context, UserS.GoshoId);
            var usedComp = comps[0];

            string initialDescription    = usedComp.Description;
            string initialName           = usedComp.Name;
            string initialTargetLanguage = usedComp.TargetLanguage;
            string initialSourceLanguage = usedComp.SourceLanguage;

            var compSave = new ComparisonSave
            {
                Id             = usedComp.Id,
                Description    = null,
                Name           = null,
                TargetLanguage = null,
                SourceLanguage = null,
            };

            ChangeTrackerOperations.DetachAll(this.context);
            Action action = () => this.comparisonService.Save(compSave, UserS.GoshoUsername);

            action.Invoke();

            usedComp = context.Comparisons.SingleOrDefault(x => x.Id == usedComp.Id);

            usedComp.Description.Should().Be(initialDescription);
            usedComp.Name.Should().Be(initialName);
            usedComp.TargetLanguage.Should().Be(initialTargetLanguage);
            usedComp.SourceLanguage.Should().Be(initialSourceLanguage);
        }
Esempio n. 9
0
        public void SaveShouldThrowIdLinesToBeUpdatedsIdsDoNoteBelongTheGivenNote()
        {
            const int NonExistantCodeLineId = 42;

            UserS.SeedPeshoAndGosho(this.context);
            var note      = NoteS.SeedNoteToUser(UserS.PeshoId, this.context);
            var codeLines = NoteS.SeedTwoCodeLinesToNote(note, this.context);

            var editInput = new NoteEdit
            {
                Id    = note.Id,
                Lines = new HashSet <CodeLineEdit>
                {
                    new CodeLineEdit
                    {
                        Id = codeLines[0].Id,
                    },
                    new CodeLineEdit
                    {
                        Id = NonExistantCodeLineId,
                    }
                }
            };

            Action action = () => this.noteService.Save(editInput, UserS.PeshoUsername);

            action.Should().Throw <AccessDenied>().WithMessage("The Lines you are trying to edit do not belong the Note you are editing!");
        }
Esempio n. 10
0
        [Test]///Checked
        public void GetVideoForEditShouldThrowIfVideoDoesNoteBelongToUser()
        {
            UserS.SeedPeshoAndGosho(context);
            var video = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId);
            Func <VideoCreate> function = () => this.videoService.GetVideoForEdit(video.Id, UserS.PeshoUsername);

            function.Should().Throw <AccessDenied>().WithMessage("You can note edit video that does not belong to you!");
        }
Esempio n. 11
0
        public void GetForEditShouldReturnTheCorrectData()
        {
            UserS.SeedPeshoAndGosho(this.context);
            var comps    = CompS.SeedTwoCompsToUser(this.context, UserS.GoshoId);
            var usedComp = comps[0];

            CompS.SeedThreeItemsToComp(this.context, usedComp);
        }
Esempio n. 12
0
        [Test]///Checked
        public void DeleteShouldThrowIfVideoDoesNoteBelongToUser()
        {
            UserS.SeedPeshoAndGosho(context);
            var    video  = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId);
            Action action = () => this.videoService.Delete(video.Id, UserS.PeshoUsername, DateTime.UtcNow);

            action.Should().Throw <AccessDenied>().WithMessage("The video you are trying to delete does not belong to you!");
        }
Esempio n. 13
0
        [Test]///Checked
        public void DeleteShouldThrowIfVideIsNotFound()
        {
            var nonExistantVideoId = 42;

            UserS.SeedPeshoAndGosho(context);
            Action action = () => this.videoService.Delete(nonExistantVideoId, UserS.GoshoUsername, DateTime.UtcNow);

            action.Should().Throw <ItemNotFound>().WithMessage("The video you are trying to delete does not exist!");
        }
Esempio n. 14
0
        [Test]///Checked
        public void GetVideoForEditShouldThrowIfVideoIsNotFound()
        {
            var nonExistantVideoId = 42;

            UserS.SeedPeshoAndGosho(context);
            Func <VideoCreate> function = () => this.videoService.GetVideoForEdit(nonExistantVideoId, UserS.GoshoUsername);

            function.Should().Throw <ItemNotFound>().WithMessage("The video you are trying to edit does not exist!");
        }
Esempio n. 15
0
        [Test]///Checked
        public void DeleteShouldThrowIfUserIsNotFound()
        {
            UserS.SeedPeshoAndGosho(context);
            var nonExistantUsername = "******";

            var    video  = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId);
            Action action = () => this.videoService.Delete(video.Id, nonExistantUsername, DateTime.UtcNow);

            action.Should().Throw <UserNotFound>();
        }
Esempio n. 16
0
        [Test]///Checked
        public void GetVideoForEditShouldThrowIfUserIsNotFound()
        {
            UserS.SeedPeshoAndGosho(context);
            var nonExistantUsername = "******";

            var video = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId);
            Func <VideoCreate> function = () => this.videoService.GetVideoForEdit(video.Id, nonExistantUsername);

            function.Should().Throw <UserNotFound>();
        }
Esempio n. 17
0
        [Test]///Checked
        public void SaveShouldThrowIfInvalidUsername()
        {
            UserS.SeedPeshoAndGosho(context);
            var invalidUsername = "******";

            ChangeTrackerOperations.DetachAll(this.context);
            Action action = () => this.comparisonService.Save(new ComparisonSave(), invalidUsername);

            action.Should().Throw <UserNotFound>();
        }
Esempio n. 18
0
        public void ShouldThrowIfVIdeoDoesNotBelogToUser()
        {
            UserS.SeedPeshoAndGosho(context);
            var video = VideoS.SeedVideosToUser(context, UserS.GoshoId);

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

            action.Should().Throw <AccessDenied>().WithMessage("The video you are trying to medify does not belong to you!");
        }
Esempio n. 19
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!");
        }
Esempio n. 20
0
        public void ShouldThrowIfNoteUserIdDoesNotMatchUserId()
        {
            UserS.SeedPeshoAndGosho(this.context);
            var    note   = NoteS.SeedNoteToUser(UserS.PeshoId, this.context);
            var    noteId = note.Id;
            Action action = () => this.noteService.Save(new NoteEdit {
                Id = noteId
            }, UserS.GoshoUsername);

            action.Should().Throw <AccessDenied>().WithMessage("The note you are trying to edit does not belong to you!");
        }
Esempio n. 21
0
        public void ShouldThrowIfUserNotFound()
        {
            const string NonExistantUsername = "******";

            UserS.SeedPeshoAndGosho(this.context);

            var    note   = NoteS.SeedNoteToUser(UserS.PeshoId, this.context);
            Action action = () => this.noteService.Save(new NoteEdit(), NonExistantUsername);

            action.Should().Throw <UserNotFound>();
        }
Esempio n. 22
0
        public void ShouldThrowIfNoteNotFound()
        {
            const int nonExistantNoteId = 42;

            UserS.SeedPeshoAndGosho(this.context);
            var    note   = NoteS.SeedNoteToUser(UserS.PeshoId, this.context);
            Action action = () => this.noteService.Save(new NoteEdit {
                Id = nonExistantNoteId
            }, UserS.GoshoUsername);

            action.Should().Throw <ItemNotFound>().WithMessage("The note you are trying to edit does not exist!");
        }
Esempio n. 23
0
        [Test]///Checked
        public void CreateThrowsIfUserDoesNotExist()
        {
            UserS.SeedPeshoAndGosho(context);

            int          ExistingDirecotryId = UserS.GoshoRootDirId;
            const string NonExistantUsername = "******";

            ChangeTrackerOperations.DetachAll(this.context);
            Action action = () => this.videoService.Create(ExistingDirecotryId, NonExistantUsername);

            action.Should().Throw <UserNotFound>();
        }
Esempio n. 24
0
        [Test]///Checked
        public void CreateThrowsIfDirectoryDoesNotBelongToUser()
        {
            UserS.SeedPeshoAndGosho(context);

            int    ExistingDirecotryId = UserS.GoshoRootDirId;
            string ExistingUsername    = UserS.PeshoUsername;

            ChangeTrackerOperations.DetachAll(this.context);
            Action action = () => this.videoService.Create(ExistingDirecotryId, ExistingUsername);

            action.Should().Throw <AccessDenied>().WithMessage("The directory you are trying to create a video on does note belong to you!");
        }
Esempio n. 25
0
        [Test]///Checked
        public void DeleteShouldSoftDeleteTheVideoAndAllItsNotes()
        {
            var now = DateTime.Now;

            UserS.SeedPeshoAndGosho(context);
            var    video  = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId, true);
            Action action = () => this.videoService.Delete(video.Id, UserS.GoshoUsername, now);

            action.Invoke();
            video.IsDeleted.Should().Be(true);
            video.DeletedOn.Should().Be(now);
            video.Notes.Select(x => x.IsDeleted).Should().AllBeEquivalentTo(true);
            video.Notes.Select(x => x.DeletedOn).Should().AllBeEquivalentTo(now);
        }
Esempio n. 26
0
        [Test]///Checked
        public void SaveShouldThrowIfCompDoesNotBelongToUser()
        {
            UserS.SeedPeshoAndGosho(context);
            var comps    = CompS.SeedTwoCompsToUser(context, UserS.GoshoId);
            var compSave = new ComparisonSave
            {
                Id = comps[0].Id,
            };

            ChangeTrackerOperations.DetachAll(this.context);
            Action action = () => this.comparisonService.Save(compSave, UserS.PeshoUsername);

            action.Should().Throw <AccessDenied>().WithMessage("The comparison does not belong to you!");
        }
Esempio n. 27
0
        [Test]///Checked
        public void CreateSetNewVidosOrderTo0WhenItIsTheFirstVideoInAdirectory()
        {
            ///Also seeds their root directories
            UserS.SeedPeshoAndGosho(context);
            int    ExistingDirecotryId = UserS.GoshoRootDirId;
            string ExistingUsername    = UserS.GoshoUsername;

            Func <int> funk    = () => this.videoService.Create(ExistingDirecotryId, ExistingUsername);
            var        videoId = funk.Invoke();

            var video = context.Videos.SingleOrDefault(x => x.Id == videoId);

            video.Order.Should().Be(0);
        }
Esempio n. 28
0
        public void ShouldNotChangeVideoFieldsIfTheyAreAllNull()
        {
            UserS.SeedPeshoAndGosho(context);
            var video = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId);

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

            action.Invoke();

            video.SeekTo.Should().Be(VideoS.DefaultVideoSeekTo);
            video.Name.Should().Be(VideoS.DefaultVideoName);
            video.Description.Should().Be(VideoS.DefaultVideoDesctiption);
            video.Url.Should().Be(VideoS.DefaultVideoUrl);
        }
Esempio n. 29
0
        [Test]///Checked
        public void SaveShouldThrowIfNonexistantComparison()
        {
            UserS.SeedPeshoAndGosho(context);
            CompS.SeedTwoCompsToUser(context, UserS.GoshoId);
            var invalidCompId = 42;
            var compSave      = new ComparisonSave
            {
                Id = invalidCompId,
            };

            ChangeTrackerOperations.DetachAll(this.context);
            Action action = () => this.comparisonService.Save(compSave, UserS.GoshoUsername);

            action.Should().Throw <ItemNotFound>().WithMessage("The comparison you are trying to modify does not exist!");
        }
Esempio n. 30
0
        [Test]///Checked
        public void GetViewShouldReturnCorrectView()
        {
            UserS.SeedPeshoAndGosho(context);
            var video              = VideoS.SeedVideosToUserWithNotes(context, UserS.PeshoId);
            var resultView         = this.videoService.GetView(video.Id);
            var expectedResultView = new VideoView
            {
                Description = video.Description,
                Name        = video.Name,
                Url         = video.Url,
                Notes       = video.Notes.Select(x => MapVideoNoteToView(x)).ToList()
            };

            resultView.Should().BeEquivalentTo(expectedResultView);
        }