public void GenerateCalculations_GivenSpaceInEnumReturnsValidEnumCalculationType()
        {
            Calculation _1619 = NewCalculation(_ => _.WithFundingStream(NewReference(rf => rf.WithId("1619")))
                                               .WithName("MethodologyType")
                                               .WithValueType(CalculationValueType.String)
                                               .WithDataType(CalculationDataType.Enum)
                                               .WithAllowedEnumTypeValues(new[] { "Type1 ", "Type2", "Type3" })
                                               .WithSourceCodeName("One")
                                               .WithCalculationNamespaceType(CalculationNamespace.Template)
                                               .WithSourceCode("return Nothing"));

            FundingLine _1619fl = NewFundingLine(_ => _.WithCalculations(new[] { NewFundingLineCalculation(_ => _.WithId(1)
                                                                                                           .WithCalculationNamespaceType(CalculationNamespace.Template)) })
                                                 .WithId(2)
                                                 .WithName("Two")
                                                 .WithSourceCodeName("Two")
                                                 .WithNamespace("1619"));

            IDictionary <string, Funding> fundingLines = new Dictionary <string, Funding> {
                { "1619", NewFunding(_ => _.WithFundingLines(new[] { _1619fl })) }
            };

            IEnumerable <SourceFile> results = new CalculationTypeGenerator(new CompilerOptions(), _fundingLineRoundingSettings.Object).GenerateCalcs(new[] { _1619 }, fundingLines).ToList();

            results.Should().HaveCount(1);

            results.First().SourceCode.Should().Contain("Enum MethodologyTypeOptions");
            results.First().SourceCode.Should().Contain("Public One As Func(Of MethodologyTypeOptions?) = Nothing");
        }
        public void GenerateCalculations_GiveEnumCalculationType()
        {
            Calculation _1619 = NewCalculation(_ => _.WithFundingStream(NewReference(rf => rf.WithId("1619")))
                                               .WithName("MethodologyType")
                                               .WithValueType(CalculationValueType.String)
                                               .WithDataType(CalculationDataType.Enum)
                                               .WithAllowedEnumTypeValues(new[] { "Type1", "Type2", "Type3" })
                                               .WithSourceCodeName("One")
                                               .WithCalculationNamespaceType(CalculationNamespace.Template)
                                               .WithSourceCode("return Nothing"));

            FundingLine _1619fl = NewFundingLine(_ => _.WithCalculations(new[] { NewFundingLineCalculation(_ => _.WithId(1)
                                                                                                           .WithCalculationNamespaceType(CalculationNamespace.Template)) })
                                                 .WithId(2)
                                                 .WithName("Two")
                                                 .WithSourceCodeName("Two")
                                                 .WithNamespace("1619"));

            IDictionary <string, Funding> fundingLines = new Dictionary <string, Funding> {
                { "1619", NewFunding(_ => _.WithFundingLines(new[] { _1619fl })) }
            };

            IEnumerable <SourceFile> results = new CalculationTypeGenerator(new CompilerOptions(), _fundingLineRoundingSettings.Object).GenerateCalcs(new[] { _1619 }, fundingLines).ToList();

            results.Should().HaveCount(1);

            results.First().SourceCode.Should().Contain("Public Enum MethodologyTypeOptions");
            results.First().SourceCode.Should().Contain("Public One As Func(Of MethodologyTypeOptions?) = Nothing");
            results.First().SourceCode.Should().Contain("Return If(String.IsNullOrWhiteSpace(existingCalculationResultString), Nothing, CType([Enum].Parse(GetType(MethodologyTypeOptions), existingCalculationResultString), MethodologyTypeOptions?))");
            results.First().SourceCode.Should().Contain($"calculationContext.DictionaryStringValues.Add(\"{_1619.Id}\", executedUserCodeCalculationResult?.ToString())");
        }
        public void GenerateCalculations_GivenEnumCalculation_ThenEnumCreated()
        {
            Calculation _1619 = NewCalculation(_ => _.WithFundingStream(NewReference(rf => rf.WithId("1619")))
                                               .WithSourceCodeName("One")
                                               .WithCalculationNamespaceType(CalculationNamespace.Template)
                                               .WithSourceCode("return 456")
                                               .WithName("EnumName")
                                               .WithDataType(CalculationDataType.Enum)
                                               .WithAllowedEnumTypeValues(new[] { "Option1", "Option2" }));

            FundingLine _1619fl = NewFundingLine(_ => _.WithCalculations(new[] { NewFundingLineCalculation(_ => _.WithId(1)
                                                                                                           .WithCalculationNamespaceType(CalculationNamespace.Template)) })
                                                 .WithId(1)
                                                 .WithName("One")
                                                 .WithSourceCodeName("One")
                                                 .WithNamespace("1619"));

            IDictionary <string, Funding> fundingLines = new Dictionary <string, Funding> {
                { "1619", NewFunding(_ => _.WithFundingLines(new[] { _1619fl })) },
            };

            IEnumerable <SourceFile> results = new CalculationTypeGenerator(new CompilerOptions(), _fundingLineRoundingSettings.Object).GenerateCalcs(new[] { _1619 }, fundingLines);

            results.Should().HaveCount(1);
            results.First()
            .SourceCode
            .Should()
            .Contain(
                @$ "Enum EnumNameOptions
        <Description(Description:=" "Option1" ")>
        Option1
        <Description(Description:=" "Option2" ")>
        Option2
    End Enum");
        }
        public void GenerateCalculations_GivenNoAdditionalCalculations_ThenFundingLineMembersCreated()
        {
            Calculation _1619 = NewCalculation(_ => _.WithFundingStream(NewReference(rf => rf.WithId("DSG")))
                                               .WithSourceCodeName("One")
                                               .WithCalculationNamespaceType(CalculationNamespace.Template)
                                               .WithSourceCode("return 456"));
            Calculation psg = NewCalculation(_ => _.WithFundingStream(NewReference(rf => rf.WithId("PSG")))
                                             .WithCalculationNamespaceType(CalculationNamespace.Template)
                                             .WithSourceCodeName("Two")
                                             .WithSourceCode("return _1619.One() + 100"));

            FundingLine _1619fl = NewFundingLine(_ => _.WithCalculations(new[] { NewFundingLineCalculation(_ => _.WithId(1)
                                                                                                           .WithCalculationNamespaceType(CalculationNamespace.Template)) })
                                                 .WithId(1)
                                                 .WithName("One")
                                                 .WithSourceCodeName("One")
                                                 .WithNamespace("1619"));

            FundingLine psgfl = NewFundingLine(_ => _.WithCalculations(new[] { NewFundingLineCalculation(_ => _.WithId(1)
                                                                                                         .WithCalculationNamespaceType(CalculationNamespace.Template)) })
                                               .WithId(2)
                                               .WithName("Two")
                                               .WithSourceCodeName("Two")
                                               .WithNamespace("PSG"));

            IDictionary <string, Funding> fundingLines = new Dictionary <string, Funding> {
                { "1619", NewFunding(_ => _.WithFundingLines(new[] { _1619fl })) },
                { "PSG", NewFunding(_ => _.WithFundingLines(new[] { psgfl })) }
            };

            IEnumerable <SourceFile> results = new CalculationTypeGenerator(new CompilerOptions(), _fundingLineRoundingSettings.Object).GenerateCalcs(new[] { _1619, psg }, fundingLines);

            results.Should().HaveCount(1);
            results.First()
            .SourceCode
            .Should()
            .ContainAll(
                "<FundingLine(FundingStream:=\"1619\", Id:=\"1\", Name:=\"One\")>",
                "Public One As Func(Of decimal?) = Nothing",
                "<FundingLine(FundingStream:=\"PSG\", Id:=\"2\", Name:=\"Two\")>",
                "Public Two As Func(Of decimal?) = Nothing",
                "_1619.FundingLines.One()");
        }
        public void GenerateCalculations_GivenNoAdditionalCalculations_ThenSingleInnerClassForAdditionalStillCreated()
        {
            Calculation _1619 = NewCalculation(_ => _.WithFundingStream(NewReference(rf => rf.WithId("1619")))
                                               .WithSourceCodeName("One")
                                               .WithCalculationNamespaceType(CalculationNamespace.Template)
                                               .WithSourceCode("return 456"));
            Calculation psg = NewCalculation(_ => _.WithFundingStream(NewReference(rf => rf.WithId("PSG")))
                                             .WithCalculationNamespaceType(CalculationNamespace.Template)
                                             .WithSourceCodeName("One")
                                             .WithSourceCode("return DSG.One() + 100"));

            FundingLine _1619fl = NewFundingLine(_ => _.WithCalculations(new[] { NewFundingLineCalculation(_ => _.WithId(1)
                                                                                                           .WithCalculationNamespaceType(CalculationNamespace.Template)) })
                                                 .WithId(1)
                                                 .WithName("One")
                                                 .WithSourceCodeName("One")
                                                 .WithNamespace("1619"));

            FundingLine psgfl = NewFundingLine(_ => _.WithCalculations(new[] { NewFundingLineCalculation(_ => _.WithId(1)
                                                                                                         .WithCalculationNamespaceType(CalculationNamespace.Template)) })
                                               .WithId(2)
                                               .WithName("One")
                                               .WithSourceCodeName("One")
                                               .WithNamespace("PSG"));

            IDictionary <string, Funding> fundingLines = new Dictionary <string, Funding> {
                { "1619", NewFunding(_ => _.WithFundingLines(new[] { _1619fl })) },
                { "PSG", NewFunding(_ => _.WithFundingLines(new[] { psgfl })) }
            };

            IEnumerable <SourceFile> results = new CalculationTypeGenerator(new CompilerOptions(), _fundingLineRoundingSettings.Object).GenerateCalcs(new[] { _1619, psg }, fundingLines);

            results.Should().HaveCount(1);
            results.First()
            .SourceCode
            .Should()
            .ContainAll("Public Class PSGCalculations",
                        "Public Class _1619Calculations",
                        "Public Class AdditionalCalculations",
                        "Public Class PSGFundingLines",
                        "Public Class _1619FundingLines");
        }