Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions source/backend/api/Services/DocumentQueueService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public async Task<PimsDocumentQueue> Update(PimsDocumentQueue documentQueue)

this.User.ThrowIfNotAuthorizedOrServiceAccount(Permissions.SystemAdmin, this._keycloakOptions);

await _documentQueueRepository.Update(documentQueue);
await _documentQueueRepository.UpdateAsync(documentQueue);

return documentQueue;
}
Expand Down Expand Up @@ -349,7 +349,7 @@ private async Task UpdateDocumentQueueStatus(PimsDocumentQueue documentQueue, Do
}
}

await _documentQueueRepository.Update(documentQueue, removeDocument);
await _documentQueueRepository.UpdateAsync(documentQueue, removeDocument);
}

private bool ValidateQueuedDocument(PimsDocumentQueue databaseDocumentQueue, PimsDocumentQueue externalDocument)
Expand Down
3 changes: 1 addition & 2 deletions source/backend/api/Services/NotificationUserService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ public async Task PushNotificationUser(long notificationUserId)
userNotification.NotificationSentDt = DateTime.UtcNow;
}

_ = await _notificationUserOutputRepository.Update(userNotification);
_notificationUserOutputRepository.CommitTransaction();
_ = await _notificationUserOutputRepository.UpdateAsync(userNotification);

return;
}
Expand Down
2 changes: 1 addition & 1 deletion source/backend/dal/Repositories/DocumentQueueRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public PimsDocumentQueue GetByDocumentId(long documentId)
/// </summary>
/// <param name="queuedDocument"></param>
/// <returns></returns>
public async Task<PimsDocumentQueue> Update(PimsDocumentQueue queuedDocument, bool removeDocument = false)
public async Task<PimsDocumentQueue> UpdateAsync(PimsDocumentQueue queuedDocument, bool removeDocument = false)
{
// Use a distributed lock to ensure that only one process can update the document queue at a time (prevents deadlocks from history triggers).
var @lock = this._synchronizationProvider.CreateLock("DocumentQueueLock");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IDocumentQueueRepository : IRepository<PimsDocument>

IEnumerable<DocumentQueueSearchResult> GetAllByFilter(DocumentQueueFilter filter);

Task<PimsDocumentQueue> Update(PimsDocumentQueue queuedDocument, bool removeDocument = false);
Task<PimsDocumentQueue> UpdateAsync(PimsDocumentQueue queuedDocument, bool removeDocument = false);

bool Delete(PimsDocumentQueue queuedDocument);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public interface INotificationUserOutputRepository : IRepository

public PimsNotificationUserOutput GetById(long notificationUserOutputId);

public Task<PimsNotificationUserOutput> Update(PimsNotificationUserOutput userNotification);
public Task<PimsNotificationUserOutput> UpdateAsync(PimsNotificationUserOutput userNotification);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public PimsNotificationUserOutput GetById(long notificationUserOutputId)
.FirstOrDefault(x => x.NotificationUserOutputId == notificationUserOutputId) ?? throw new KeyNotFoundException();
}

public async Task<PimsNotificationUserOutput> Update(PimsNotificationUserOutput userNotification)
public async Task<PimsNotificationUserOutput> UpdateAsync(PimsNotificationUserOutput userNotification)
{
var @lock = _synchronizationProvider.CreateLock("NotificationUserOutputLock");
await using (await @lock.AcquireAsync())
Expand All @@ -91,7 +91,7 @@ public async Task<PimsNotificationUserOutput> Update(PimsNotificationUserOutput
.FirstOrDefault(x => x.NotificationUserOutputId == userNotification.NotificationUserOutputId);

Context.Entry(existingUserNotification).CurrentValues.SetValues(userNotification);
Context.Update(existingUserNotification);
await Context.SaveChangesAsync();

return existingUserNotification;
}
Expand Down
24 changes: 12 additions & 12 deletions source/backend/tests/api/Services/DocumentQueueServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,15 @@ public async void Update_Success()
var documentQueue = new PimsDocumentQueue { DocumentQueueId = 1 };
var documentQueueRepositoryMock = this._helper.GetService<Mock<IDocumentQueueRepository>>();

documentQueueRepositoryMock.Setup(m => m.Update(documentQueue, false));
documentQueueRepositoryMock.Setup(m => m.UpdateAsync(documentQueue, false));
documentQueueRepositoryMock.Setup(m => m.CommitTransaction());

// Act
var result = await service.Update(documentQueue);

// Assert
result.Should().Be(documentQueue);
documentQueueRepositoryMock.Verify(m => m.Update(documentQueue, false), Times.Once);
documentQueueRepositoryMock.Verify(m => m.UpdateAsync(documentQueue, false), Times.Once);
}

[Fact]
Expand Down Expand Up @@ -216,7 +216,7 @@ public async Task PollForDocument_RelatedDocumentMayanIdNull_UpdatesStatusToPIMS

// Assert
await act.Should().ThrowAsync<InvalidDataException>();
documentQueueRepositoryMock.Verify(m => m.Update(databaseDocumentQueue, false), Times.Once);
documentQueueRepositoryMock.Verify(m => m.UpdateAsync(databaseDocumentQueue, false), Times.Once);
}

[Fact]
Expand All @@ -241,7 +241,7 @@ public async Task PollForDocument_GetStorageDocumentDetailFails_UpdatesStatusToP

// Assert
result.Should().Be(databaseDocumentQueue);
documentQueueRepositoryMock.Verify(m => m.Update(databaseDocumentQueue, false), Times.Once);
documentQueueRepositoryMock.Verify(m => m.UpdateAsync(databaseDocumentQueue, false), Times.Once);
}

[Fact]
Expand All @@ -267,7 +267,7 @@ public async Task PollForDocument_FileLatestIdNull_LogsFileStillProcessing()

// Assert
result.Should().Be(databaseDocumentQueue);
documentQueueRepositoryMock.Verify(m => m.Update(databaseDocumentQueue, false), Times.Never);
documentQueueRepositoryMock.Verify(m => m.UpdateAsync(databaseDocumentQueue, false), Times.Never);
documentQueueRepositoryMock.Verify(m => m.CommitTransaction(), Times.Never);
}

Expand Down Expand Up @@ -295,7 +295,7 @@ public async Task PollForDocument_FileLatestIdNotNull_UpdatesStatusToSuccess()
// Assert
result.Should().Be(databaseDocumentQueue);
result.DocumentQueueStatusTypeCode.Should().Be(DocumentQueueStatusTypes.SUCCESS.ToString());
documentQueueRepositoryMock.Verify(m => m.Update(databaseDocumentQueue, true), Times.Once);
documentQueueRepositoryMock.Verify(m => m.UpdateAsync(databaseDocumentQueue, true), Times.Once);
}

[Fact]
Expand Down Expand Up @@ -359,7 +359,7 @@ public async Task Upload_Success()
// Assert
result.Should().NotBeNull();
result.DocumentQueueStatusTypeCode.Should().Be(DocumentQueueStatusTypes.SUCCESS.ToString());
documentQueueRepositoryMock.Verify(x => x.Update(It.IsAny<PimsDocumentQueue>(), It.IsAny<bool>()), Times.AtLeastOnce);
documentQueueRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny<PimsDocumentQueue>(), It.IsAny<bool>()), Times.AtLeastOnce);
documentServiceMock.Verify(x => x.UploadDocumentAsync(It.IsAny<DocumentUploadRequest>(), true), Times.Once);
}

Expand Down Expand Up @@ -425,7 +425,7 @@ public async Task Upload_Retry_Success()
result.Should().NotBeNull();
result.DocProcessRetries.Should().Be(1);
result.DocumentQueueStatusTypeCode.Should().Be(DocumentQueueStatusTypes.SUCCESS.ToString());
documentQueueRepositoryMock.Verify(x => x.Update(It.IsAny<PimsDocumentQueue>(), It.IsAny<bool>()), Times.AtLeastOnce);
documentQueueRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny<PimsDocumentQueue>(), It.IsAny<bool>()), Times.AtLeastOnce);
documentServiceMock.Verify(x => x.UploadDocumentAsync(It.IsAny<DocumentUploadRequest>(), true), Times.Once);
}

Expand Down Expand Up @@ -455,7 +455,7 @@ public async Task Upload_ValidateQueuedDocumentFails_UpdatesStatusToPIMSError()
// Assert
result.Should().NotBeNull();
result.DocumentQueueStatusTypeCode.Should().Be(DocumentQueueStatusTypes.PIMS_ERROR.ToString());
documentQueueRepositoryMock.Verify(x => x.Update(It.IsAny<PimsDocumentQueue>(), It.IsAny<bool>()), Times.AtLeastOnce);
documentQueueRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny<PimsDocumentQueue>(), It.IsAny<bool>()), Times.AtLeastOnce);
documentServiceMock.Verify(x => x.UploadDocumentAsync(It.IsAny<DocumentUploadRequest>(), true), Times.Never);
}

Expand Down Expand Up @@ -591,7 +591,7 @@ public async Task Upload_RelatedDocument_MayanId()
// Assert
result.Should().NotBeNull();
result.DocumentQueueStatusTypeCode.Should().Be(DocumentQueueStatusTypes.PROCESSING.ToString());
documentQueueRepositoryMock.Verify(x => x.Update(It.IsAny<PimsDocumentQueue>(), It.IsAny<bool>()), Times.AtLeastOnce);
documentQueueRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny<PimsDocumentQueue>(), It.IsAny<bool>()), Times.AtLeastOnce);
documentServiceMock.Verify(x => x.UploadDocumentAsync(It.IsAny<DocumentUploadRequest>(), true), Times.Once);
}

Expand Down Expand Up @@ -684,7 +684,7 @@ public async Task Upload_DocumentTypeIdNull()
await act.Should().ThrowAsync<InvalidDataException>();

// Assert
documentQueueRepositoryMock.Verify(x => x.Update(It.Is<PimsDocumentQueue>(p => p.DocumentQueueStatusTypeCode == DocumentQueueStatusTypes.PIMS_ERROR.ToString()), It.IsAny<bool>()), Times.AtLeastOnce);
documentQueueRepositoryMock.Verify(x => x.UpdateAsync(It.Is<PimsDocumentQueue>(p => p.DocumentQueueStatusTypeCode == DocumentQueueStatusTypes.PIMS_ERROR.ToString()), It.IsAny<bool>()), Times.AtLeastOnce);
}

[Fact]
Expand Down Expand Up @@ -741,7 +741,7 @@ public async Task Upload_UploadDocumentFails_UpdatesStatusToMayanError()
// Assert
result.Should().NotBeNull();
result.DocumentQueueStatusTypeCode.Should().Be(DocumentQueueStatusTypes.MAYAN_ERROR.ToString());
documentQueueRepositoryMock.Verify(x => x.Update(It.IsAny<PimsDocumentQueue>(), It.IsAny<bool>()), Times.AtLeastOnce);
documentQueueRepositoryMock.Verify(x => x.UpdateAsync(It.IsAny<PimsDocumentQueue>(), It.IsAny<bool>()), Times.AtLeastOnce);
documentServiceMock.Verify(x => x.UploadDocumentAsync(It.IsAny<DocumentUploadRequest>(), true), Times.Once);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

// Act
documentQueue.DocumentQueueStatusTypeCode = "Updated";
var result = repository.Update(documentQueue);
var result = repository.UpdateAsync(documentQueue);

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning test

This assignment to
result
is useless, since its value is never read.
context.CommitTransaction();

// Assert
Expand All @@ -90,7 +90,7 @@
// Act
documentQueue.DocumentQueueStatusTypeCode = "Updated";
documentQueue.Document = null;
var result = repository.Update(documentQueue, removeDocument: true);
var result = repository.UpdateAsync(documentQueue, removeDocument: true);

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning test

This assignment to
result
is useless, since its value is never read.
context.CommitTransaction();

// Assert
Expand All @@ -109,7 +109,7 @@
var repository = helper.CreateRepository<DocumentQueueRepository>(user);

// Act
Func<Task> act = () => repository.Update(null);
Func<Task> act = () => repository.UpdateAsync(null);

// Assert
act.Should().ThrowAsync<ArgumentNullException>();
Expand Down
Loading