[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); }
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); }
[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); }
[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); }
[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!"); }
[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!"); }
[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>(); }
[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>(); }
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!"); }
[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); }
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); }
[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); }
[Test]///Checked public void GetViewShouldReturnCorrectViewWithNestedNotes() { UserS.SeedPeshoAndGosho(context); var video = VideoS.SeedVideosToUserWithNotes(context, UserS.PeshoId, true); var resultView = this.videoService.GetView(video.Id); var expectedResultView = new VideoView { Description = video.Description, Name = video.Name, Url = video.Url, ///We ignore the notes that are also nested in parent notes Notes = video.Notes.Where(x => x.Note == null).Select(x => MapVideoNoteToView(x)).ToList() }; resultView.Should().BeEquivalentTo(expectedResultView); }
public void ShouldThrowIfIdsToChangeDoNotBelongToVideo() { UserS.SeedPeshoAndGosho(context); var video = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId); var changes = new string[][] { new string[] { "1", "some prop", "some val" }, new string[] { "2", "some prop", "some val" }, ///The existing values are 1 and 2, 3 is not in that video; new string[] { "3", "some prop", "some val" } }; ChangeTrackerOperations.DetachAll(this.context); Action action = GetPartialSaveAction(video.Id, UserS.GoshoUsername, changes); action.Should().Throw <AccessDenied>().WithMessage("The video notes you are trying to modify does not belong the the current video"); }
public void PartialSaveDoesNotRegisterModificationOfVideoIfItIsNotFinalSave() { UserS.SeedPeshoAndGosho(this.context); var video = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId); var videoLastModifiedOn = video.LastModifiedOn; var videoMidificationCount = video.TimesModified; ChangeTrackerOperations.DetachAll(this.context); Action action = this.GetPartialSaveAction(video.Id, UserS.GoshoUsername, false); action.Invoke(); var newVideoLastModifiedOn = video.LastModifiedOn; var newVideoMidificationCount = video.TimesModified; newVideoLastModifiedOn.Value.Should().Be(videoLastModifiedOn.Value); newVideoMidificationCount.Should().Be(videoMidificationCount); }
[Test]///Checked public void RegisterModificationWhenExistingItemsAreChanged() { const Formatting Note1NewFormatting = Formatting.SQL; const Formatting Note2NewFormatting = Formatting.None; UserS.SeedPeshoAndGosho(context); var video = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId); var note1 = video.Notes.SingleOrDefault(x => x.Id == VideoS.preExistingNote1Id); var note2 = video.Notes.SingleOrDefault(x => x.Id == VideoS.preExistingNote2Id); var intialModifedOnNote1 = note1.LastModifiedOn; var intialModifedOnNote2 = note2.LastModifiedOn; var initialTimesModifiedNote1 = note1.TimesModified; var initialTimesModifiedNote2 = note2.TimesModified; var changes = new string[][] { new string[] { VideoS.preExistingNote1Id.ToString(), "Formatting", ((int)Note1NewFormatting).ToString() }, new string[] { VideoS.preExistingNote2Id.ToString(), "Formatting", ((int)Note2NewFormatting).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); note1 = video.Notes.SingleOrDefault(x => x.Id == VideoS.preExistingNote1Id); note2 = video.Notes.SingleOrDefault(x => x.Id == VideoS.preExistingNote2Id); intialModifedOnNote1.Value.Should().BeBefore(note1.LastModifiedOn.Value); intialModifedOnNote2.Value.Should().BeBefore(note2.LastModifiedOn.Value); initialTimesModifiedNote1.Should().Be(note1.TimesModified - 1); initialTimesModifiedNote2.Should().Be(note2.TimesModified - 1); }
public void ShouldChangeVideoFieldsIfTheyAreProvided() { const int NewSeekTo = 20; const string NewName = "NewName"; const string NewDescription = "NewDescription"; const string NewUrl = "NewUrl"; UserS.SeedPeshoAndGosho(context); var video = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId); ChangeTrackerOperations.DetachAll(this.context); Action action = GetPartialSaveAction(video.Id, UserS.GoshoUsername, NewSeekTo, NewName, NewDescription, NewUrl); action.Invoke(); video = context.Videos .SingleOrDefault(x => x.Id == video.Id); video.SeekTo.Should().Be(NewSeekTo); video.Name.Should().Be(NewName); video.Description.Should().Be(NewDescription); video.Url.Should().Be(NewUrl); }
[Test]///Checked public void GetVideoForEditShouldReturnCorrectResult() { UserS.SeedPeshoAndGosho(context); var video = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId, true); Func <VideoCreate> function = () => this.videoService.GetVideoForEdit(video.Id, UserS.GoshoUsername); var result = function.Invoke(); var dbNote0 = video.Notes.SingleOrDefault(x => x.Order == 0); var dbNote1 = video.Notes.SingleOrDefault(x => x.Order == 1); var dbNote2 = video.Notes.SingleOrDefault(x => x.Order == 2); var pageNote0 = MapVideoNoteToNoteCreate(dbNote0); var pageNote1 = MapVideoNoteToNoteCreate(dbNote1); var pageNote2 = MapVideoNoteToNoteCreate(dbNote2); pageNote0.Level = 1; pageNote1.Level = 2; pageNote2.Level = 1; pageNote1.InPageParentId = pageNote0.InPageId; var expectedResult = new VideoCreate { Description = video.Description, DirectoryId = video.DirectoryId, Id = video.Id, Name = video.Name, Order = video.Order, SeekTo = video.SeekTo, Url = video.Url, Notes = new List <VideoNoteCreate> { pageNote0, pageNote1, pageNote2 } }; result.Should().BeEquivalentTo(expectedResult); }
[Test]///Cheked public void PartialSaveRegisterModificationOfVideoIfItIsFinalSave() { UserS.SeedPeshoAndGosho(this.context); var video = VideoS.SeedVideosToUserWithNotes(context, UserS.GoshoId); var videoLastModifiedOn = video.LastModifiedOn; var videoMidificationCount = video.TimesModified; ChangeTrackerOperations.DetachAll(this.context); Action action = this.GetPartialSaveAction(video.Id, UserS.GoshoUsername, true); action.Invoke(); video = context.Videos .Include(x => x.Notes) .SingleOrDefault(x => x.Id == video.Id); var newVideoLastModifiedOn = video.LastModifiedOn; var newVideoMidificationCount = video.TimesModified; newVideoLastModifiedOn.Value.Should().NotBe(videoLastModifiedOn.Value); newVideoMidificationCount.Should().Be(videoMidificationCount + 1); }