public async Task DeterminesCalculationRelationsForAllCalculationsInTheSpecificationWithTheSuppliedId() { string specificationId = NewRandomString(); Calculation calculation = new Calculation(); SpecificationSummary specificationSummary = new SpecificationSummary(); Specification graphSpecification = NewGraphSpecification(); Calculation[] calculations = new[] { calculation, }; GraphCalculation[] graphCalculations = new GraphCalculation[0]; FundingLine[] fundingLines = new FundingLine[0]; CalculationRelationship[] calculationRelationships = new CalculationRelationship[0]; FundingLineCalculationRelationship[] fundingLineCalculationRelationships = new FundingLineCalculationRelationship[0]; List <Models.Calcs.DatasetRelationshipSummary> datasetRelationshipSummaries = new List <Models.Calcs.DatasetRelationshipSummary>(); DatasetReference[] datasetReferences = new[] { new DatasetReference { Calculations = graphCalculations.ToList(), DataField = new DataField(), Dataset = new Models.Graph.Dataset(), DatasetDefinition = new DatasetDefinition() }, }; GivenTheSpecification(specificationId, specificationSummary); AndTheCalculations(specificationId, calculations); AndTheRelationshipsForTheCalculations(calculations, calculationRelationships); AndTheBuildProjectForTheSpecification(specificationId, datasetRelationshipSummaries); AndTheDatasetReferencesForTheCalculations(calculations, datasetRelationshipSummaries, datasetReferences); AndTheMapping(calculations, graphCalculations); AndTheMapping(specificationSummary, graphSpecification); SpecificationCalculationRelationships specificationCalculationRelationships = await WhenTheRelationshipsAreDetermined(specificationId); specificationCalculationRelationships .Should() .BeEquivalentTo(new SpecificationCalculationRelationships { Specification = graphSpecification, FundingLineRelationships = fundingLineCalculationRelationships, FundingLines = fundingLines, Calculations = graphCalculations, CalculationRelationships = calculationRelationships, CalculationDataFieldRelationships = datasetReferences.SelectMany(_ => _.Calculations.Select(calculation => new CalculationDataFieldRelationship { Calculation = calculation, DataField = _.DataField })), DatasetDataFieldRelationships = datasetReferences.Select(_ => new DatasetDataFieldRelationship { Dataset = _.Dataset, DataField = _.DataField }), DatasetDatasetDefinitionRelationships = datasetReferences.Select(_ => new DatasetDatasetDefinitionRelationship { Dataset = _.Dataset, DatasetDefinition = _.DatasetDefinition }) }); }
public async Task DeletesThenInsertsGraphForSpecification(bool withCallsCalculation, bool withBelongsToSpecification, bool withFundingLineRemoval) { string specificationId = NewRandomString(); string fundingLineIdOne = NewRandomString(); string fundingLineIdTwo = NewRandomString(); string fundingLineIdThree = NewRandomString(); string fundingLineIdFour = NewRandomString(); string fundingLineIdFive = NewRandomString(); string calculationIdOne = NewRandomString(); string calculationIdTwo = NewRandomString(); string calculationIdThree = NewRandomString(); string calculationIdFour = NewRandomString(); string calculationIdFive = NewRandomString(); string datafieldId = NewRandomString(); Specification specification = NewGraphSpecification(_ => _.WithId(specificationId)); IEnumerable <ApiEntitySpecification> existingEntities = new[] { new ApiEntitySpecification { Node = new ApiSpecification { SpecificationId = specificationId }, Relationships = withBelongsToSpecification ? new[] { new ApiRelationship { One = NewGraphCalculation(_ => _.WithId(calculationIdFive)), Type = "BelongsToSpecification", Two = specification } } : null } }; IEnumerable <ApiEntityCalculation> existingCalculationEntities = new[] { new ApiEntityCalculation { Node = new ApiCalculation { CalculationId = calculationIdFive }, Relationships = new[] { new ApiRelationship { One = NewGraphCalculation(_ => _.WithId(calculationIdOne)), Type = "ReferencesDataField", Two = NewDataField(_ => _.WithCalculationId(calculationIdOne).WithDataFieldId(datafieldId)) } } } }; if (withCallsCalculation) { existingCalculationEntities = existingCalculationEntities.Concat(new[] { new ApiEntityCalculation { Node = new ApiCalculation { SpecificationId = specificationId, CalculationId = calculationIdFour }, Relationships = new[] { new ApiRelationship { One = NewGraphCalculation(_ => _.WithId(calculationIdFour)), Type = "CallsCalculation", Two = NewGraphCalculation(_ => _.WithId(calculationIdFive)) } } } }); } IEnumerable <ApiEntityFundingLine> existingFundingLines = (new[] { new ApiEntityFundingLine { Node = new ApiFundingLine { FundingLineId = fundingLineIdFive } } }); FundingLine[] fundingLines = new[] { NewGraphFundingLine(_ => _.WithId(fundingLineIdOne)), NewGraphFundingLine(_ => _.WithId(fundingLineIdTwo)), NewGraphFundingLine(_ => _.WithId(fundingLineIdThree)), NewGraphFundingLine(_ => _.WithId(fundingLineIdFour)), NewGraphFundingLine(_ => _.WithId(fundingLineIdFive)) }; FundingLineCalculationRelationship[] fundingLineRelationships = new[] { NewFundingLineRelationship(_ => _.WithCalculationOneId(calculationIdOne) .WithCalculationTwoId(calculationIdOne) .WithFundingLine(fundingLines[0])), NewFundingLineRelationship(_ => _.WithCalculationOneId(calculationIdOne) .WithCalculationTwoId(calculationIdTwo) .WithFundingLine(fundingLines[1])), NewFundingLineRelationship(_ => _.WithCalculationOneId(calculationIdOne) .WithCalculationTwoId(calculationIdThree) .WithFundingLine(fundingLines[2])), NewFundingLineRelationship(_ => _.WithCalculationOneId(calculationIdOne) .WithCalculationTwoId(calculationIdFour) .WithFundingLine(fundingLines[3])) }; IEnumerable <FundingLine> unusedFundingLines = new FundingLine[0]; unusedFundingLines = unusedFundingLines.Concat(new[] { NewGraphFundingLine(_ => _.WithId(fundingLineIdFive)) }); Calculation[] calculations = new[] { NewGraphCalculation(_ => _.WithId(calculationIdOne)), NewGraphCalculation(_ => _.WithId(calculationIdTwo)), NewGraphCalculation(_ => _.WithId(calculationIdThree)), NewGraphCalculation(_ => _.WithId(calculationIdFour)), }; CalculationRelationship[] calculationRelationships = new[] { NewCalculationRelationship(_ => _.WithCalculationOneId(calculationIdTwo) .WithCalculationTwoId(calculationIdOne)), NewCalculationRelationship(_ => _.WithCalculationOneId(calculationIdThree) .WithCalculationTwoId(calculationIdTwo)), NewCalculationRelationship(_ => _.WithCalculationOneId(calculationIdFour) .WithCalculationTwoId(calculationIdThree)) }; IEnumerable <CalculationRelationship> unusedCalculationRelationships = new CalculationRelationship[0]; if (withCallsCalculation) { unusedCalculationRelationships = unusedCalculationRelationships.Concat(new[] { NewCalculationRelationship(_ => _.WithCalculationOneId(calculationIdFour) .WithCalculationTwoId(calculationIdFive)) }); } CalculationDataFieldRelationship[] dataFieldRelationships = calculations.Select(_ => new CalculationDataFieldRelationship { Calculation = _, DataField = NewDataField(datafieldBuilder => datafieldBuilder.WithCalculationId(_.CalculationId)) }).ToArray(); Dataset newDataset = NewDataset(); DatasetDataFieldRelationship[] datasetDataFieldRelationships = dataFieldRelationships.Select(_ => new DatasetDataFieldRelationship { DataField = _.DataField, Dataset = newDataset }).ToArray(); DatasetDefinition newDatasetDefinition = NewDatasetDefinition(); DatasetDatasetDefinitionRelationship[] datasetDatasetDefinitionRelationships = datasetDataFieldRelationships.Select(_ => new DatasetDatasetDefinitionRelationship { Dataset = _.Dataset, DatasetDefinition = newDatasetDefinition }).ToArray(); CalculationDataFieldRelationship[] unusedDataFieldRelationships = new[] { new CalculationDataFieldRelationship { Calculation = NewGraphCalculation(_ => _.WithId(calculationIdOne)), DataField = NewDataField(datasetBuilder => datasetBuilder.WithCalculationId(calculationIdOne).WithDataFieldId(datafieldId)) } }; SpecificationCalculationRelationships specificationCalculationRelationships = NewSpecificationCalculationRelationships(_ => _.WithSpecification(specification) .WithCalculations(calculations) .WithFundingLines(fundingLines) .WithFundingLineCalculationRelationships(fundingLineRelationships) .WithCalculationRelationships(calculationRelationships) .WithCalculationDataFieldRelationships(dataFieldRelationships) .WithDatasetDataFieldRelationships(datasetDataFieldRelationships) .WithDatasetDatasetDefinitionRelationships(datasetDatasetDefinitionRelationships)); ApiSpecification apiSpecification = NewApiSpecification(); ApiCalculation[] apiCalculations = new[] { NewApiCalculation(), NewApiCalculation(), NewApiCalculation() }; ApiFundingLine[] apiFundingLines = new[] { NewApiFundingLine(_ => _.WithId(fundingLineIdOne)), NewApiFundingLine(_ => _.WithId(fundingLineIdTwo)), NewApiFundingLine(_ => _.WithId(fundingLineIdThree)), NewApiFundingLine(_ => _.WithId(fundingLineIdFour)), NewApiFundingLine(_ => _.WithId(fundingLineIdFive)) }; GivenTheMapping(specification, apiSpecification); foreach (CalculationDataFieldRelationship datFieldRelationship in dataFieldRelationships) { AndTheMapping(datFieldRelationship.DataField, new ApiDataField { CalculationId = datFieldRelationship.DataField.CalculationId, DataFieldId = datFieldRelationship.DataField.DataFieldId, DataFieldName = datFieldRelationship.DataField.DataFieldName }); } AndTheMapping(newDataset, new ApiDataSet { DatasetId = newDataset.DatasetId, Name = newDataset.Name }); AndTheMapping(newDatasetDefinition, new ApiDatasetDefinition { DatasetDefinitionId = newDatasetDefinition.DatasetDefinitionId, Name = newDatasetDefinition.Name }); if (withFundingLineRemoval) { AndTheMapping(existingFundingLines.Select(_ => _.Node).First(), unusedFundingLines.First()); } foreach (FundingLine fundingLine in fundingLines.Where(_ => !unusedFundingLines.Any(uf => uf.FundingLineId == _.FundingLineId))) { AndTheMapping(fundingLine, apiFundingLines.Where(_ => _.FundingLineId == fundingLine.FundingLineId).First()); } AndTheCollectionMapping(calculations, apiCalculations); AndTheSpecificationRelationshipsAreDeleted(calculationIdFive, specificationId, unusedCalculationRelationships, unusedDataFieldRelationships, withBelongsToSpecification); if (withFundingLineRemoval) { AndTheFundingLinesAreDeleted(unusedFundingLines.ToArray()); } AndTheSpecificationIsCreated(apiSpecification); AndTheCalculationsAreCreated(apiCalculations); AndTheFundingLinesAreCreated(apiFundingLines.Where(_ => !unusedFundingLines.Any(uf => uf.FundingLineId == _.FundingLineId)).ToArray()); AndTheSpecificationCalculationRelationshipsWereCreated(specificationId, new [] { calculationIdOne, calculationIdTwo, calculationIdThree, calculationIdFour }); AndTheFundingLineCalculationRelationshipsWereCreated(calculationIdOne, fundingLines.Select(_ => _.FundingLineId).ToArray(), calculations.Select(_ => _.CalculationId).ToArray()); AndTheExistingRelationships(specificationId, existingEntities); AndTheExistingCalculationRelationships(calculationIdOne, existingCalculationEntities); if (withFundingLineRemoval) { AndTheExistingFundingLines(existingFundingLines); } AndTheRelationshipsWereCreated(calculationRelationships); AndTheDataFieldRelationshipsWereCreated(dataFieldRelationships); AndTheDatasetDataFieldRelationshipsWereCreated(datasetDataFieldRelationships, specificationId); AndTheDatasetDatasetDefinitionRelationshipsWereCreated(datasetDatasetDefinitionRelationships); SpecificationCalculationRelationships specificationUnusedCalculationRelationships = await WhenTheUnusedRelationshipsAreReturned(specificationCalculationRelationships); await AndTheGraphIsRecreated(specificationCalculationRelationships, specificationUnusedCalculationRelationships); _graphApiClient.VerifyAll(); }