コード例 #1
0
        /// <summary>
        /// Creates a new Note.
        /// </summary>
        /// <param name="entityToCreate">Note domain object with the properties to map to an Notes table entity</param>
        public void Create(Note entityToCreate)
        {
            // get the last inserted Note ordering index
            var maxOrderingIndex = -1;
            var result = _unitOfWork.Load<NoteEntity>("Notes", n => n.PartitionKey == entityToCreate.Owner.RowKey).ToList();

            if (result.Any())
            {
                maxOrderingIndex = result.Max(n => n.OrderingIndex);
            }

            entityToCreate.PartitionKey = entityToCreate.Owner.RowKey;
            entityToCreate.RowKey = ShortGuid.NewGuid();
            entityToCreate.OrderingIndex = maxOrderingIndex + 1;
            entityToCreate.ContainerKeys = string.Format("{0}+{1}", entityToCreate.Container.PartitionKey, entityToCreate.Container.RowKey);

            var noteEntity = entityToCreate.MapToNoteEntity();
            _unitOfWork.Create(noteEntity, "Notes");

            // the User that creates the new Note is automatically add in the Note Shares list.
            var noteSharePartitionKey = string.Format("{0}+{1}", entityToCreate.PartitionKey, entityToCreate.RowKey);
            var noteShare = new NoteShareEntity(noteSharePartitionKey, entityToCreate.Owner.RowKey);
            _unitOfWork.Create(noteShare, "NoteShares");

            // store in the TaskListNotes an entity to indicate that the Note is in the containing TaskList.
            var taskListNoteEntityPartitionKey = string.Format("{0}+{1}", entityToCreate.Container.PartitionKey, entityToCreate.Container.RowKey);
            var taskListNoteEntityRowKey = string.Format("{0}+{1}", entityToCreate.PartitionKey, entityToCreate.RowKey);
            var taskListNoteEntity = new TaskListNoteEntity(taskListNoteEntityPartitionKey, taskListNoteEntityRowKey);
            _unitOfWork.Create(taskListNoteEntity, "TaskListNotes");
        }
コード例 #2
0
        public void Create(Note entityToCreate)
        {
            var note = entityToCreate.MapToNoteEntity();
            var maxIndex = _notes.Max(n => n.OrderingIndex);
            note.OrderingIndex = maxIndex + 1;
            var noteShare = new NoteShareEntity(entityToCreate.RowKey, entityToCreate.Owner.RowKey);

            _notes.Add(note);
            _noteShares.Add(noteShare);
        }
コード例 #3
0
 /// <summary>
 /// Share the Note with a User.
 /// </summary>
 /// <param name="note">The Note to be shared</param>
 /// <param name="userId">RowKey from the User</param>
 public void AddShare(Note note, string userId)
 {
     var sharePartitionKey = string.Format("{0}+{1}", note.PartitionKey, note.RowKey);
     var share = new NoteShareEntity(sharePartitionKey, userId);
     _unitOfWork.Create(share, "NoteShares");
 }
コード例 #4
0
        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());
        }