public void ChangingCategoryNameChangeNoteCategory()
        {
            // Arrange: We create the repo's mocks
            var noteMock = new Mock<INoteRepository>();
            var categoryMock = new Mock<ICategoryRepository>();

            var category = new Category("Dummy", "#123123123", "#123123123");

            categoryMock.Setup(rep => rep.FindAll()).Returns(new List<Category> { category });
            categoryMock.Setup(rep => rep.GetById(category.Id)).Returns(category);
            noteMock.Setup(rep => rep.FindAll()).Returns(new List<Note> { new Note("Note", category) });

            // Act: we create a viewModel's instance, a list with the new category changes and we send a mesage
            var viewModel = new MainViewModel(noteMock.Object, categoryMock.Object);

            category.Name = "Party";
            var categoryId = new List<Guid> { category.Id };
            var categoryEditorChanges = new CategoryEditorChangesMessage
            {
                CategoriesIds = categoryId
            };
            Messenger.Default.Send(categoryEditorChanges);

            // Assert: and the category and the note have the new name
            viewModel.Categories.First(c => c.Id == category.Id).Name.ShouldEqual("Party");
            viewModel.Notes.First(n => n.Content == "Note").Category.Name.ShouldEqual("Party");
        }
        public void DeletingACategoryWithItsNotes()
        {
            // Arrange: We create the repo's mocks
            var noteMock = new Mock<INoteRepository>();
            var categoryMock = new Mock<ICategoryRepository>();

            var category = new Category("Dummy", "#123123123", "#123123123");

            categoryMock.Setup(rep => rep.FindAll()).Returns(new List<Category> { category });
            noteMock.Setup(rep => rep.FindAll()).Returns(new List<Note> { new Note("Note", category) });

            // Act: we create a viewModel's instance, a list with the category to delete and we send a message
            var viewModel = new MainViewModel(noteMock.Object, categoryMock.Object);
            var notesToDelete = new List<Guid> { category.Id };
            var categoryEditorChanges = new CategoryEditorChangesMessage
            {
                NotesToDelete = notesToDelete
            };
            Messenger.Default.Send(categoryEditorChanges);

            // Assert: and the note is gone
            viewModel.Notes.Count.ShouldEqual(0);
        }
        public void DeletingACategoryWithoutNotes()
        {
            // Arrange: We create the repo's mocks
            var noteMock = new Mock<INoteRepository>();
            var categoryMock = new Mock<ICategoryRepository>();

            var category = new Category("Dummy", "#123123123", "#123123123");

            categoryMock.Setup(rep => rep.FindAll()).Returns(new List<Category> { category });
            noteMock.Setup(rep => rep.FindAll()).Returns(new List<Note> {new Note("Note", category)});

            // Act: we create a viewModel's instance, a list with the category to delete and we send a message
            var viewModel = new MainViewModel(noteMock.Object, categoryMock.Object);
            var notesToTrash = new List<Guid> {category.Id};
            var categoryEditorChanges = new CategoryEditorChangesMessage
                                            {
                                                NotesToTrash = notesToTrash
                                            };
            Messenger.Default.Send(categoryEditorChanges);

            // Assert: and the note's category should be trash
            viewModel.Notes.FirstOrDefault(n => n.Content == "Note").Category.Name.ShouldEqual("Trash");
        }
Exemple #4
0
 /// <summary>
 /// Takes the 3 lists with changes and makes the correct changes.
 /// </summary>
 /// <param name="lists">The list of lists :P.</param>
 private void MakingNewCatChanges(CategoryEditorChangesMessage changes)
 {
     UpdatingCatAndNotes(changes.CategoriesIds);
     if (changes.NotesToDelete.Count > 0)
         DeleteNotesWithoutCategory(changes.NotesToDelete);
     if (changes.NotesToTrash.Count > 0)
         MoveNotesToTrash(changes.NotesToTrash);
 }