public void MarkAsDeleted_ShouldMarkAsDeletedWithCorrectName5() { var deletedBy = new UserDto { }; var itemToBeDeleted = new CloudResource { }; var ex = Assert.Throws <ArgumentNullException>(() => SoftDeleteUtil.MarkAsDeleted(null, "")); Assert.Contains("Item to delete was null", ex.Message); Assert.False(SoftDeleteUtil.IsMarkedAsDeleted(itemToBeDeleted)); }
public void MarkAsDeleted_ShouldMarkAsDeletedWithCorrectName() { var deletedBy = "John"; var itemToBeDeleted = new CloudResource { }; SoftDeleteUtil.MarkAsDeleted(itemToBeDeleted, deletedBy); Assert.Equal(itemToBeDeleted.DeletedBy, deletedBy); Assert.True(SoftDeleteUtil.IsMarkedAsDeleted(itemToBeDeleted)); }
public async Task <bool> ResourceIsDeleted(int resourceId) { var resource = await _db.CloudResources.AsNoTracking().FirstOrDefaultAsync(r => r.Id == resourceId); if (resource == null) { return(true); } return(SoftDeleteUtil.IsMarkedAsDeleted(resource)); }
public async Task <List <SandboxResourceLight> > GetSandboxResourcesLight(int sandboxId) { var sandboxFromDb = await _sandboxModelService.GetByIdForResourcesAsync(sandboxId); //Filter out deleted resources var resourcesFiltered = sandboxFromDb.Resources .Where(r => !SoftDeleteUtil.IsMarkedAsDeleted(r) || ( SoftDeleteUtil.IsMarkedAsDeleted(r) && !r.Operations.Where(o => o.OperationType == CloudResourceOperationType.DELETE && o.Status == CloudResourceOperationState.DONE_SUCCESSFUL).Any()) ).ToList(); var resourcesMapped = _mapper.Map <List <SandboxResourceLight> >(resourcesFiltered); return(resourcesMapped); }
public async Task <List <DatasetResourceLightDto> > GetDatasetResourcesAsync(int studyId, int datasetId, CancellationToken cancellation) { var dataset = await _studySpecificDatasetModelService.GetForResourceAndFirewall(datasetId, UserOperation.Study_Read); //Filter out deleted resources var resourcesFiltered = dataset.Resources .Where(r => !SoftDeleteUtil.IsMarkedAsDeleted(r) || ( SoftDeleteUtil.IsMarkedAsDeleted(r) && !r.Operations.Where(o => o.OperationType == CloudResourceOperationType.DELETE && o.Status == CloudResourceOperationState.DONE_SUCCESSFUL).Any()) ).ToList(); var resourcesMapped = _mapper.Map <List <DatasetResourceLightDto> >(resourcesFiltered); return(resourcesMapped); }
CloudResource GetResourceGroupForStudySpecificDataset(Study study, bool includeDeleted = false) { if (study.Resources == null) { throw new Exception("Missing Include for CloudResource on Study"); } foreach (var curResource in study.Resources) { if (!SoftDeleteUtil.IsMarkedAsDeleted(curResource) || includeDeleted) { if (curResource.ResourceType == AzureResourceType.ResourceGroup) { if (!String.IsNullOrWhiteSpace(curResource.Purpose) && curResource.Purpose == CloudResourcePurpose.StudySpecificDatasetContainer) { return(curResource); } } } } return(null); }