public void UpdateNoteTags_RemovingExistingNoteTags() { var options = SQLiteHelpers.CreateOptions(); // SEEDING using (var context = new NexusContext(options)) { context.Database.EnsureCreated(); // Creates the in-memory SQLite database var note = DataProvider.CreateNote().AssignNoteTags(DataProvider.GetAlphabeticalTags()); context.Notes.Add(note); context.SaveChanges(); } using (var context = new NexusContext(options)) { var repo = new NoteRepository(context); repo.UpdateNoteTags(1, new List <string>()); repo.UnitOfWork.SaveChanges(); } using (var context = new NexusContext(options)) { var note = context.Notes.Include(n => n.NoteTags).First(); Assert.False(note.NoteTags.Any()); } }
public void UpdateNoteTags_NoteHasTags_AddingNewANDExistingTag() { var options = SQLiteHelpers.CreateOptions(); using (var context = new NexusContext(options)) { context.Database.EnsureCreated(); context.Notes.Add(DataProvider.CreateNote().AssignNoteTags(DataProvider.GetAlphabeticalTags())); context.Tags.Add(new Tag() { Title = "D" }); context.SaveChanges(); } using (var context = new NexusContext(options)) { var repo = new NoteRepository(context); var note = repo.GetAll().First(); repo.UpdateNoteTags(note.Id, new List <string>() { "A", "B", "X", "D" }); repo.UnitOfWork.SaveChanges(); } using (var context = new NexusContext(options)) { var note = context.Notes.Include(n => n.NoteTags).ThenInclude(nt => nt.Tag).First(); Assert.True(note.NoteTags.Count == 4); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "A"); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "B"); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "X"); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "D"); int totalTagCount = context.Tags.Count(); Assert.True(totalTagCount == 5); } }
public void UpdateNoteTags_ModifyingExistingNoteTagsByAddingAndRemovingTags() { var options = SQLiteHelpers.CreateOptions(); // SEEDING using (var context = new NexusContext(options)) { context.Database.EnsureCreated(); // Creates the in-memory SQLite database var note = DataProvider.CreateNote().AssignNoteTags(DataProvider.GetAlphabeticalTags()); context.Notes.Add(note); context.SaveChanges(); } using (var context = new NexusContext(options)) { var repo = new NoteRepository(context); // Adding D, removing C repo.UpdateNoteTags(1, new [] { "A", "B", "D" }); repo.UnitOfWork.SaveChanges(); } using (var context = new NexusContext(options)) { var note = context.Notes.Include(n => n.NoteTags).ThenInclude(nt => nt.Tag).First(); var tagTitles = note.NoteTags.Select(nt => nt.Tag.Title).ToList(); Assert.Contains("A", tagTitles); Assert.Contains("B", tagTitles); Assert.Contains("D", tagTitles); Assert.DoesNotContain("C", tagTitles); } }
public void UpdateNoteTags_NoteHasTags_GivenTheSameNoteTagsToUpdateNotesTags() { var options = SQLiteHelpers.CreateOptions(); using (var context = new NexusContext(options)) { context.Database.EnsureCreated(); var note = DataProvider.CreateNote(); var tags = DataProvider.GetAlphabeticalTags(); note.AssignNoteTags(tags); context.Notes.Add(note); context.SaveChanges(); } using (var context = new NexusContext(options)) { var noteRepo = new NoteRepository(context); var note = noteRepo.GetAll().Single(); noteRepo.UpdateNoteTags(note.Id, DataProvider.GetAlphabeticalTags().Select(t => t.Title)); noteRepo.UnitOfWork.SaveChanges(); } using (var context = new NexusContext(options)) { var note = context.Notes.Include(n => n.NoteTags).ThenInclude(nt => nt.Tag).First(); Assert.Equal(3, note.NoteTags.Count); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "A"); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "B"); Assert.Contains(note.NoteTags, nt => nt.Tag.Title == "C"); } }