public void NotesRepositoryAddShareCallsCreateFromTheUnitOfWork()
        {
            // Arrange
            var user = new User { PartitionKey = User1PartitionKey, RowKey = User1RowKey };
            var taskList = new TaskList("Test title", user) { PartitionKey = TaskList1PartitionKey, RowKey = _taskList1RowKey };
            var note = new Note("Test title", "Test content", user, taskList);
            note.Share.Add(user);

            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new NotesRepository(unitOfWorkMock.Object);

            // Act
            repository.AddShare(note, string.Format("{0}+{1}", User1PartitionKey, User1RowKey));

            // Assert
            unitOfWorkMock.Verify(uow => uow.Create(It.IsAny<NoteShareEntity>(), "NoteShares"), Times.Once());
        }
        public void NotesRepositoryCreateCallsCreateFromTheUnitOfWork()
        {
            // Arrange
            var user = new User { PartitionKey = User1PartitionKey, RowKey = User1RowKey };
            var taskList = new TaskList("Test title", user) { PartitionKey = TaskList1PartitionKey, RowKey = _taskList1RowKey };
            var note = new Note("Test title", "Test content", user, taskList);
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            unitOfWorkMock.Setup(u => u.Load("Notes", It.IsAny<Expression<Func<NoteEntity, bool>>>())).Returns(BuildNotesTable());
            var repository = new NotesRepository(unitOfWorkMock.Object);

            // Act
            repository.Create(note);

            // Assert
            Assert.IsTrue(note.PartitionKey != string.Empty);
            Assert.IsTrue(note.RowKey != string.Empty);
            unitOfWorkMock.Verify(uow => uow.Create(It.IsAny<NoteEntity>(), "Notes"), Times.Once());
            unitOfWorkMock.Verify(uow => uow.Create(It.IsAny<NoteShareEntity>(), "NoteShares"), Times.Once());
            unitOfWorkMock.Verify(uow => uow.Create(It.IsAny<TaskListNoteEntity>(), "TaskListNotes"), Times.Once());
        }
        public void NotesRepositoryDeleteCallsDeletesFromTheUnitOfWork()
        {
            // Arrange
            var user = new User { PartitionKey = User1PartitionKey, RowKey = User1RowKey };
            var taskList = new TaskList("Test title", user) { PartitionKey = TaskList1PartitionKey, RowKey = _taskList1RowKey };
            var note = new Note("Test title", "Test content", user, taskList) { PartitionKey = Note1PartitionKey, RowKey = _note1RowKey };
            var taskListNote = new TaskListEntity(string.Format("{0}+{1}", TaskList1PartitionKey, _taskList1RowKey), string.Format("{0}+{1}", Note1PartitionKey, _note1RowKey));

            var unitOfWorkMock = new Mock<IUnitOfWork>();
            unitOfWorkMock.Setup(uow => uow.Get("TaskListNotes", It.IsAny<Expression<Func<TaskListEntity, bool>>>())).Returns(taskListNote);
            unitOfWorkMock.Setup(uow => uow.Load<NoteShareEntity>(It.Is<string>(s => s == "NoteShares"))).Returns(BuildNoteSharesTable());
            var repository = new NotesRepository(unitOfWorkMock.Object);

            // Act
            repository.Delete(note);

            // Assert
            unitOfWorkMock.Verify(uow => uow.Delete<NoteEntity>("Notes", Note1PartitionKey, _note1RowKey), Times.Once());
            unitOfWorkMock.Verify(uow => uow.Delete<TaskListEntity>("TaskListNotes", taskListNote.PartitionKey, taskListNote.RowKey), Times.Once());
            unitOfWorkMock.Verify(uow => uow.Delete<NoteShareEntity>("NoteShares", string.Format("{0}+{1}", Note1PartitionKey, _note1RowKey), User1RowKey), Times.Once());
            unitOfWorkMock.Verify(uow => uow.Delete<NoteShareEntity>("NoteShares", string.Format("{0}+{1}", Note1PartitionKey, _note1RowKey), User3RowKey), Times.Once());
        }
        public void NotesRepositoryNoteWithTitleExistsCallsGetFromTheUnitOfWork()
        {
            // Arrange
            var user = new User { PartitionKey = User1PartitionKey, RowKey = User1RowKey };
            var taskList = new TaskList("Test title", user) { PartitionKey = User1RowKey, RowKey = _taskList1RowKey };
            var note = new Note("Test title", "Test content", user, taskList) { PartitionKey = Note1PartitionKey, RowKey = _note1RowKey };
            note.Share.Add(user);

            var unitOfWorkMock = new Mock<IUnitOfWork>();
            unitOfWorkMock.Setup(u => u.Get("Notes", It.IsAny<Expression<Func<Note, bool>>>())).Returns(note);
            var repository = new NotesRepository(unitOfWorkMock.Object);

            // Act
            var result = repository.NoteWithTitleExists("Test title", taskList);

            // Assert
            Assert.IsTrue(result);
            unitOfWorkMock.Verify(uow => uow.Get("Notes", It.IsAny<Expression<Func<Note, bool>>>()), Times.Once());
        }
        public void NotesRepositoryUpdateCallsUpdateFromTheUnitOfWork()
        {
            // Arrange
            var user = new User { PartitionKey = User1PartitionKey, RowKey = User1RowKey };
            var taskList = new TaskList("Test title", user) { PartitionKey = TaskList1PartitionKey, RowKey = _taskList1RowKey };
            var note = new Note("Test title", "Test content", user, taskList);
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new NotesRepository(unitOfWorkMock.Object);

            // Act
            repository.Update(note);

            // Assert
            unitOfWorkMock.Verify(uow => uow.Update("Notes", It.IsAny<NoteEntity>()), Times.Once());
        }
        public void NotesRepositoryLoadNotesCallsLoadAndGetsFromTheUnitOfWork()
        {
            // Arrange
            var user = new User { PartitionKey = User1PartitionKey, RowKey = User1RowKey };
            var taskList = new TaskList("Test title", user) { PartitionKey = User1RowKey, RowKey = _taskList1RowKey };
            var note = new Note("Test title", "Test content", user, taskList) { PartitionKey = Note1PartitionKey, RowKey = _note1RowKey };
            var noteEntity = new NoteEntity(Note1PartitionKey, _note1RowKey);
            note.Share.Add(user);

            var unitOfWorkMock = new Mock<IUnitOfWork>();
            unitOfWorkMock.Setup(u => u.Load("TaskListNotes", It.IsAny<Expression<Func<TaskListNoteEntity, bool>>>())).Returns(BuildTaskListNotesTable());
            unitOfWorkMock.Setup(u => u.Get("Notes", It.IsAny<Expression<Func<NoteEntity, bool>>>())).Returns(noteEntity);
            var repository = new NotesRepository(unitOfWorkMock.Object);

            // Act
            repository.LoadNotes(taskList);

            // Assert
            unitOfWorkMock.Verify(uow => uow.Load("TaskListNotes", It.IsAny<Expression<Func<TaskListNoteEntity, bool>>>()), Times.Once());
            unitOfWorkMock.Verify(uow => uow.Get("Notes", It.IsAny<Expression<Func<NoteEntity, bool>>>()), Times.Exactly(2));
        }
        public void NotesRepositoryLoadCallsLoadFromTheUnitOfWork()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            unitOfWorkMock.Setup(u => u.Load<NoteEntity>(It.Is<string>(s => s == "Notes"))).Returns(BuildNotesTable());
            var repository = new NotesRepository(unitOfWorkMock.Object);

            // Act
            var result = repository.Load().ToList();

            // Assert
            Assert.IsTrue(result.Count() == 2);
            unitOfWorkMock.Verify(uow => uow.Load<NoteEntity>("Notes"), Times.Once());
        }
        public void NotesRepositoryHasPermisionToEditCallsGetFromTheUnitOfWork()
        {
            // Arrange
            var user = new User { PartitionKey = User1PartitionKey, RowKey = User1RowKey };
            var taskList = new TaskList("Test title", user) { PartitionKey = TaskList1PartitionKey, RowKey = _taskList1RowKey };
            var note = new Note("Test title", "Test content", user, taskList) { PartitionKey = Note1PartitionKey, RowKey = _note1RowKey };
            var noteShare = new NoteShareEntity(string.Format("{0}+{1}", Note1PartitionKey, _note1RowKey), User1RowKey);
            note.Share.Add(user);

            var unitOfWorkMock = new Mock<IUnitOfWork>();
            unitOfWorkMock.Setup(u => u.Get("NoteShares", It.IsAny<Expression<Func<NoteShareEntity, bool>>>())).Returns(noteShare);
            var repository = new NotesRepository(unitOfWorkMock.Object);

            // Act
            var result = repository.HasPermissionToEdit(user, note);

            // Assert
            Assert.IsTrue(result);
            unitOfWorkMock.Verify(uow => uow.Get("NoteShares", It.IsAny<Expression<Func<NoteShareEntity, bool>>>()), Times.Once());
        }
        public void NotesRepositoryGetWihtFilterCallsGetFromTheUnitOfWorkAndReturnsAnExistingNote()
        {
            // Arrange
            var user = new User { PartitionKey = User1PartitionKey, RowKey = User1RowKey };
            var taskList = new TaskList("Test title", user) { PartitionKey = TaskList1PartitionKey, RowKey = _taskList1RowKey };
            var note = new Note("Test title", "Test content", user, taskList);
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            unitOfWorkMock.Setup(u => u.Get("Notes", It.IsAny<Expression<Func<Note, bool>>>())).Returns(note);
            var repository = new NotesRepository(unitOfWorkMock.Object);

            // Act
            var result = repository.Get(n => n.PartitionKey == Note1PartitionKey && n.RowKey == _note1RowKey);

            // Assert
            Assert.IsNotNull(result);
            unitOfWorkMock.Verify(uow => uow.Get("Notes", It.IsAny<Expression<Func<Note, bool>>>()), Times.Once());
        }
        public void NotesRepositoryGetCallsGetFromTheUnitOfWorkAndReturnsNullForANonExistingNote()
        {
            // Arrange
            var unitOfWorkMock = new Mock<IUnitOfWork>();
            var repository = new NotesRepository(unitOfWorkMock.Object);

            // Act
            var result = repository.Get(Note3PartitionKey, _note3RowKey);

            // Assert
            Assert.IsNull(result);
            unitOfWorkMock.Verify(uow => uow.Get("Notes", It.IsAny<Expression<Func<NoteEntity, bool>>>()), Times.Once());
        }