public void WhenModelIsNotAnInstanceOfAnObject_ThenItThrowsArgumentNullException() { ShortLinkUpdateDto model = null; var act = new AsyncTestDelegate(() => ShortLinkUpdateValidator.ValidateModelAsync(model)); Assert.ThrowsAsync <ArgumentNullException>(act); }
public async Task UpdateAsync(string ownerSubjectId, Guid id, ShortLinkUpdateDto dto) { if (!id.Equals(dto.Id)) { throw new InvalidUpdateRequestException($"Update request for ID '{id}' contains a model with ID '{dto.Id}'"); } await ShortLinkUpdateValidator.ValidateModelAsync(dto); if (await _repository.CheckIfShortCodeIsUniqueForShortLinkAsync(id, dto.ShortCode)) { await InvalidateCacheAsync(dto.ShortCode); await _repository.UpdateExistingShortLinkAsync(ownerSubjectId, dto); } }
public async Task UpdateExistingShortLinkAsync(string ownerId, ShortLinkUpdateDto dto) { var table = await _tableFactory.GetCloudTableReferenceAsync(TableNames.ShortLinks); var operation = TableOperation.Retrieve <ShortLinkEntity>(PartitionKeys.ShortLinks, dto.Id.ToString()); var result = await table.ExecuteAsync(operation); if (result.Result is ShortLinkEntity entity) { if (entity.OwnerId != ownerId) { throw new ShortLinkNotFoundException(dto.Id); } entity.ShortCode = dto.ShortCode; entity.EndpointUrl = dto.EndpointUrl; entity.ExpiresOn = dto.ExpirationOn; var mergeOperation = TableOperation.InsertOrReplace(entity); await table.ExecuteAsync(mergeOperation); } }