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); }
public async Task AddAsync(DocumentCollaboratorEntity collaborator) { using (var db = new DataContext()) { db.DocumentCollaborators.AddRange(new[] { collaborator }); await db.SaveChangesAsync(); } }
public async Task UpdateAsync(DocumentCollaboratorEntity collaborator) { using (var db = new DataContext()) { db.DocumentCollaborators.Attach(collaborator); db.Entry(collaborator).State = EntityState.Modified; await db.SaveChangesAsync(); } }
public async Task RemoveAsync(DocumentCollaboratorEntity document) { using (var db = new DataContext()) { var query = db.DocumentCollaborators .Where(p => p.DocumentId == document.DocumentId && p.ConnectionId == document.ConnectionId); db.DocumentCollaborators.RemoveRange(query); await db.SaveChangesAsync(); } }
public Task UpdateAsync(DocumentCollaboratorEntity collaborator) { return(_context.UpdateAsync(collaborator)); }
public Task RemoveAsync(DocumentCollaboratorEntity collaborator) { return(_context.RemoveAsync(collaborator)); }
public Task AddAsync(DocumentCollaboratorEntity collaborator) { return(_context.AddAsync(collaborator)); }