public void GetReferencedCalculations_GivenListOfCalcsAndSourceCodeContainsTwoCalcs_ReturnsTwoCalcs() { //Arrange string sourceCode = " calc1() + calc2()"; IEnumerable <string> calcNames = new[] { "calc1", "calc2", "calc3" }; //Act IEnumerable <string> results = SourceCodeHelpers.GetReferencedCalculations(calcNames, sourceCode); //Assert results .Count() .Should() .Be(2); results .ElementAt(0) .Should() .Be("calc1"); results .ElementAt(1) .Should() .Be("calc2"); }
public void GetReferencedCalculations_GivenAnEmptySourceCodeString_ReturnsEmptyList() { //Arrange string sourceCode = ""; IEnumerable <string> calcNames = new[] { "calc1", "calc2", "calc3" }; //Act IEnumerable <string> results = SourceCodeHelpers.GetReferencedCalculations(calcNames, sourceCode); //Assert results .Any() .Should() .BeFalse(); }
public void GetReferencedCalculations_GivenListOfCalcsAndSourceCodeDoesNotContainCalc_ReturnsEmptyList() { //Arrange string sourceCode = " calc4() + calc5()"; IEnumerable <string> calcNames = new[] { "calc1", "calc2", "calc3" }; //Act IEnumerable <string> results = SourceCodeHelpers.GetReferencedCalculations(calcNames, sourceCode); //Assert results .Any() .Should() .BeFalse(); }
public IEnumerable <CalculationRelationship> DetermineRelationshipsBetweenCalculations(IEnumerable <Calculation> calculations) { Guard.IsNotEmpty(calculations, nameof(calculations)); Dictionary <string, string> calculationIdsBySourceCodeName = calculations .ToDictionary(_ => $"{_.Namespace}.{_.Current.SourceCodeName}", _ => _.Id); string[] calculationNames = calculations.Select(_ => $"{_.Namespace}.{_.Current.SourceCodeName}") .ToArray(); return(calculations.SelectMany(_ => { IEnumerable <string> relatedCalculationNames = SourceCodeHelpers.GetReferencedCalculations(calculationNames, _.Current.SourceCode); return relatedCalculationNames.Select(rel => new CalculationRelationship { CalculationOneId = _.Id, CalculationTwoId = calculationIdsBySourceCodeName.TryGetValue(rel, out string twoId) ? twoId : throw new InvalidOperationException($"Could not locate a calculation id for sourceCodeName {rel}") }); }));