Пример #1
0
        public async Task DeleteDatasetsBySpecificationId(string specificationId, DeletionType deletionType)
        {
            IEnumerable <Dataset> datasets = await GetDatasetsByQuery(d => d.Id == specificationId);

            List <Dataset> datasetList = datasets.ToList();

            if (!datasetList.Any())
            {
                return;
            }

            if (deletionType == DeletionType.SoftDelete)
            {
                await _cosmosRepository.BulkDeleteAsync(datasets.Select(c => new KeyValuePair <string, Dataset>(null, c)), hardDelete : false);
            }
            if (deletionType == DeletionType.PermanentDelete)
            {
                IEnumerable <DatasetVersion> datasetVersions = await GetDatasetVersionsByQuery(d => d.Id == specificationId);

                List <DatasetVersion> datasetVersionsList = datasetVersions.ToList();

                if (datasetVersionsList.Any())
                {
                    await _cosmosRepository.BulkDeleteAsync(datasetVersions.Select(c => new KeyValuePair <string, DatasetVersion>(null, c)), hardDelete : true);
                }

                await _cosmosRepository.BulkDeleteAsync(datasets.Select(c => new KeyValuePair <string, Dataset>(null, c)), hardDelete : true);
            }
        }
Пример #2
0
 private async Task WhenTheQueueDeleteSpecificationJobActionIsRun(
     string specificationId,
     Reference user,
     string correlationId,
     DeletionType deletionType)
 {
     await _action.Run(specificationId, user, correlationId, deletionType);
 }
Пример #3
0
        public static DeletionType ToDeletionType(this string deletionTypeProperty)
        {
            DeletionType deletionType = DeletionType.SoftDelete;

            if (int.TryParse(deletionTypeProperty, out var deletionTypeValue))
            {
                deletionType = (DeletionType)deletionTypeValue;
            }

            return(deletionType);
        }
        public async Task DeleteTestResultsBySpecificationId(string specificationId, DeletionType deletionType)
        {
            IEnumerable <TestScenarioResult> testResults = await GetTestResultsBySpecificationId(specificationId);

            List <TestScenarioResult> testResultList = testResults.ToList();

            if (!testResultList.Any())
            {
                return;
            }

            if (deletionType == DeletionType.SoftDelete)
            {
                await _cosmosRepository.BulkDeleteAsync(testResultList.ToDictionary(c => c.Id), hardDelete : false);
            }
            if (deletionType == DeletionType.PermanentDelete)
            {
                await _cosmosRepository.BulkDeleteAsync(testResultList.ToDictionary(c => c.Id), hardDelete : true);
            }
        }
        public async Task DeleteJobsBySpecificationId(string specificationId, DeletionType deletionType)
        {
            IEnumerable <Job> jobs = await GetJobsBySpecificationId(specificationId);

            List <Job> jobsList = jobs.ToList();

            if (!jobsList.Any())
            {
                return;
            }

            if (deletionType == DeletionType.SoftDelete)
            {
                await _cosmosRepository.BulkDeleteAsync(jobsList.ToDictionary(c => c.Id), hardDelete : false);
            }
            if (deletionType == DeletionType.PermanentDelete)
            {
                await _cosmosRepository.BulkDeleteAsync(jobsList.ToDictionary(c => c.Id), hardDelete : true);
            }
        }
        public async Task DeleteSpecifications(string specificationId, DeletionType deletionType)
        {
            if (deletionType == DeletionType.SoftDelete)
            {
                await _repository.DeleteAsync <Specification>(specificationId, null, hardDelete : false);
            }
            else if (deletionType == DeletionType.PermanentDelete)
            {
                IEnumerable <SpecificationVersion> specifications =
                    await _repository.Query <SpecificationVersion>(m => m.Content.SpecificationId == specificationId);

                List <SpecificationVersion> specificationsList = specifications.ToList();

                if (specificationsList.Any())
                {
                    await _repository.BulkDeleteAsync(specificationsList.Select(_ => new KeyValuePair <string, SpecificationVersion>(null, _)), hardDelete : true);
                }

                await _repository.DeleteAsync <Specification>(specificationId, null, hardDelete : true);
            }
        }
        public async Task Run(string specificationId, Reference user, string correlationId, DeletionType deletionType)
        {
            string deletionTypeValue = deletionType.ToString("D");

            var deleteSpecificationJob = await CreateJob(NewJobCreateModel(specificationId,
                                                                           "Deleting Specification",
                                                                           JobConstants.DefinitionNames.DeleteSpecificationJob,
                                                                           correlationId,
                                                                           user,
                                                                           new Dictionary <string, string>
            {
                { "specification-id", specificationId },
                { "deletion-type", deletionTypeValue },
                { "user-id", user.Id },
                { "user-name", user.Name }
            }));

            IEnumerable <Task> specificationChildJobs = _specificationChildJobDefinitions.Select(childJob => CreateJob(
                                                                                                     NewJobCreateModel(specificationId,
                                                                                                                       childJob.Value,
                                                                                                                       childJob.Key,
                                                                                                                       correlationId,
                                                                                                                       user,
                                                                                                                       new Dictionary <string, string>
            {
                { "specification-id", specificationId },
                { "deletion-type", deletionTypeValue },
                { "user-id", user.Id },
                { "user-name", user.Name }
            },
                                                                                                                       deleteSpecificationJob.Id)));

            await TaskHelper.WhenAllAndThrow(specificationChildJobs.ToArray());
        }
Пример #8
0
        public async Task DeleteTestResults_Deletes_Dependencies_Using_Correct_SpecificationId_And_DeletionType(string specificationId, DeletionType deletionType)
        {
            string jobId = "job-id";

            Message message = new Message
            {
                UserProperties =
                {
                    new KeyValuePair <string, object>("jobId",            jobId),
                    new KeyValuePair <string, object>("specification-id", specificationId),
                    new KeyValuePair <string, object>("deletion-type",    (int)deletionType)
                }
            };
            ITestResultsRepository testResultsRepository = CreateTestResultsRepository();
            TestResultsService     service = CreateTestResultsService(testResultsRepository: testResultsRepository);

            await service.DeleteTestResults(message);

            await testResultsRepository.Received(1).DeleteTestResultsBySpecificationId(specificationId, deletionType);
        }
Пример #9
0
        public async Task QueuesParentJobAndAssignCalculationsJobsWhereConfigurationHasADefaultTemplateVersion(DeletionType deletionType)
        {
            string specificationId     = NewRandomString();
            string expectedParentJobId = NewRandomString();
            string deletionTypeValue   = deletionType.ToString("D");

            SetupDeleteSpecificationJob(expectedParentJobId, specificationId);
            SetupDeleteSpecificationChildJobs(specificationId, expectedParentJobId);
            var deleteSpecificationParentJob = CreateJobModelMatching(_ =>
                                                                      _.JobDefinitionId == DeleteSpecificationJob &&
                                                                      _.ParentJobId == null &&
                                                                      _.ItemCount == null &&
                                                                      HasProperty(_, SpecificationId, specificationId) &&
                                                                      HasProperty(_, Deletion, deletionTypeValue)
                                                                      );

            await WhenTheQueueDeleteSpecificationJobActionIsRun(specificationId, _user, _correlationId, deletionType);

            await ThenTheDeleteSpecificationJobIsCreated(deleteSpecificationParentJob);
            await AndThenTheSpecificationChildJobsWereCreated(specificationId, deletionTypeValue, expectedParentJobId);
        }
        public async Task DeleteTemplateMappingsBySpecificationId(string specificationId, DeletionType deletionType)
        {
            IEnumerable <TemplateMapping> mappings = await GetTemplateMappinsBySpecificationId(specificationId);

            List <TemplateMapping> existingmappings = mappings.ToList();

            if (!existingmappings.Any())
            {
                return;
            }

            if (deletionType == DeletionType.SoftDelete)
            {
                await _cosmosRepository.BulkDeleteAsync(existingmappings.Select(c => new KeyValuePair <string, TemplateMapping>(null, c)), hardDelete : false);
            }
            if (deletionType == DeletionType.PermanentDelete)
            {
                await _cosmosRepository.BulkDeleteAsync(existingmappings.Select(c => new KeyValuePair <string, TemplateMapping>(null, c)), hardDelete : true);
            }
        }
Пример #11
0
    public override IEnumerator Execute(UTContext context)
    {
        DeletionType theDeletionType = deletionType.EvaluateIn(context);
        var          doDryRun        = dryRun.EvaluateIn(context);

        if (theDeletionType == DeletionType.SingleFileOrFolder)
        {
            var theSingleFileOrFolder = fileOrFolder.EvaluateIn(context);
            if (string.IsNullOrEmpty(theSingleFileOrFolder))
            {
                throw new UTFailBuildException("You need to specify the name of the file or folder to be deleted.", this);
            }
            if (doDryRun)
            {
                Debug.Log("[Dry Run] Would delete " + theSingleFileOrFolder);
            }
            else
            {
                FileAttributes attributes;
                try {
                    attributes = File.GetAttributes(theSingleFileOrFolder);
                }
                catch (DirectoryNotFoundException) {
                    if (UTPreferences.DebugMode)
                    {
                        Debug.Log("File " + theSingleFileOrFolder + " already deleted.");
                    }
                    yield break;
                }
                if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    if (UTPreferences.DebugMode)
                    {
                        Debug.Log("Deleting directory " + theSingleFileOrFolder);
                    }
                    Directory.Delete(theSingleFileOrFolder, true);
                }
                else
                {
                    if (UTPreferences.DebugMode)
                    {
                        Debug.Log("Deleting file " + theSingleFileOrFolder);
                    }
                    File.Delete(theSingleFileOrFolder);
                }
            }
        }
        else
        {
            var theBaseDirectory = baseDirectory.EvaluateIn(context);
            if (string.IsNullOrEmpty(theBaseDirectory))
            {
                theBaseDirectory = UTFileUtils.ProjectRoot;
            }
            if (!Directory.Exists(theBaseDirectory))
            {
                Debug.Log("Base directory " + theBaseDirectory + " does not exist. Skipping delete action.");
            }
            else
            {
                theBaseDirectory = UTFileUtils.NormalizeSlashes(theBaseDirectory);

                var theIncludes = EvaluateAll(includes, context);
                var theExcludes = EvaluateAll(excludes, context);

                var theStuff = UTFileUtils.CalculateFileset(theBaseDirectory, theIncludes, theExcludes, UTFileUtils.FileSelectionMode.FilesAndFolders);


                Debug.Log("Deleting " + theStuff.Length + " files & directories.");

                for (int i = 0; i < theStuff.Length; i++)
                {
                    context.LocalProgress = ((float)i) / ((float)theStuff.Length);

                    var stuff  = theStuff [i];
                    var exists = File.Exists(stuff) || Directory.Exists(stuff);
                    if (!exists)
                    {
                        Debug.LogWarning(stuff + " does no longer exist. Check if your fileset can be simplified.");
                        // maybe was a subfolder of a directory that got deleted before.
                        continue;
                    }
                    var attributes = File.GetAttributes(stuff);
                    if ((attributes & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        if (doDryRun)
                        {
                            Debug.Log("[Dry Run] Would delete directory " + stuff);
                        }
                        else
                        {
                            if (UTPreferences.DebugMode)
                            {
                                Debug.Log("Deleting directory " + stuff);
                            }
                            Directory.Delete(stuff, true);
                        }
                    }
                    else
                    {
                        if (doDryRun)
                        {
                            Debug.Log("[Dry Run] Would delete file" + stuff);
                        }
                        else
                        {
                            if (UTPreferences.DebugMode)
                            {
                                Debug.Log("Deleting file " + stuff);
                            }
                            File.Delete(stuff);
                        }
                    }
                    yield return("");
                }
            }
        }
    }
        public async Task DeleteCalculations_Deletes_Dependencies_Using_Correct_SpecificationId_And_DeletionType(string specificationId, DeletionType deletionType)
        {
            Message message = new Message
            {
                UserProperties =
                {
                    new KeyValuePair <string, object>("jobId",            JobId),
                    new KeyValuePair <string, object>("specification-id", specificationId),
                    new KeyValuePair <string, object>("deletion-type",    (int)deletionType)
                }
            };
            ICalculationsRepository calculationsRepository = CreateCalculationsRepository();
            CalculationService      calculationService     = CreateCalculationService(calculationsRepository: calculationsRepository);

            await calculationService.DeleteCalculations(message);

            await calculationsRepository.Received(1).DeleteCalculationsBySpecificationId(specificationId, deletionType);
        }
Пример #13
0
        public async Task DeleteCalculationResultsBySpecificationId(string specificationId, DeletionType deletionType)
        {
            IEnumerable <ProviderResult> calculationResults = await GetCalculationResultsBySpecificationId(specificationId);

            List <ProviderResult> calculationResultList = calculationResults.ToList();

            if (!calculationResultList.Any())
            {
                return;
            }

            if (deletionType == DeletionType.SoftDelete)
            {
                await _cosmosRepository.BulkDeleteAsync(calculationResultList.ToDictionary(c => c.Provider.Id), hardDelete : false);
            }
            if (deletionType == DeletionType.PermanentDelete)
            {
                await _cosmosRepository.BulkDeleteAsync(calculationResultList.ToDictionary(c => c.Provider.Id), hardDelete : true);
            }
        }
Пример #14
0
        public async Task DeleteDefinitionSpecificationRelationshipBySpecificationId(string specificationId, DeletionType deletionType)
        {
            IEnumerable <DefinitionSpecificationRelationship> relationships =
                await GetDefinitionSpecificationRelationshipsByQuery(r => r.Content.Specification.Id == specificationId);

            List <DefinitionSpecificationRelationship> definitionSpecificationRelationshipList = relationships.ToList();

            if (!definitionSpecificationRelationshipList.Any())
            {
                return;
            }

            if (deletionType == DeletionType.SoftDelete)
            {
                await _cosmosRepository.BulkDeleteAsync(definitionSpecificationRelationshipList.Select(c => new KeyValuePair <string, DefinitionSpecificationRelationship>(null, c)), hardDelete : false);
            }
            if (deletionType == DeletionType.PermanentDelete)
            {
                await _cosmosRepository.BulkDeleteAsync(definitionSpecificationRelationshipList.Select(c => new KeyValuePair <string, DefinitionSpecificationRelationship>(null, c)), hardDelete : true);
            }
        }
        public async Task DeleteCalculationsBySpecificationId(string specificationId, DeletionType deletionType)
        {
            IEnumerable <Calculation> calculations = await GetCalculationsBySpecificationId(specificationId);

            List <Calculation> existingCalculations = calculations.ToList();

            if (!existingCalculations.Any())
            {
                return;
            }

            if (deletionType == DeletionType.SoftDelete)
            {
                await _cosmosRepository.BulkDeleteAsync(existingCalculations.Select(c => new KeyValuePair <string, Calculation>(null, c)), hardDelete : false);
            }
            if (deletionType == DeletionType.PermanentDelete)
            {
                await _cosmosRepository.BulkDeleteAsync(existingCalculations.Select(c => new KeyValuePair <string, Calculation>(null, c)), hardDelete : true);
            }
        }
        public async Task DeleteProviderSourceDataset(string providerSourceDatasetId, DeletionType deletionType)
        {
            IEnumerable <ProviderSourceDataset> providerSourceDatasets =
                await _cosmosRepository.Query <ProviderSourceDataset>(m => m.Id == providerSourceDatasetId);

            List <ProviderSourceDataset> providerSourceDatasetList = providerSourceDatasets.ToList();

            if (!providerSourceDatasetList.Any())
            {
                return;
            }

            if (deletionType == DeletionType.SoftDelete)
            {
                await _cosmosRepository.BulkDeleteAsync(providerSourceDatasetList.ToDictionary(c => c.ProviderId), hardDelete : false);
            }
            if (deletionType == DeletionType.PermanentDelete)
            {
                await _cosmosRepository.BulkDeleteAsync(providerSourceDatasetList.ToDictionary(c => c.ProviderId), hardDelete : true);
            }
        }
        public async Task DeleteTestResults_Deletes_Dependencies_Using_Correct_SpecificationId_And_DeletionType(string specificationId, DeletionType deletionType)
        {
            string jobId = "job-id";

            Message message = new Message
            {
                UserProperties =
                {
                    new KeyValuePair <string, object>("jobId",            jobId),
                    new KeyValuePair <string, object>("specification-id", specificationId),
                    new KeyValuePair <string, object>("deletion-type",    (int)deletionType)
                }
            };
            IScenariosRepository testsRepository = Substitute.For <IScenariosRepository>();
            var scenariosResiliencePolicies      = Substitute.For <IScenariosResiliencePolicies>();

            scenariosResiliencePolicies.JobsApiClient           = Policy.NoOpAsync();
            scenariosResiliencePolicies.CalcsRepository         = Policy.NoOpAsync();
            scenariosResiliencePolicies.ScenariosRepository     = Policy.NoOpAsync();
            scenariosResiliencePolicies.SpecificationsApiClient = Policy.NoOpAsync();
            ScenariosService service = new ScenariosService(
                Substitute.For <ILogger>(),
                testsRepository,
                Substitute.For <ISpecificationsApiClient>(),
                Substitute.For <IValidator <CreateNewTestScenarioVersion> >(),
                Substitute.For <ISearchRepository <ScenarioIndex> >(),
                Substitute.For <ICacheProvider>(),
                Substitute.For <IVersionRepository <TestScenarioVersion> >(),
                Substitute.For <IJobManagement>(),
                Substitute.For <ICalcsRepository>(),
                scenariosResiliencePolicies
                );

            await service.DeleteTests(message);

            await testsRepository.Received(1).DeleteTestsBySpecificationId(specificationId, deletionType);
        }