Exemple #1
0
        public async Task RemoveCollaboratorTest()
        {
            var collaborator = new DocumentCollaborator
            {
                Id            = 1,
                UserId        = "userId",
                DocumentId    = "documentId",
                CaretPosition = 2,
                ConnectionId  = "3"
            };

            DocumentCollaboratorEntity removedEntity = null;

            var collaboratorRepositoryMock = new Mock <IDocumentCollaboratorRepository>();

            collaboratorRepositoryMock.Setup(p => p.RemoveAsync(It.IsAny <DocumentCollaboratorEntity>()))
            .Callback((DocumentCollaboratorEntity entity) => { removedEntity = entity; })
            .Returns(() => Task.FromResult(0));

            var collaboratorService = new DocumentCollaboratorService(collaboratorRepositoryMock.Object, MockObjects.GetMapper());

            await collaboratorService.RemoveAsync(collaborator);

            Assert.NotNull(removedEntity);
            Assert.Equal(collaborator.Id, removedEntity.Id);
            Assert.Equal(collaborator.CaretPosition, removedEntity.CaretPosition);
            Assert.Equal(collaborator.ConnectionId, removedEntity.ConnectionId);
            Assert.Equal(collaborator.DocumentId, removedEntity.DocumentId);
            Assert.Equal(collaborator.UserId, removedEntity.UserId);

            collaboratorRepositoryMock.Verify(p => p.RemoveAsync(It.IsAny <DocumentCollaboratorEntity>()), Times.Once);
        }
Exemple #2
0
        /// <summary>
        ///     Notifies group members about new caret position.
        /// </summary>
        /// <param name="documentId">Document identifier.</param>
        /// <param name="caretPosition">Caret position.</param>
        public Task SetCaret(string documentId, int?caretPosition)
        {
            var userId = Context.User.Identity.Name;

            var collaborator = new DocumentCollaborator
            {
                DocumentId    = documentId,
                ConnectionId  = Context.ConnectionId,
                UserId        = userId,
                CaretPosition = caretPosition
            };

            Clients.OthersInGroup(documentId).caretPosition(collaborator);

            return(_collaboratorService.UpdateAsync(collaborator));
        }
Exemple #3
0
        /// <summary>
        ///     Removes a document collaborator.
        /// </summary>
        /// <param name="documentId">Document identifier.</param>
        public async Task LeaveDocument(string documentId)
        {
            // Leave group and notify collaborators
            var connectionId = Context.ConnectionId;

            await Groups.Remove(connectionId, documentId);

            var collaborator = new DocumentCollaborator
            {
                DocumentId   = documentId,
                ConnectionId = connectionId
            };

            await _collaboratorService.RemoveAsync(collaborator);

            Clients.Group(documentId).removeCollaborator(collaborator);
        }
Exemple #4
0
        /// <summary>
        ///     Adds a new document collaborator.
        /// </summary>
        /// <param name="documentId">Document identifier.</param>
        public async Task JoinDocument(string documentId)
        {
            // Join group and notify collaborators
            var userId       = Context.User.Identity.Name;
            var connectionId = Context.ConnectionId;

            await Groups.Add(connectionId, documentId);

            var collaborator = new DocumentCollaborator
            {
                DocumentId   = documentId,
                ConnectionId = connectionId,
                UserId       = userId
            };

            Clients.Group(documentId).addCollaborator(collaborator);

            await _collaboratorService.AddAsync(collaborator);
        }
Exemple #5
0
        public Task RemoveAsync(DocumentCollaborator collaborator)
        {
            var entity = _mapper.Map<DocumentCollaborator, DocumentCollaboratorEntity>(collaborator);

            return _collaboratorsRepository.RemoveAsync(entity);
        }